summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-13 11:57:59 +0000
committerrubidium <rubidium@openttd.org>2010-08-13 11:57:59 +0000
commita7beb897e22ca3101b02cc29d4e378c062b8989f (patch)
tree2a340c44ca360899ae9fb2dec46a370447f28f66 /src
parent7e5309a28a530d1c534dfee837d83469a1be0ea2 (diff)
downloadopenttd-a7beb897e22ca3101b02cc29d4e378c062b8989f.tar.xz
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
Diffstat (limited to 'src')
-rw-r--r--src/town_cmd.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index d3b1dcfae..365d64780 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -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();