(svn r4120) Use the new station functions where appropriate
authortron
Sun, 26 Mar 2006 19:20:15 +0000
changeset 3338 7cff208f0446
parent 3337 3a9b086c6369
child 3339 cd4199eef081
(svn r4120) Use the new station functions where appropriate
ai/default/default.c
ai/trolly/trolly.c
aircraft_cmd.c
aircraft_gui.c
disaster_cmd.c
industry_cmd.c
order_gui.c
roadveh_cmd.c
smallmap_gui.c
station_map.h
vehicle.h
water_cmd.c
--- a/ai/default/default.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/ai/default/default.c	Sun Mar 26 19:20:15 2006 +0000
@@ -359,7 +359,7 @@
 	BackuppedOrders orderbak[1];
 	EngineID veh;
 
-	if (!IsAircraftHangarTile(v->tile) || !(v->vehstatus&VS_STOPPED)) {
+	if (!IsHangarTile(v->tile) || !(v->vehstatus & VS_STOPPED)) {
 		AiHandleGotoDepot(p, CMD_SEND_AIRCRAFT_TO_HANGAR);
 		return;
 	}
@@ -3176,15 +3176,6 @@
 	p->ai.state = AIS_0;
 }
 
-static bool AiCheckIfHangar(Station *st)
-{
-	TileIndex tile = st->airport_tile;
-
-	// HANGAR of airports
-	// 0x20 - hangar large airport (32)
-	// 0x41 - hangar small airport (65)
-	return (_m[tile].m5 == 32 || _m[tile].m5 == 65);
-}
 
 static void AiStateAirportStuff(Player *p)
 {
@@ -3245,7 +3236,7 @@
 			 * here for now (some of the new airport types would be
 			 * broken because they will probably need different
 			 * tileoff values etc), no matter that
-			 * AiCheckIfHangar() makes no sense. --pasky */
+			 * IsHangarTile() makes no sense. --pasky */
 			if (acc_planes == HELICOPTERS_ONLY) {
 				/* Heliports should have maybe own rulesets but
 				 * OTOH we don't want AI to pick them up when
@@ -3255,7 +3246,7 @@
 				 * because we have no such rule. */
 				rule = 1;
 			} else {
-				rule = AiCheckIfHangar(st);
+				rule = IsHangarTile(st->airport_tile);
 			}
 
 			aib->cur_building_rule = rule;
@@ -3504,7 +3495,7 @@
 
 			DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
 		} else if (v->type == VEH_Aircraft) {
-			if (!IsAircraftHangarTile(v->tile) || !(v->vehstatus & VS_STOPPED)) {
+			if (!IsHangarTile(v->tile) || !(v->vehstatus & VS_STOPPED)) {
 				if (v->current_order.type != OT_GOTO_DEPOT)
 					DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 				goto going_to_depot;
--- a/ai/trolly/trolly.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/ai/trolly/trolly.c	Sun Mar 26 19:20:15 2006 +0000
@@ -617,9 +617,7 @@
 							if (AiNew_CheckVehicleStation(p, st)) {
 								// We did found a station that was good enough!
 								new_tile = st->xy;
-								// Cheap way to get the direction of the station...
-								//  Bus stations save it as 0x47 .. 0x4A, so decrease it with 0x47, and tada!
-								direction = _m[st->xy].m5 - 0x47;
+								direction = GetRoadStationDir(st->xy);
 								break;
 							}
 						}
--- a/aircraft_cmd.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/aircraft_cmd.c	Sun Mar 26 19:20:15 2006 +0000
@@ -150,7 +150,7 @@
 	// to just query the cost, it is not neccessary to have a valid tile (automation/AI)
 	if (flags & DC_QUERY_COST) return value;
 
-	if (!IsAircraftHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
+	if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
 
 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
@@ -305,18 +305,10 @@
 	return value;
 }
 
-bool IsAircraftHangarTile(TileIndex tile)
-{
-	// 0x56 - hangar facing other way international airport (86)
-	// 0x20 - hangar large airport (32)
-	// 0x41 - hangar small airport (65)
-	return IsTileType(tile, MP_STATION) &&
-				(_m[tile].m5 == 32 || _m[tile].m5 == 65 || _m[tile].m5 == 86);
-}
 
 bool CheckStoppedInHangar(const Vehicle* v)
 {
-	return v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile);
+	return v->vehstatus & VS_STOPPED && IsHangarTile(v->tile);
 }
 
 
@@ -378,7 +370,7 @@
 		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
 
 	if (flags & DC_EXEC) {
-		if (v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile)) {
+		if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) {
 			DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN);
 		}
 
