changeset 3540:9ce56da91abd draft

(svn r4403) CodeChange : Add GetStationGfx and make use of [G|S]etStationGfx accessors. Also, use GetStationGfx instead of directly accessing the map for functions in station_map.h
author belugas <belugas@openttd.org>
date Wed, 12 Apr 2006 20:01:52 +0000
parents 0bd856c18296
children 91a08939858d
files station_cmd.c station_map.h
diffstat 2 files changed, 51 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2066,7 +2066,7 @@
 {
 	// FIXME -- GetTileTrackStatus_Station -> animated stationtiles
 	// hardcoded.....not good
-	switch (_m[tile].m5) {
+	switch (GetStationGfx(tile)) {
 		case 0x27: // large big airport
 		case 0x3A: // flag small airport
 		case 0x5A: // radar international airport
@@ -2086,41 +2086,41 @@
 
 static void AnimateTile_Station(TileIndex tile)
 {
-	byte m5 = _m[tile].m5;
+	byte gfx = GetStationGfx(tile);
 	//FIXME -- AnimateTile_Station -> not nice code, lots of things double
   // again hardcoded...was a quick hack
 
   // turning radar / windsack on airport
-	if (m5 >= 39 && m5 <= 50) { // turning radar (39 - 50)
+	if (gfx >= 39 && gfx <= 50) { // turning radar (39 - 50)
 		if (_tick_counter & 3)
 			return;
 
-		if (++m5 == 50+1)
-			m5 = 39;
-
-		_m[tile].m5 = m5;
+		if (++gfx == 50+1)
+			gfx = 39;
+
+		SetStationGfx(tile, gfx);
 		MarkTileDirtyByTile(tile);
   //added - begin
-	} else if (m5 >= 90 && m5 <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113)
+	} else if (gfx >= 90 && gfx <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113)
 		if (_tick_counter & 3)
 			return;
 
-		m5++;
-
-		if (m5 == 101+1) {m5 = 90;}  // radar with fences in south
-		else if (m5 == 113+1) {m5 = 102;} // radar with fences in north
-
-		_m[tile].m5 = m5;
+		gfx++;
+
+		if (gfx == 101+1) {gfx = 90;}  // radar with fences in south
+		else if (gfx == 113+1) {gfx = 102;} // radar with fences in north
+
+		SetStationGfx(tile, gfx);
 		MarkTileDirtyByTile(tile);
 	//added - end
-	} else if (m5 >= 0x3A && m5 <= 0x3D) {  // windsack (58 - 61)
+	} else if (gfx >= 0x3A && gfx <= 0x3D) {  // windsack (58 - 61)
 		if (_tick_counter & 1)
 			return;
 
-		if (++m5 == 0x3D+1)
-			m5 = 0x3A;
-
-		_m[tile].m5 = m5;
+		if (++gfx == 0x3D+1)
+			gfx = 0x3A;
+
+		SetStationGfx(tile, gfx);
 		MarkTileDirtyByTile(tile);
 	}
 }
--- a/station_map.h
+++ b/station_map.h
@@ -65,10 +65,21 @@
 	return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS;
 }
 
+static inline byte GetStationGfx(TileIndex t)
+{
+	assert(IsTileType(t, MP_STATION));
+	return _m[t].m5;
+}
+
+static inline void SetStationGfx(TileIndex t, byte gfx)
+{
+	assert(IsTileType(t, MP_STATION));
+	_m[t].m5 = gfx;
+}
+
 static inline bool IsRailwayStation(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
-	return _m[t].m5 < RAILWAY_BASE + RAILWAY_SIZE;
+	return GetStationGfx(t) < RAILWAY_BASE + RAILWAY_SIZE;
 }
 
 static inline bool IsRailwayStationTile(TileIndex t)
@@ -78,31 +89,29 @@
 
 static inline bool IsHangar(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
+	byte gfx = GetStationGfx(t);
 	return
-		_m[t].m5 == HANGAR_TILE_0 ||
-		_m[t].m5 == HANGAR_TILE_1 ||
-		_m[t].m5 == HANGAR_TILE_2;
+		gfx == HANGAR_TILE_0 ||
+		gfx == HANGAR_TILE_1 ||
+		gfx == HANGAR_TILE_2;
 }
 
 static inline bool IsAirport(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
+	byte gfx = GetStationGfx(t);
 	return
-		IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE, AIRPORT_BASE + AIRPORT_SIZE) ||
-		IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE_EXTENDED, AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED);
+		IS_INT_INSIDE(gfx, AIRPORT_BASE, AIRPORT_BASE + AIRPORT_SIZE) ||
+		IS_INT_INSIDE(gfx, AIRPORT_BASE_EXTENDED, AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED);
 }
 
 static inline bool IsTruckStop(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
-	return IS_INT_INSIDE(_m[t].m5, TRUCK_BASE, TRUCK_BASE + TRUCK_SIZE);
+	return IS_INT_INSIDE(GetStationGfx(t), TRUCK_BASE, TRUCK_BASE + TRUCK_SIZE);
 }
 
 static inline bool IsBusStop(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
-	return IS_INT_INSIDE(_m[t].m5, BUS_BASE, BUS_BASE + BUS_SIZE);
+	return IS_INT_INSIDE(GetStationGfx(t), BUS_BASE, BUS_BASE + BUS_SIZE);
 }
 
 static inline bool IsRoadStop(TileIndex t)
