diff options
author | terkhen <terkhen@openttd.org> | 2010-08-02 21:07:23 +0000 |
---|---|---|
committer | terkhen <terkhen@openttd.org> | 2010-08-02 21:07:23 +0000 |
commit | 7a6df202d0816db1e46c33949f99aed236e531b1 (patch) | |
tree | 3395506d65b1f54db511e97dd710e47200be4741 /src/town_gui.cpp | |
parent | ca0751adb82094a3f7d0042f386f72f43b756575 (diff) | |
download | openttd-7a6df202d0816db1e46c33949f99aed236e531b1.tar.xz |
(svn r20323) -Codechange: Move Delete town code to a command.
Diffstat (limited to 'src/town_gui.cpp')
-rw-r--r-- | src/town_gui.cpp | 58 |
1 files changed, 1 insertions, 57 deletions
diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 4a50b1211..e1581cb70 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -33,8 +33,6 @@ #include "townname_func.h" #include "townname_type.h" #include "core/geometry_func.hpp" -#include "station_base.h" -#include "depot_base.h" #include "genworld.h" #include "table/sprites.h" @@ -466,65 +464,11 @@ public: break; case TVW_DELETE: // delete town - only available on Scenario editor - if (this->CanDeleteTown()) { - delete this->town; - } else { - ShowErrorMessage(STR_ERROR_TOWN_CAN_T_DELETE, INVALID_STRING_ID, WL_INFO); - } + DoCommandP(0, this->window_number, 0, CMD_DELETE_TOWN | CMD_MSG(STR_ERROR_TOWN_CAN_T_DELETE)); break; } } - /** - * Can we delete the town? - * Or in other words, does anything refer to this town? - * @return true if it's possible - */ - bool CanDeleteTown() const - { - /* Stations refer to towns. */ - const Station *st; - FOR_ALL_STATIONS(st) { - if (st->town == this->town) { - /* Non-oil rig stations are always a problem. */ - if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return false; - /* We can only automatically delete oil rigs *if* there's no vehicle on them. */ - if (DoCommand(st->airport.tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed()) return false; - } - } - - /* Depots refer to towns. */ - const Depot *d; - FOR_ALL_DEPOTS(d) { - if (d->town == this->town) return false; - } - - /* Check all tiles for town ownership. */ - for (TileIndex tile = 0; tile < MapSize(); ++tile) { - switch (GetTileType(tile)) { - case MP_ROAD: - if (HasTownOwnedRoad(tile) && GetTownIndex(tile) == this->town->index) { - /* Can we clear this tile? */ - if (DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed()) return false; - } - break; - - case MP_TUNNELBRIDGE: - if (IsTileOwner(tile, OWNER_TOWN) && - ClosestTownFromTile(tile, UINT_MAX) == this->town) { - /* Can we clear this bridge? */ - if (DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed()) return false; - } - break; - - default: - break; - } - } - - return true; - } - virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { switch (widget) { |