mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
This commit is contained in:
parent
7e5309a28a
commit
a7beb897e2
|
@ -47,6 +47,7 @@
|
|||
#include "core/random_func.hpp"
|
||||
#include "core/backup_type.hpp"
|
||||
#include "depot_base.h"
|
||||
#include "object_map.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/town_land.h"
|
||||
|
@ -65,33 +66,27 @@ Town::~Town()
|
|||
|
||||
if (CleaningPool()) return;
|
||||
|
||||
Industry *i;
|
||||
|
||||
/* Delete town authority window
|
||||
* and remove from list of sorted towns */
|
||||
DeleteWindowById(WC_TOWN_VIEW, this->index);
|
||||
|
||||
/* Delete all industries belonging to the town */
|
||||
FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
|
||||
/* Check no industry is related to us. */
|
||||
Industry *i;
|
||||
FOR_ALL_INDUSTRIES(i) assert(i->town != this);
|
||||
|
||||
/* Go through all tiles and delete those belonging to the town */
|
||||
/* Check no tile is related to us. */
|
||||
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_HOUSE:
|
||||
if (Town::GetByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
assert(GetTownIndex(tile) != this->index);
|
||||
break;
|
||||
|
||||
case MP_ROAD:
|
||||
/* Cached nearest town is updated later (after this town has been deleted) */
|
||||
if (HasTownOwnedRoad(tile) && GetTownIndex(tile) == this->index) {
|
||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
}
|
||||
assert(!HasTownOwnedRoad(tile) || GetTownIndex(tile) != this->index);
|
||||
break;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (IsTileOwner(tile, OWNER_TOWN) &&
|
||||
ClosestTownFromTile(tile, UINT_MAX) == this)
|
||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
assert(!IsTileOwner(tile, OWNER_TOWN) || ClosestTownFromTile(tile, UINT_MAX) != this);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -2372,7 +2367,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||
/* Non-oil rig stations are always a problem. */
|
||||
if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return CMD_ERROR;
|
||||
/* We can only automatically delete oil rigs *if* there's no vehicle on them. */
|
||||
CommandCost ret = DoCommand(st->airport.tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
||||
CommandCost ret = DoCommand(st->airport.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
}
|
||||
|
@ -2385,30 +2380,34 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||
|
||||
/* Check all tiles for town ownership. */
|
||||
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
|
||||
bool try_clear = false;
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_ROAD:
|
||||
if (HasTownOwnedRoad(tile) && GetTownIndex(tile) == t->index) {
|
||||
/* Can we clear this tile? */
|
||||
CommandCost ret = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
try_clear = HasTownOwnedRoad(tile) && GetTownIndex(tile) == t->index;
|
||||
break;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (IsTileOwner(tile, OWNER_TOWN) &&
|
||||
ClosestTownFromTile(tile, UINT_MAX) == t) {
|
||||
/* Can we clear this bridge? */
|
||||
CommandCost ret = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
try_clear = IsTileOwner(tile, OWNER_TOWN) && ClosestTownFromTile(tile, UINT_MAX) == t;
|
||||
break;
|
||||
|
||||
case MP_HOUSE:
|
||||
try_clear = GetTownIndex(tile) == t->index;
|
||||
break;
|
||||
|
||||
case MP_INDUSTRY:
|
||||
try_clear = Industry::GetByTile(tile)->town == t;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (try_clear) {
|
||||
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* The town destructor will delete everything related to the town. */
|
||||
/* The town destructor will delete the other things related to the town. */
|
||||
if (flags & DC_EXEC) delete t;
|
||||
|
||||
return CommandCost();
|
||||
|
|
Loading…
Reference in New Issue