summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
authordP <dp@dpointer.org>2021-01-15 17:38:14 +0300
committerCharles Pigott <charlespigott@googlemail.com>2021-01-22 09:50:53 +0000
commitbab7de6cf23dce124ef8b1e284d0d1f3996dc8b8 (patch)
tree3686edd1b3ebb285e802a8a16b79552972c0b1b4 /src/industry_cmd.cpp
parent4b42ecb0f64c0044786412c15fb31b3705016375 (diff)
downloadopenttd-bab7de6cf23dce124ef8b1e284d0d1f3996dc8b8.tar.xz
Feature: Allow GameScripts to add additional text to Industry view window
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 69d67b9d8..20c38e545 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -40,6 +40,8 @@
#include "object_base.h"
#include "game/game.hpp"
#include "error.h"
+#include "cmd_helper.h"
+#include "string_func.h"
#include "table/strings.h"
#include "table/industry_land.h"
@@ -2063,16 +2065,13 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
* @param flags Type of operation.
* @param p1 IndustryID
* @param p2 various bitstuffed elements
- * - p2 = (bit 0 - 7) - action to perform:
- * 0 = set control flags
- * 1 = set exclusive supplier
- * 2 = set exclusive consumer
+ * - p2 = (bit 0 - 7) - IndustryAction to perform
* - p2 = (bit 8 - 15) - IndustryControlFlags
* (only used with set control flags)
* - p2 = (bit 16 - 23) - CompanyID to set or INVALID_OWNER (available to everyone) or
* OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
* (only used with set exclusive supplier / consumer)
- * @param text unused
+ * @param text - Additional industry text (only used with set text action)
* @return Empty cost or an error.
*/
CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
@@ -2082,10 +2081,10 @@ CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
Industry *ind = Industry::GetIfValid(p1);
if (ind == nullptr) return CMD_ERROR;
- uint8 action = GB(p2, 0, 8);
+ auto action = static_cast<IndustryAction>(GB(p2, 0, 8));
switch (action) {
- case 0: {
+ case IndustryAction::SetControlFlags: {
IndustryControlFlags ctlflags = (IndustryControlFlags)GB(p2, 8, 8) & INDCTL_MASK;
if (flags & DC_EXEC) ind->ctlflags = ctlflags;
@@ -2093,15 +2092,15 @@ CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
break;
}
- case 1:
- case 2: {
+ case IndustryAction::SetExclusiveSupplier:
+ case IndustryAction::SetExclusiveConsumer: {
Owner company_id = (Owner)GB(p2, 16, 8);
if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
&& !Company::IsValidID(company_id)) return CMD_ERROR;
if (flags & DC_EXEC) {
- if (action == 1) {
+ if (action == IndustryAction::SetExclusiveSupplier) {
ind->exclusive_supplier = company_id;
} else {
ind->exclusive_consumer = company_id;
@@ -2111,6 +2110,13 @@ CommandCost CmdIndustryCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
break;
}
+ case IndustryAction::SetText: {
+ ind->text.clear();
+ if (!StrEmpty(text)) ind->text = text;
+ InvalidateWindowData(WC_INDUSTRY_VIEW, ind->index);
+ break;
+ }
+
default:
NOT_REACHED();
}