MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdExpandTown

Function CmdExpandTown

src/town_cmd.cpp:3257–3287  ·  view source on GitHub ↗

* Expand a town (scenario editor only). * @param flags Type of operation. * @param TownID Town ID to expand. * @param grow_amount Amount to grow, or 0 to grow a random size up to the current amount of houses. * @return Empty cost or an error. */

Source from the content-addressed store, hash-verified

3255 * @return Empty cost or an error.
3256 */
3257CommandCost CmdExpandTown(DoCommandFlags flags, TownID town_id, uint32_t grow_amount, TownExpandModes modes)
3258{
3259 if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) return CMD_ERROR;
3260 if (modes.None()) return CMD_ERROR;
3261 Town *t = Town::GetIfValid(town_id);
3262 if (t == nullptr) return CMD_ERROR;
3263
3264 if (flags.Test(DoCommandFlag::Execute)) {
3265 /* The more houses, the faster we grow */
3266 if (grow_amount == 0) {
3267 uint amount = RandomRange(ClampTo<uint16_t>(t->cache.num_houses / 10)) + 3;
3268 t->cache.num_houses += amount;
3269 UpdateTownRadius(t);
3270
3271 uint n = amount * 10;
3272 do GrowTown(t, modes); while (--n);
3273
3274 t->cache.num_houses -= amount;
3275 } else {
3276 for (; grow_amount > 0; grow_amount--) {
3277 /* Try several times to grow, as we are really suppose to grow */
3278 for (uint i = 0; i < 25; i++) if (GrowTown(t, modes)) break;
3279 }
3280 }
3281 UpdateTownRadius(t);
3282
3283 UpdateTownMaxPass(t);
3284 }
3285
3286 return CommandCost();
3287}
3288
3289/**
3290 * Delete a town (scenario editor or worldgen only).

Callers

nothing calls this directly

Calls 7

RandomRangeFunction · 0.85
UpdateTownRadiusFunction · 0.85
GrowTownFunction · 0.85
UpdateTownMaxPassFunction · 0.85
CommandCostClass · 0.85
NoneMethod · 0.80
TestMethod · 0.80

Tested by

no test coverage detected