(svn r5281) -Backport: r5124 0.4
authortron
Thu, 15 Jun 2006 14:45:03 +0000
branch0.4
changeset 10035 23985f53225c
parent 10034 76c349a8330a
child 10036 1b119438cefb
(svn r5281) -Backport: r5124
-Fix: Be more strict what it means for an aircraft to be in a hangar: It's not just being stopped on a hangar tile
aircraft.h
aircraft_cmd.c
aircraft_gui.c
station_map.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aircraft.h	Thu Jun 15 14:45:03 2006 +0000
@@ -0,0 +1,16 @@
+/* $Id$ */
+
+#include "station_map.h"
+#include "vehicle.h"
+
+
+static inline bool IsAircraftInHangar(const Vehicle* v)
+{
+	assert(v->type == VEH_Aircraft);
+	return v->vehstatus & VS_HIDDEN && IsHangarTile(v->tile);
+}
+
+static inline bool IsAircraftInHangarStopped(const Vehicle* v)
+{
+	return IsAircraftInHangar(v) && v->vehstatus & VS_STOPPED;
+}
--- a/aircraft_cmd.c	Thu Jun 15 14:34:31 2006 +0000
+++ b/aircraft_cmd.c	Thu Jun 15 14:45:03 2006 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "aircraft.h"
 #include "debug.h"
 #include "functions.h"
 #include "table/strings.h"
@@ -312,16 +313,6 @@
 				(_m[tile].m5 == 32 || _m[tile].m5 == 65 || _m[tile].m5 == 86);
 }
 
-bool CheckStoppedInHangar(const Vehicle* v)
-{
-	if (!(v->vehstatus & VS_STOPPED) || !IsAircraftHangarTile(v->tile)) {
-		_error_message = STR_A01B_AIRCRAFT_MUST_BE_STOPPED;
-		return false;
-	}
-
-	return true;
-}
-
 
 static void DoDeleteAircraft(Vehicle *v)
 {
@@ -345,8 +336,8 @@
 
 	v = GetVehicle(p1);
 
-	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner) || !CheckStoppedInHangar(v))
-		return CMD_ERROR;
+	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
+	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
 
 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
@@ -472,7 +463,7 @@
 	v = GetVehicle(p1);
 
 	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
-	if (!CheckStoppedInHangar(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
+	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
 
 	avi = AircraftVehInfo(v->engine_type);
 
--- a/aircraft_gui.c	Thu Jun 15 14:34:31 2006 +0000
+++ b/aircraft_gui.c	Thu Jun 15 14:45:03 2006 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "aircraft.h"
 #include "debug.h"
 #include "functions.h"
 #include "table/sprites.h"
@@ -492,7 +493,6 @@
 { WIDGETS_END }
 };
 
-bool CheckStoppedInHangar(const Vehicle* v); /* XXX extern function declaration in .c */
 
 static void AircraftViewWndProc(Window *w, WindowEvent *e)
 {
@@ -502,9 +502,7 @@
 		uint32 disabled = 1 << 8;
 		StringID str;
 
-		if (v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile)) {
-			disabled = 0;
-		}
+		if (IsAircraftInHangarStopped(v)) disabled = 0;
 
 		if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7;
 		w->disabled_state = disabled;
@@ -597,7 +595,7 @@
 
 	case WE_MOUSELOOP: {
 		const Vehicle* v = GetVehicle(w->window_number);
-		uint32 h = CheckStoppedInHangar(v) ? (1 << 7) : (1 << 11);
+		uint32 h = IsAircraftInHangarStopped(v) ? 1 << 7 : 1 << 11;
 
 		if (h != w->hidden_state) {
 			w->hidden_state = h;
@@ -1033,7 +1031,7 @@
 			DrawVehicleProfitButton(v, x, y + 13);
 
 			SetDParam(0, v->unitnumber);
-			if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) {
+			if (IsAircraftInHangar(v)) {
 				str = STR_021F;
 			} else {
 				str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/station_map.h	Thu Jun 15 14:45:03 2006 +0000
@@ -0,0 +1,40 @@
+/* $Id$ */
+
+#include "tile.h"
+
+#ifndef STATION_MAP_H
+#define STATION_MAP_H
+
+typedef byte StationGfx;
+
+
+typedef enum HangarTiles {
+	HANGAR_TILE_0 = 32,
+	HANGAR_TILE_1 = 65,
+	HANGAR_TILE_2 = 86
+} HangarTiles;
+
+
+static inline StationGfx GetStationGfx(TileIndex t)
+{
+	assert(IsTileType(t, MP_STATION));
+	return _m[t].m5;
+}
+
+
+static inline bool IsHangar(TileIndex t)
+{
+	StationGfx gfx = GetStationGfx(t);
+	return
+		gfx == HANGAR_TILE_0 ||
+		gfx == HANGAR_TILE_1 ||
+		gfx == HANGAR_TILE_2;
+}
+
+
+static inline bool IsHangarTile(TileIndex t)
+{
+	return IsTileType(t, MP_STATION) && IsHangar(t);
+}
+
+#endif