File diff r20886:9dafd02949ba → r20887:c27609398d9e
src/town_cmd.cpp
Show inline comments
 
@@ -2518,25 +2518,38 @@ CommandCost CmdTownSetText(TileIndex til
 
 * @return Empty cost or an error.
 
 */
 
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (_current_company != OWNER_DEITY) return CMD_ERROR;
 
	if ((p2 & TOWN_GROW_RATE_CUSTOM) != 0) return CMD_ERROR;
 
	if (GB(p2, 16, 16) != 0) return CMD_ERROR;
 

	
 
	Town *t = Town::GetIfValid(p1);
 
	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);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Expand a town (scenario editor only).
 
 * @param tile Unused.
 
 * @param flags Type of operation.
 
 * @param p1 Town ID to expand.