summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-10-30 10:01:49 +0000
committerfrosch <frosch@openttd.org>2013-10-30 10:01:49 +0000
commitcef342d57c89dcb962545432bd0bf0edaccc8708 (patch)
tree82e33b47dea3cb0428c19df2b2e4e276c006253b /src/town_cmd.cpp
parent403168287e1f4b855429f16ae2b5d3c876fbbb87 (diff)
downloadopenttd-cef342d57c89dcb962545432bd0bf0edaccc8708.tar.xz
(svn r25931) -Fix [FS#5786-ish]: [NoGo] Preserve the relative town growth progress when changing the town growth rate.
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index d431242c3..38894fe76 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2527,7 +2527,20 @@ CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (t == NULL) return CMD_ERROR;
if (flags & DC_EXEC) {
- t->growth_rate = (p2 == 0) ? 0 : p2 | TOWN_GROW_RATE_CUSTOM;
+ if (p2 == 0) {
+ /* Clear TOWN_GROW_RATE_CUSTOM, UpdateTownGrowRate will determine a proper value */
+ t->growth_rate = 0;
+ } else {
+ uint old_rate = t->growth_rate & ~TOWN_GROW_RATE_CUSTOM;
+ if (t->grow_counter >= old_rate) {
+ /* This also catches old_rate == 0 */
+ t->grow_counter = p2;
+ } else {
+ /* Scale grow_counter, so half finished houses stay half finished */
+ t->grow_counter = t->grow_counter * p2 / old_rate;
+ }
+ t->growth_rate = p2 | TOWN_GROW_RATE_CUSTOM;
+ }
UpdateTownGrowRate(t);
InvalidateWindowData(WC_TOWN_VIEW, p1);
}