--- a/aircraft_gui.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/aircraft_gui.c	Sun Mar 26 19:20:15 2006 +0000
@@ -502,9 +502,7 @@
 		uint32 disabled = 1 << 8;
 		StringID str;
 
-		if (v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile)) {
-			disabled = 0;
-		}
+		if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) disabled = 0;
 
 		if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7;
 		w->disabled_state = disabled;
@@ -1033,7 +1031,7 @@
 			DrawVehicleProfitButton(v, x, y + 13);
 
 			SetDParam(0, v->unitnumber);
-			if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) {
+			if (IsHangarTile(v->tile) && v->vehstatus & VS_HIDDEN) {
 				str = STR_021F;
 			} else {
 				str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
@@ -1096,7 +1094,7 @@
 
 			tile = _last_built_aircraft_depot_tile;
 			do {
-				if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
+				if (IsHangarTile(tile) && IsTileOwner(tile, _local_player)) {
 					ShowAircraftDepotWindow(tile);
 					ShowBuildAircraftWindow(tile);
 					return;
--- a/disaster_cmd.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/disaster_cmd.c	Sun Mar 26 19:20:15 2006 +0000
@@ -179,7 +179,7 @@
 
 			if (IsValidTile(tile) &&
 					IsTileType(tile, MP_STATION) &&
-					IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
+					IsAirport(tile) &&
 					IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 				v->current_order.station = 1;
 				v->age = 0;
@@ -204,7 +204,7 @@
 
 		if (IsValidTile(tile) &&
 				IsTileType(tile, MP_STATION) &&
-				IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
+				IsAirport(tile) &&
 				IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 			st = GetStationByTile(tile);
 			CLRBITS(st->airport_flags, RUNWAY_IN_block);
@@ -246,7 +246,7 @@
 	tile = v->tile;/**/
 	if (IsValidTile(tile) &&
 			IsTileType(tile, MP_STATION) &&
-			IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
+			IsAirport(tile) &&
 			IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 		st = GetStationByTile(tile);
 		SETBITS(st->airport_flags, RUNWAY_IN_block);
--- a/industry_cmd.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/industry_cmd.c	Sun Mar 26 19:20:15 2006 +0000
@@ -4,6 +4,7 @@
 #include "openttd.h"
 #include "clear_map.h"
 #include "industry_map.h"
+#include "station_map.h"
 #include "table/strings.h"
 #include "table/sprites.h"
 #include "functions.h"
@@ -877,7 +878,7 @@
 			if (GetIndustryIndex(tile_cur) == i->index) {
 				DoClearSquare(tile_cur);
 			}
-		} else if (IsTileType(tile_cur, MP_STATION) && _m[tile_cur].m5 == 0x4B) {
+		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 			DeleteOilRig(tile_cur);
 		}
 	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
--- a/order_gui.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/order_gui.c	Sun Mar 26 19:20:15 2006 +0000
@@ -218,7 +218,7 @@
 
 		case MP_STATION:
 			if (v->type != VEH_Aircraft) break;
-			if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
+			if (IsHangar(tile) && IsTileOwner(tile, _local_player)) {
 				order.type = OT_GOTO_DEPOT;
 				order.flags = OF_PART_OF_ORDERS;
 				order.station = GetStationIndex(tile);
--- a/roadveh_cmd.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/roadveh_cmd.c	Sun Mar 26 19:20:15 2006 +0000
@@ -1088,8 +1088,7 @@
 				goto do_it;
 			}
 		} else if (IsTileType(desttile, MP_STATION)) {
-			if (IS_BYTE_INSIDE(_m[desttile].m5, 0x43, 0x4B)) {
-				/* We are heading for a station */
+			if (IsRoadStop(desttile)) {
 				dir = GetRoadStationDir(desttile);
 do_it:;
 				/* When we are heading for a depot or station, we just
@@ -1321,7 +1320,7 @@
 				v->cur_speed = 0;
 				return;
 			}
-			if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
+			if (IsRoadStop(v->tile)) {
 				RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 
 				// reached a loading bay, mark it as used and clear the usage bit
--- a/smallmap_gui.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/smallmap_gui.c	Sun Mar 26 19:20:15 2006 +0000
@@ -6,6 +6,7 @@
 #include "clear_map.h"
 #include "functions.h"
 #include "spritecache.h"
+#include "station_map.h"
 #include "table/strings.h"
 #include "table/sprites.h"
 #include "map.h"
@@ -445,14 +446,15 @@
 	uint32 bits;
 
 	if (t == MP_STATION) {
-		byte m5 = _m[tile].m5;
-		(bits = MKCOLOR(0x56565656), m5 < 8) ||			//   8 - railroad station (green)
-		(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x43) ||	//  67 - airport (red)
-		(bits = MKCOLOR(0xC2C2C2C2), m5 < 0x47) ||	//  71 - truck loading bay (orange)
-		(bits = MKCOLOR(0xBFBFBFBF), m5 < 0x4B) ||	//  75 - bus station (yellow)
-		(bits = MKCOLOR(0x98989898), m5 < 0x53) ||	//  83 - docks (blue)
-		(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x73) ||	// 115 - airport (red) (new airports)
-		(bits = MKCOLOR(0xFFFFFFFF), true);					// all others
+		switch (GetStationType(tile)) {
+			case STATION_RAIL:    bits = MKCOLOR(0x56565656); break;
+			case STATION_HANGAR:
+			case STATION_AIRPORT: bits = MKCOLOR(0xB8B8B8B8); break;
+			case STATION_TRUCK:   bits = MKCOLOR(0xC2C2C2C2); break;
+			case STATION_BUS:     bits = MKCOLOR(0xBFBFBFBF); break;
+			case STATION_DOCK:    bits = MKCOLOR(0x98989898); break;
+			default:              bits = MKCOLOR(0xFFFFFFFF); break;
+		}
 	} else {
 		// ground color
 		bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);
--- a/station_map.h	Sun Mar 26 19:03:03 2006 +0000
+++ b/station_map.h	Sun Mar 26 19:20:15 2006 +0000
@@ -111,6 +111,12 @@
 }
 
 
+static inline bool IsHangarTile(TileIndex t)
+{
+	return IsTileType(t, MP_STATION) && IsHangar(t);
+}
+
+
 static inline Axis GetRailStationAxis(TileIndex t)
 {
 	assert(IsRailwayStation(t));
--- a/vehicle.h	Sun Mar 26 19:03:03 2006 +0000
+++ b/vehicle.h	Sun Mar 26 19:20:15 2006 +0000
@@ -300,7 +300,6 @@
 void BeginVehicleMove(Vehicle *v);
 void EndVehicleMove(Vehicle *v);
 
-bool IsAircraftHangarTile(TileIndex tile);
 void ShowAircraftViewWindow(const Vehicle* v);
 
 UnitID GetFreeUnitNumber(byte type);
--- a/water_cmd.c	Sun Mar 26 19:03:03 2006 +0000
+++ b/water_cmd.c	Sun Mar 26 19:20:15 2006 +0000
@@ -3,6 +3,7 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "bridge_map.h"
+#include "station_map.h"
 #include "table/sprites.h"
 #include "table/strings.h"
 #include "functions.h"
@@ -340,17 +341,13 @@
 // return true if a tile is a water tile.
 static bool IsWateredTile(TileIndex tile)
 {
-	byte m5 = _m[tile].m5;
-
 	switch (GetTileType(tile)) {
 		case MP_WATER:
 			// true, if not coast/riverbank
-			return m5 != 1;
+			return _m[tile].m5 != 1;
 
 		case MP_STATION:
-			// returns true if it is a dock-station
-			// m5 inside values is m5 < 75 all stations, 83 <= m5 <= 114 new airports
-			return !(m5 < 75 || (m5 >= 83 && m5 <= 114));
+			return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile);
 
 		case MP_TUNNELBRIDGE:
 			return IsBridge(tile) && IsBridgeMiddle(tile) && IsWaterUnderBridge(tile);