Changeset - r20887:c27609398d9e
[Not reviewed]
master
0 1 0
frosch - 11 years ago 2013-10-30 10:01:49
frosch@openttd.org
(svn r25931) -Fix [FS#5786-ish]: [NoGo] Preserve the relative town growth progress when changing the town growth rate.
1 file changed with 14 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/town_cmd.cpp
Show inline comments
 
@@ -2527,7 +2527,20 @@ CommandCost CmdTownGrowthRate(TileIndex 
 
	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);
 
	}
0 comments (0 inline, 0 general)