Feature: Script API to change town rating of companies

This commit is contained in:
Niels Martin Hansen
2020-01-04 17:31:52 +01:00
parent b524f1ae21
commit f401622149
6 changed files with 85 additions and 0 deletions

View File

@@ -2804,6 +2804,35 @@ CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
return CommandCost();
}
/**
* 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.