@@ -118,28 +127,25 @@
 /**
  * Gets the direction the road stop entrance points towards.
  */
-static inline DiagDirection GetRoadStopDir(TileIndex tile)
+static inline DiagDirection GetRoadStopDir(TileIndex t)
 {
-	assert(IsRoadStopTile(tile));
-	return (_m[tile].m5 - TRUCK_BASE) & 3;
+	assert(IsRoadStopTile(t));
+	return (GetStationGfx(t) - TRUCK_BASE) & 3;
 }
 
 static inline bool IsOilRig(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
-	return _m[t].m5 == OILRIG_BASE;
+	return GetStationGfx(t) == OILRIG_BASE;
 }
 
 static inline bool IsDock(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
-	return IS_INT_INSIDE(_m[t].m5, DOCK_BASE, DOCK_BASE + DOCK_SIZE_TOTAL);
+	return IS_INT_INSIDE(GetStationGfx(t), DOCK_BASE, DOCK_BASE + DOCK_SIZE_TOTAL);
 }
 
 static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict
 {
-	assert(IsTileType(t, MP_STATION));
-	return _m[t].m5 == BUOY_BASE;
+	return GetStationGfx(t) == BUOY_BASE;
 }
 
 static inline bool IsBuoyTile(TileIndex t)
@@ -156,8 +162,7 @@
 
 static inline Axis GetRailStationAxis(TileIndex t)
 {
-	assert(IsRailwayStation(t));
-	return HASBIT(_m[t].m5, 0) ? AXIS_Y : AXIS_X;
+	return HASBIT(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X;
 }
 
 
@@ -178,10 +183,9 @@
 
 static inline DiagDirection GetDockDirection(TileIndex t)
 {
-	assert(IsTileType(t, MP_STATION));
-	assert(_m[t].m5 < DOCK_BASE_WATER_PART);
-
-	return (DiagDirection)(_m[t].m5 - DOCK_BASE);
+	byte gfx = GetStationGfx(t);
+	assert(gfx < DOCK_BASE_WATER_PART);
+	return (DiagDirection)(gfx - DOCK_BASE);
 }
 
 static inline TileIndexDiffC GetDockOffset(TileIndex t)
@@ -223,13 +227,6 @@
 	return _m[t].m4;
 }
 
-static inline byte GetStationGfx(TileIndex t)
-{
-	assert(IsTileType(t, MP_STATION));
-	return _m[t].m5;
-}
-
-
 static inline void MakeStation(TileIndex t, Owner o, StationID sid, byte m5)
 {
 	SetTileType(t, MP_STATION);