mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
This commit is contained in:
parent
c861d9b64b
commit
59f94619c7
@ -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)
|
* @param ignore town that should be ignored (because we are deleting it now)
|
||||||
* @pre invalidate == true implies _generating_world == true
|
* @pre invalidate == true implies _generating_world == true
|
||||||
*/
|
*/
|
||||||
void UpdateNearestTownForRoadTiles(bool invalidate, const Town *ignore)
|
void UpdateNearestTownForRoadTiles(bool invalidate)
|
||||||
{
|
{
|
||||||
assert(!invalidate || _generating_world);
|
assert(!invalidate || _generating_world);
|
||||||
|
|
||||||
@ -1256,7 +1256,7 @@ void UpdateNearestTownForRoadTiles(bool invalidate, const Town *ignore)
|
|||||||
if (IsTileType(t, MP_ROAD) && !HasTownOwnedRoad(t)) {
|
if (IsTileType(t, MP_ROAD) && !HasTownOwnedRoad(t)) {
|
||||||
TownID tid = (TownID)INVALID_TOWN;
|
TownID tid = (TownID)INVALID_TOWN;
|
||||||
if (!invalidate) {
|
if (!invalidate) {
|
||||||
const Town *town = CalcClosestTownFromTile(t, UINT_MAX, ignore);
|
const Town *town = CalcClosestTownFromTile(t);
|
||||||
if (town != NULL) tid = town->index;
|
if (town != NULL) tid = town->index;
|
||||||
}
|
}
|
||||||
SetTownIndex(t, tid);
|
SetTownIndex(t, tid);
|
||||||
|
@ -8,6 +8,6 @@
|
|||||||
#include "direction_type.h"
|
#include "direction_type.h"
|
||||||
|
|
||||||
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt);
|
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 */
|
#endif /* ROAD_CMD_H */
|
||||||
|
@ -142,6 +142,7 @@ struct Town : TownPool::PoolItem<&_town_pool> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Town *GetRandom();
|
static Town *GetRandom();
|
||||||
|
static void PostDestructor(size_t index);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32 GetWorldPopulation();
|
uint32 GetWorldPopulation();
|
||||||
@ -181,7 +182,7 @@ bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
|
|||||||
|
|
||||||
TileIndexDiff GetHouseNorthPart(HouseID &house);
|
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_FROM(var, start) FOR_ALL_ITEMS_FROM(Town, town_index, var, start)
|
||||||
#define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
|
#define FOR_ALL_TOWNS(var) FOR_ALL_TOWNS_FROM(var, 0)
|
||||||
|
@ -102,8 +102,17 @@ Town::~Town()
|
|||||||
DeleteSubsidyWithTown(this->index);
|
DeleteSubsidyWithTown(this->index);
|
||||||
|
|
||||||
MarkWholeScreenDirty();
|
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;
|
Town *t;
|
||||||
uint best = threshold;
|
uint best = threshold;
|
||||||
Town *best_town = NULL;
|
Town *best_town = NULL;
|
||||||
|
|
||||||
FOR_ALL_TOWNS(t) {
|
FOR_ALL_TOWNS(t) {
|
||||||
if (t == ignore) continue;
|
|
||||||
uint dist = DistanceManhattan(tile, t->xy);
|
uint dist = DistanceManhattan(tile, t->xy);
|
||||||
if (dist < best) {
|
if (dist < best) {
|
||||||
best = dist;
|
best = dist;
|
||||||
|
Loading…
Reference in New Issue
Block a user