summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-04 17:31:52 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-04 19:07:13 +0100
commitf40162214909116507811be4a1f5af9ec9d3ef97 (patch)
tree7e06ca0ceda70bda1c9c3cd2ee091e879e0fdb1d /src/town_cmd.cpp
parentb524f1ae21487caf8ed460d8e20a51c3dd7e11a6 (diff)
downloadopenttd-f40162214909116507811be4a1f5af9ec9d3ef97.tar.xz
Feature: Script API to change town rating of companies
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 7b1d5c90f..31e11ae45 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2805,6 +2805,35 @@ CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
}
/**
+ * Change the rating of a company in a town
+ * @param tile Unused.
+ * @param flags Type of operation.
+ * @param p1 Bit 0..15 = Town ID to change, bit 16..23 = Company ID to change.
+ * @param p2 Bit 0..15 = New rating of company (signed int16).
+ * @param text Unused.
+ * @return Empty cost or an error.
+ */
+CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+
+ TownID town_id = (TownID)GB(p1, 0, 16);
+ Town *t = Town::GetIfValid(town_id);
+ if (t == nullptr) return CMD_ERROR;
+
+ CompanyID company_id = (CompanyID)GB(p1, 16, 8);
+ if (!Company::IsValidID(company_id)) return CMD_ERROR;
+
+ int16 new_rating = Clamp((int16)GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM);
+ if (flags & DC_EXEC) {
+ t->ratings[company_id] = new_rating;
+ InvalidateWindowData(WC_TOWN_AUTHORITY, town_id);
+ }
+
+ return CommandCost();
+}
+
+/**
* Expand a town (scenario editor only).
* @param tile Unused.
* @param flags Type of operation.