summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authorPavel Stupnikov <dp@dpointer.org>2018-05-02 22:01:30 +0300
committerfrosch <github@elsenhans.name>2018-05-02 21:01:30 +0200
commitfef8b831a93a0fc772fc8a0b7799ec51cd86a967 (patch)
tree327b1463e2d0828bb5d5036370517c3abdc77709 /src/script/api
parent61515c9abd6fb31e24c5fd610a9f6b3a899c7171 (diff)
downloadopenttd-fef8b831a93a0fc772fc8a0b7799ec51cd86a967.tar.xz
Change: Switch town growth rate and counter to actual game ticks (#6763)
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_town.cpp18
-rw-r--r--src/script/api/script_town.hpp2
2 files changed, 10 insertions, 10 deletions
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index d81704ae3..4cdd6a9d0 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -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)
diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp
index 03868e67a..7fdf8a6b3 100644
--- a/src/script/api/script_town.hpp
+++ b/src/script/api/script_town.hpp
@@ -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.