summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-06-08 18:31:54 +0000
committertron <tron@openttd.org>2006-06-08 18:31:54 +0000
commit7c1f1d823f059e3e8c8a336b6acb819c0ee5a03c (patch)
tree1721f3f0ea1d8ad323751b7106f968c10d52a3b2
parentb690e85604ce3f024dab32bf19a23afe992090e7 (diff)
downloadopenttd-7c1f1d823f059e3e8c8a336b6acb819c0ee5a03c.tar.xz
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
-rw-r--r--openttd.c32
-rw-r--r--town_cmd.c22
-rw-r--r--town_map.h9
3 files changed, 37 insertions, 26 deletions
diff --git a/openttd.c b/openttd.c
index 0589f84b7..d3f831fca 100644
--- a/openttd.c
+++ b/openttd.c
@@ -1210,22 +1210,22 @@ bool AfterLoadGame(void)
* all about ;) */
if (CheckSavegameVersionOldStyle(6, 1)) {
BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
- if (IsTileType(tile, MP_HOUSE)) {
- _m[tile].m4 = _m[tile].m2;
- //XXX magic
- SetTileType(tile, MP_VOID);
- _m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
- SetTileType(tile, MP_HOUSE);
- } else if (IsTileType(tile, MP_STREET)) {
- //XXX magic
- _m[tile].m4 |= (_m[tile].m2 << 4);
- if (IsTileOwner(tile, OWNER_TOWN)) {
- SetTileType(tile, MP_VOID);
- _m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index;
- SetTileType(tile, MP_STREET);
- } else {
- SetTownIndex(tile, 0);
- }
+ switch (GetTileType(tile)) {
+ case MP_HOUSE:
+ _m[tile].m4 = _m[tile].m2;
+ SetTownIndex(tile, CalcClosestTownFromTile(tile, (uint)-1)->index);
+ break;
+
+ case MP_STREET:
+ _m[tile].m4 |= (_m[tile].m2 << 4);
+ if (IsTileOwner(tile, OWNER_TOWN)) {
+ SetTownIndex(tile, CalcClosestTownFromTile(tile, (uint)-1)->index);
+ } else {
+ SetTownIndex(tile, 0);
+ }
+ break;
+
+ default: break;
}
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
}
diff --git a/town_cmd.c b/town_cmd.c
index 2c7a8653c..753be77b4 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1739,18 +1739,12 @@ bool CheckIfAuthorityAllows(TileIndex tile)
}
-Town *ClosestTownFromTile(TileIndex tile, uint threshold)
+Town* CalcClosestTownFromTile(TileIndex tile, uint threshold)
{
Town *t;
uint dist, best = threshold;
Town *best_town = NULL;
- if (IsTileType(tile, MP_HOUSE) || (
- IsTileType(tile, MP_STREET) &&
- (IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN
- ))
- return GetTownByTile(tile);
-
FOR_ALL_TOWNS(t) {
if (t->xy != 0) {
dist = DistanceManhattan(tile, t->xy);
@@ -1764,6 +1758,20 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold)
return best_town;
}
+
+Town *ClosestTownFromTile(TileIndex tile, uint threshold)
+{
+ if (IsTileType(tile, MP_HOUSE) || (
+ IsTileType(tile, MP_STREET) &&
+ (IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN
+ )) {
+ return GetTownByTile(tile);
+ } else {
+ return CalcClosestTownFromTile(tile, threshold);
+ }
+}
+
+
void ChangeTownRating(Town *t, int add, int max)
{
int rating;
diff --git a/town_map.h b/town_map.h
index 88148152c..bc546cd10 100644
--- a/town_map.h
+++ b/town_map.h
@@ -20,14 +20,13 @@ static inline TownID GetTownIndex(TileIndex t)
}
/**
- * Set the town index for a street tile.
+ * Set the town index for a road or house tile.
* @param tile the tile
* @param index the index of the town
- * @pre IsTileType(tile, MP_STREET)
*/
static inline void SetTownIndex(TileIndex t, TownID index)
{
- assert(IsTileType(t, MP_STREET));
+ assert(IsTileType(t, MP_STREET) || IsTileType(t, MP_HOUSE));
_m[t].m2 = index;
}
@@ -81,6 +80,10 @@ static inline Town* GetTownByTile(TileIndex t)
return GetTown(GetTownIndex(t));
}
+
+Town* CalcClosestTownFromTile(TileIndex tile, uint threshold);
+
+
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
{
assert(IsTileType(t, MP_CLEAR));