(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
authortron
Fri, 24 Mar 2006 12:00:24 +0000
changeset 3319 16c0f06829a5
parent 3318 15ec70e8e6cb
child 3320 e9e284ab853a
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
rail_cmd.c
road_cmd.c
town_cmd.c
town_map.h
--- a/rail_cmd.c	Fri Mar 24 10:53:49 2006 +0000
+++ b/rail_cmd.c	Fri Mar 24 12:00:24 2006 +0000
@@ -11,6 +11,7 @@
 #include "table/strings.h"
 #include "map.h"
 #include "tile.h"
+#include "town_map.h"
 #include "tunnel_map.h"
 #include "vehicle.h"
 #include "viewport.h"
@@ -321,7 +322,7 @@
 						(track == TRACK_Y && GetRoadBits(tile) == ROAD_X)
 					)) {
 				if (flags & DC_EXEC) {
-					MakeRoadCrossing(tile, GetTileOwner(tile), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), p1, _m[tile].m2);
+					MakeRoadCrossing(tile, GetTileOwner(tile), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), p1, GetTownIndex(tile));
 				}
 				break;
 			}
@@ -396,7 +397,7 @@
 			}
 
 			if (flags & DC_EXEC) {
-				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), _m[tile].m2);
+				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile));
 			}
 			break;
 		}
--- a/road_cmd.c	Fri Mar 24 10:53:49 2006 +0000
+++ b/road_cmd.c	Fri Mar 24 12:00:24 2006 +0000
@@ -10,6 +10,7 @@
 #include "functions.h"
 #include "map.h"
 #include "tile.h"
+#include "town_map.h"
 #include "vehicle.h"
 #include "viewport.h"
 #include "command.h"
@@ -109,7 +110,7 @@
 		if (IsTileType(tile, MP_TUNNELBRIDGE)) { // index of town is not saved for bridge (no space)
 			t = ClosestTownFromTile(tile, _patches.dist_local_authority);
 		} else {
-			t = GetTown(_m[tile].m2);
+			t = GetTownByTile(tile);
 		}
 	} else {
 		t = NULL;
@@ -1106,7 +1107,7 @@
 				break;
 
 			case ROAD_CROSSING:
-				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), _m[tile].m2);
+				MakeRoadNormal(tile, GetCrossingRoadOwner(tile), GetCrossingRoadBits(tile), GetTownIndex(tile));
 				break;
 
 			default:
--- a/town_cmd.c	Fri Mar 24 10:53:49 2006 +0000
+++ b/town_cmd.c	Fri Mar 24 12:00:24 2006 +0000
@@ -9,6 +9,7 @@
 #include "table/sprites.h"
 #include "map.h"
 #include "tile.h"
+#include "town_map.h"
 #include "tunnel_map.h"
 #include "viewport.h"
 #include "town.h"
@@ -265,7 +266,7 @@
 	_m[tile].m3 = _m[tile].m3 + 0x40;
 
 	if ((_m[tile].m3 & 0xC0) == 0xC0) {
-		ChangePopulation(GetTown(_m[tile].m2), _housetype_population[_m[tile].m4]);
+		ChangePopulation(GetTownByTile(tile), _housetype_population[_m[tile].m4]);
 	}
 	MarkTileDirtyByTile(tile);
 }
@@ -298,7 +299,7 @@
 		_m[tile].m5 = (_m[tile].m5 & 0x40) | 0x80;
 	}
 
-	t = GetTown(_m[tile].m2);
+	t = GetTownByTile(tile);
 
 	r = Random();
 
@@ -356,7 +357,7 @@
 
 	rating = _housetype_remove_ratingmod[house];
 	_cleared_town_rating += rating;
-	_cleared_town = t = GetTown(_m[tile].m2);
+	_cleared_town = t = GetTownByTile(tile);
 
 	if (_current_player < MAX_PLAYERS) {
 		if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
@@ -743,7 +744,7 @@
 
 		if (IsTileType(tile, MP_STREET)) {
 			/* Don't allow building over roads of other cities */
-			if (IsTileOwner(tile, OWNER_TOWN) && GetTown(_m[tile].m2) != t)
+			if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t)
 				_grow_town_result = -1;
 			else if (_game_mode == GM_EDITOR) {
 				/* If we are in the SE, and this road-piece has no town owner yet, it just found an
@@ -1483,7 +1484,7 @@
 	for (tile = 0; tile < MapSize(); ++tile) {
 		switch (GetTileType(tile)) {
 			case MP_HOUSE:
-				if (GetTown(_m[tile].m2) == t)
+				if (GetTownByTile(tile) == t)
 					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 				break;
 
@@ -1830,7 +1831,7 @@
 				IsTileType(tile, MP_STREET) &&
 				(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN
 			))
-		return GetTown(_m[tile].m2);
+		return GetTownByTile(tile);
 
 	FOR_ALL_TOWNS(t) {
 		if (t->xy != 0) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/town_map.h	Fri Mar 24 12:00:24 2006 +0000
@@ -0,0 +1,14 @@
+/* $Id$ */
+
+#include "town.h"
+
+
+static inline uint GetTownIndex(TileIndex t)
+{
+	return _m[t].m2;
+}
+
+static inline Town* GetTownByTile(TileIndex t)
+{
+	return GetTown(GetTownIndex(t));
+}