summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-07-05 13:21:51 +0000
committersmatz <smatz@openttd.org>2009-07-05 13:21:51 +0000
commit59f94619c75be0ff4dc5f6edf8e0b365261dc9d6 (patch)
treeff8099d504f93a338e423ed5c3a36ebf2a4650c6 /src
parentc861d9b64b2a63fa86ea87ac1e71f8f7341c694b (diff)
downloadopenttd-59f94619c75be0ff4dc5f6edf8e0b365261dc9d6.tar.xz
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
Diffstat (limited to 'src')
-rw-r--r--src/road_cmd.cpp4
-rw-r--r--src/road_cmd.h2
-rw-r--r--src/town.h3
-rw-r--r--src/town_cmd.cpp14
4 files changed, 16 insertions, 7 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index ef9206fde..19e390114 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1248,7 +1248,7 @@ void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
* @param ignore town that should be ignored (because we are deleting it now)
* @pre invalidate == true implies _generating_world == true
*/
-void UpdateNearestTownForRoadTiles(bool invalidate, const Town *ignore)
+void UpdateNearestTownForRoadTiles(bool invalidate)
{
assert(!invalidate || _generating_world);
@@ -1256,7 +1256,7 @@ void UpdateNearestTownForRoadTiles(bool invalidate, const Town *ignore)
if (IsTileType(t, MP_ROAD) && !HasTownOwnedRoad(t)) {
TownID tid = (TownID)INVALID_TOWN;
if (!invalidate) {
- const Town *town = CalcClosestTownFromTile(t, UINT_MAX, ignore);
+ const Town *town = CalcClosestTownFromTile(t);
if (town != NULL) tid = town->index;
}
SetTownIndex(t, tid);
diff --git a/src/road_cmd.h b/src/road_cmd.h
index d1ff2b8d0..00235a3b3 100644
--- a/src/road_cmd.h
+++ b/src/road_cmd.h
@@ -8,6 +8,6 @@
#include "direction_type.h"
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt);
-void UpdateNearestTownForRoadTiles(bool invalidate, const struct Town *ignore = NULL);
+void UpdateNearestTownForRoadTiles(bool invalidate);
#endif /* ROAD_CMD_H */
diff --git a/src/town.h b/src/town.h
index c65569ad1..1f02afa8d 100644
--- a/src/town.h
+++ b/src/town.h
@@ -142,6 +142,7 @@ struct Town : TownPool::PoolItem<&_town_pool> {
}
static Town *GetRandom();
+ static void PostDestructor(size_t index);
};
uint32 GetWorldPopulation();
@@ -181,7 +182,7 @@ bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
TileIndexDiff GetHouseNorthPart(HouseID &house);
-Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX, const Town *ignore = NULL);
+Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX);
#define FOR_ALL_TOWNS_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start)
#define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 734214fa8..aaebfabaf 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -102,8 +102,17 @@ Town::~Town()
DeleteSubsidyWithTown(this->index);
MarkWholeScreenDirty();
+}
+
- UpdateNearestTownForRoadTiles(false, this);
+/**
+ * Invalidating of the "nearest town cache" has to be done
+ * after removing item from the pool.
+ * @param index index of deleted item
+ */
+void Town::PostDestructor(size_t index)
+{
+ UpdateNearestTownForRoadTiles(false);
}
/**
@@ -2694,14 +2703,13 @@ bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
}
-Town *CalcClosestTownFromTile(TileIndex tile, uint threshold, const Town *ignore)
+Town *CalcClosestTownFromTile(TileIndex tile, uint threshold)
{
Town *t;
uint best = threshold;
Town *best_town = NULL;
FOR_ALL_TOWNS(t) {
- if (t == ignore) continue;
uint dist = DistanceManhattan(tile, t->xy);
if (dist < best) {
best = dist;