* Change the growth rate of the town. * @param flags Type of operation. * @param town_id Town ID to cargo game of. * @param growth_rate Amount of days between growth, or TOWN_GROWTH_RATE_NONE, or 0 to reset custom growth rate. * @return Empty cost or an error. */
| 3192 | * @return Empty cost or an error. |
| 3193 | */ |
| 3194 | CommandCost CmdTownGrowthRate(DoCommandFlags flags, TownID town_id, uint16_t growth_rate) |
| 3195 | { |
| 3196 | if (_current_company != OWNER_DEITY) return CMD_ERROR; |
| 3197 | |
| 3198 | Town *t = Town::GetIfValid(town_id); |
| 3199 | if (t == nullptr) return CMD_ERROR; |
| 3200 | |
| 3201 | if (flags.Test(DoCommandFlag::Execute)) { |
| 3202 | if (growth_rate == 0) { |
| 3203 | /* Just clear the flag, UpdateTownGrowth will determine a proper growth rate */ |
| 3204 | t->flags.Reset(TownFlag::CustomGrowth); |
| 3205 | } else { |
| 3206 | uint old_rate = t->growth_rate; |
| 3207 | if (t->grow_counter >= old_rate) { |
| 3208 | /* This also catches old_rate == 0 */ |
| 3209 | t->grow_counter = growth_rate; |
| 3210 | } else { |
| 3211 | /* Scale grow_counter, so half finished houses stay half finished */ |
| 3212 | t->grow_counter = t->grow_counter * growth_rate / old_rate; |
| 3213 | } |
| 3214 | t->growth_rate = growth_rate; |
| 3215 | t->flags.Set(TownFlag::CustomGrowth); |
| 3216 | } |
| 3217 | UpdateTownGrowth(t); |
| 3218 | InvalidateWindowData(WC_TOWN_VIEW, town_id); |
| 3219 | } |
| 3220 | |
| 3221 | return CommandCost(); |
| 3222 | } |
| 3223 | |
| 3224 | /** |
| 3225 | * Change the rating of a company in a town |
nothing calls this directly
no test coverage detected