(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
authorcelestar
Thu, 30 Mar 2006 15:06:49 +0000
changeset 3377 014725164f97
parent 3376 a946f51034e7
child 3378 6f5846e508e0
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
town_cmd.c
town_map.h
--- a/town_cmd.c	Thu Mar 30 13:12:36 2006 +0000
+++ b/town_cmd.c	Thu Mar 30 15:06:49 2006 +0000
@@ -99,7 +99,7 @@
 	/* Retrieve pointer to the draw town tile struct */
 	{
 		/* this "randomizes" on the (up to) 4 variants of a building */
-		byte gfx   = _m[ti->tile].m4;
+		byte gfx   = GetHouseType(ti->tile);
 		byte stage = GB(_m[ti->tile].m3, 6, 2);
 		uint variant;
 		variant  = ti->x >> 4;
@@ -166,7 +166,7 @@
 	// Not exactly sure when this happens, but probably when a house changes.
 	// Before this was just a return...so it'd leak animated tiles..
 	// That bug seems to have been here since day 1??
-	if (!(_housetype_extra_flags[_m[tile].m4] & 0x20)) {
+	if (!(_housetype_extra_flags[GetHouseType(tile)] & 0x20)) {
 		DeleteAnimatedTile(tile);
 		return;
 	}
@@ -267,14 +267,14 @@
 	_m[tile].m3 = _m[tile].m3 + 0x40;
 
 	if ((_m[tile].m3 & 0xC0) == 0xC0) {
-		ChangePopulation(GetTownByTile(tile), _housetype_population[_m[tile].m4]);
+		ChangePopulation(GetTownByTile(tile), _housetype_population[GetHouseType(tile)]);
 	}
 	MarkTileDirtyByTile(tile);
 }
 
 static void MakeTownHouseBigger(TileIndex tile)
 {
-	uint flags = _house_more_flags[_m[tile].m4];
+	uint flags = _house_more_flags[GetHouseType(tile)];
 	if (flags & 8) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0));
 	if (flags & 4) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1));
 	if (flags & 2) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0));
@@ -292,7 +292,7 @@
 		return;
 	}
 
-	house = _m[tile].m4;
+	house = GetHouseType(tile);
 	if (_housetype_extra_flags[house] & 0x20 &&
 			!(_m[tile].m5 & 0x80) &&
 			CHANCE16(1, 2) &&
@@ -353,7 +353,7 @@
 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 	if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 
-	house = _m[tile].m4;
+	house = GetHouseType(tile);
 	cost = _price.remove_house * _housetype_remove_cost[house] >> 8;
 
 	rating = _housetype_remove_ratingmod[house];
@@ -377,7 +377,7 @@
 
 static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
 {
-	byte type = _m[tile].m4;
+	byte type = GetHouseType(tile);
 
 	ac[CT_PASSENGERS] = _housetype_cargo_passengers[type];
 	ac[CT_MAIL]       = _housetype_cargo_mail[type];
@@ -387,7 +387,7 @@
 
 static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
 {
-	td->str = _town_tile_names[_m[tile].m4];
+	td->str = _town_tile_names[GetHouseType(tile)];
 	if ((_m[tile].m3 & 0xC0) != 0xC0) {
 		SetDParamX(td->dparam, 0, td->str);
 		td->str = STR_2058_UNDER_CONSTRUCTION;
@@ -1378,7 +1378,7 @@
 
 static void ClearTownHouse(Town *t, TileIndex tile)
 {
-	uint house = _m[tile].m4;
+	uint house = GetHouseType(tile);
 	uint eflags;
 
 	assert(IsTileType(tile, MP_HOUSE));
--- a/town_map.h	Thu Mar 30 13:12:36 2006 +0000
+++ b/town_map.h	Thu Mar 30 15:06:49 2006 +0000
@@ -2,6 +2,11 @@
 
 #include "town.h"
 
+static inline int GetHouseType(TileIndex t)
+{
+	assert(IsTileType(t, MP_HOUSE));
+	return _m[t].m4;
+}
 
 static inline uint GetTownIndex(TileIndex t)
 {