Change: Switch town growth rate and counter to actual game ticks (#6763)
This commit is contained in:
@@ -159,24 +159,24 @@
|
||||
/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, uint32 days_between_town_growth)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
|
||||
uint16 growth_rate;
|
||||
switch (days_between_town_growth) {
|
||||
case TOWN_GROWTH_NORMAL:
|
||||
days_between_town_growth = 0;
|
||||
growth_rate = 0;
|
||||
break;
|
||||
|
||||
case TOWN_GROWTH_NONE:
|
||||
days_between_town_growth = TOWN_GROW_RATE_CUSTOM_NONE;
|
||||
growth_rate = TOWN_GROWTH_RATE_NONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
days_between_town_growth = days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS;
|
||||
EnforcePrecondition(false, days_between_town_growth < TOWN_GROW_RATE_CUSTOM);
|
||||
if (days_between_town_growth == 0) days_between_town_growth = 1; // as fast as possible
|
||||
EnforcePrecondition(false, days_between_town_growth <= MAX_TOWN_GROWTH_TICKS);
|
||||
/* Don't use growth_rate 0 as it means GROWTH_NORMAL */
|
||||
growth_rate = max(days_between_town_growth * DAY_TICKS, 2u) - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, days_between_town_growth, CMD_TOWN_GROWTH_RATE);
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, growth_rate, CMD_TOWN_GROWTH_RATE);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptTown::GetGrowthRate(TownID town_id)
|
||||
@@ -185,9 +185,9 @@
|
||||
|
||||
const Town *t = ::Town::Get(town_id);
|
||||
|
||||
if (t->growth_rate == TOWN_GROW_RATE_CUSTOM_NONE) return TOWN_GROWTH_NONE;
|
||||
if (t->growth_rate == TOWN_GROWTH_RATE_NONE) return TOWN_GROWTH_NONE;
|
||||
|
||||
return ((t->growth_rate & ~TOWN_GROW_RATE_CUSTOM) * TOWN_GROWTH_TICKS + DAY_TICKS) / DAY_TICKS;
|
||||
return RoundDivSU(t->growth_rate + 1, DAY_TICKS);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptTown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
|
||||
|
@@ -259,7 +259,7 @@ public:
|
||||
* @param town_id The index of the town.
|
||||
* @param days_between_town_growth The amount of days between town growth, TOWN_GROWTH_NONE or TOWN_GROWTH_NORMAL.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre days_between_town_growth <= 30000 || days_between_town_growth == TOWN_GROWTH_NONE || days_between_town_growth == TOWN_GROWTH_NORMAL.
|
||||
* @pre days_between_town_growth <= 880 || days_between_town_growth == TOWN_GROWTH_NONE || days_between_town_growth == TOWN_GROWTH_NORMAL.
|
||||
* @return True if the action succeeded.
|
||||
* @note Even when setting a growth rate, towns only grow when the conditions for growth (SetCargoCoal) are met,
|
||||
* and the game settings (economy.town_growth_rate) allow town growth at all.
|
||||
|
Reference in New Issue
Block a user