summaryrefslogtreecommitdiff
path: root/town_cmd.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-26 18:05:05 +0000
committertruelight <truelight@openttd.org>2006-08-26 18:05:05 +0000
commitbb9f29ae1f49d4d935d343dd2e24d8d66ce938ce (patch)
treec18ac40dc8f148d3b3583c9e04d5b511c24faf0b /town_cmd.c
parentb7ecdc85d8b9dd3dc0de61947a490df2fcbffea4 (diff)
downloadopenttd-bb9f29ae1f49d4d935d343dd2e24d8d66ce938ce.tar.xz
(svn r6149) -Codechange: DeleteTown removes a town from the pool
-Codechange: DestroyTown is called by DeleteTown to remove all things where a town depends on. Last 2 changes to prepare for new pool system. Not pretty now, will be soon.
Diffstat (limited to 'town_cmd.c')
-rw-r--r--town_cmd.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/town_cmd.c b/town_cmd.c
index eb7b19966..d7550ed62 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -51,6 +51,43 @@ static void TownPoolNewBlock(uint start_item)
/* Initialize the town-pool */
MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, NULL, 0, 0, NULL };
+void DestroyTown(Town *t)
+{
+ Industry *i;
+ TileIndex tile;
+
+ /* Delete town authority window
+ * and remove from list of sorted towns */
+ DeleteWindowById(WC_TOWN_VIEW, t->index);
+ _town_sort_dirty = true;
+
+ /* Delete all industries belonging to the town */
+ FOR_ALL_INDUSTRIES(i) if (i->town == t) DeleteIndustry(i);
+
+ /* Go through all tiles and delete those belonging to the town */
+ for (tile = 0; tile < MapSize(); ++tile) {
+ switch (GetTileType(tile)) {
+ case MP_HOUSE:
+ if (GetTownByTile(tile) == t) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+ break;
+
+ case MP_STREET:
+ case MP_TUNNELBRIDGE:
+ if (IsTileOwner(tile, OWNER_TOWN) &&
+ ClosestTownFromTile(tile, (uint)-1) == t)
+ DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ DeleteName(t->townnametype);
+
+ MarkWholeScreenDirty();
+}
+
// Local
static int _grow_town_result;
@@ -1363,48 +1400,6 @@ int32 CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
// Called from GUI
-void DeleteTown(Town *t)
-{
- Industry *i;
- TileIndex tile;
-
- // Delete town authority window
- // and remove from list of sorted towns
- DeleteWindowById(WC_TOWN_VIEW, t->index);
- _town_sort_dirty = true;
-
- // Delete all industries belonging to the town
- FOR_ALL_INDUSTRIES(i) {
- if (i->town == t) DeleteIndustry(i);
- }
-
- // Go through all tiles and delete those belonging to the town
- for (tile = 0; tile < MapSize(); ++tile) {
- switch (GetTileType(tile)) {
- case MP_HOUSE:
- if (GetTownByTile(tile) == t)
- DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
- break;
-
- case MP_STREET:
- case MP_TUNNELBRIDGE:
- if (IsTileOwner(tile, OWNER_TOWN) &&
- ClosestTownFromTile(tile, (uint)-1) == t)
- DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
- break;
-
- default:
- break;
- }
- }
-
- t->xy = 0;
- DeleteName(t->townnametype);
-
- MarkWholeScreenDirty();
-}
-
-// Called from GUI
void ExpandTown(Town *t)
{
int amount, n;