Changeset - r4396:de3f13de914f
[Not reviewed]
master
0 2 0
truelight - 18 years ago 2006-08-26 18:05:05
truelight@openttd.org
(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.
2 files changed with 45 insertions and 43 deletions:
town.h
8
1
town_cmd.c
37
42
0 comments (0 inline, 0 general)
town.h
Show inline comments
 
@@ -81,7 +81,6 @@ uint32 GetWorldPopulation(void);
 
void UpdateTownVirtCoord(Town *t);
 
void InitializeTown(void);
 
void ShowTownViewWindow(TownID town);
 
void DeleteTown(Town *t);
 
void ExpandTown(Town *t);
 
Town *CreateRandomTown(uint attempts, uint size_mode);
 

	
 
@@ -218,6 +217,14 @@ static inline bool IsValidTownID(uint in
 
	return index < GetTownPoolSize() && IsValidTown(GetTown(index));
 
}
 

	
 
void DestroyTown(Town *t);
 

	
 
static inline void DeleteTown(Town *t)
 
{
 
	DestroyTown(t);
 
	t->xy = 0;
 
}
 

	
 
#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL) if (IsValidTown(t))
 
#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
 

	
town_cmd.c
Show inline comments
 
@@ -51,6 +51,43 @@ static void TownPoolNewBlock(uint start_
 
/* 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, uint
 
}
 

	
 
// 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;
0 comments (0 inline, 0 general)