changeset 3963:b8b3c73be0e9 draft

(svn r5124) Add IsAircraftInHangar{Stopped,}(), which supersedes CheckStoppedInHangar() -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
author tron <tron@openttd.org>
date Mon, 05 Jun 2006 12:43:41 +0000
parents 082bf707b9ef
children ae9d8c18a39c
files aircraft.h aircraft_cmd.c aircraft_gui.c
diffstat 3 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/aircraft.h
@@ -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
+++ b/aircraft_cmd.c
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "aircraft.h"
 #include "debug.h"
 #include "functions.h"
 #include "station_map.h"
@@ -338,12 +339,6 @@
 }
 
 
-bool CheckStoppedInHangar(const Vehicle* v)
-{
-	return v->vehstatus & VS_STOPPED && IsHangarTile(v->tile);
-}
-
-
 static void DoDeleteAircraft(Vehicle *v)
 {
 	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
@@ -367,7 +362,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);
 
 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
@@ -402,7 +397,7 @@
 		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
 
 	if (flags & DC_EXEC) {
-		if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) {
+		if (IsAircraftInHangarStopped(v)) {
 			DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN);
 		}
 
@@ -499,7 +494,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
+++ b/aircraft_gui.c
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "aircraft.h"
 #include "debug.h"
 #include "functions.h"
 #include "station_map.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,7 +502,7 @@
 		uint32 disabled = 1 << 8;
 		StringID str;
 
-		if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) disabled = 0;
+		if (IsAircraftInHangarStopped(v)) disabled = 0;
 
 		if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7;
 		w->disabled_state = disabled;
@@ -595,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;
@@ -1027,7 +1027,7 @@
 			DrawVehicleProfitButton(v, x, y + 13);
 
 			SetDParam(0, v->unitnumber);
-			if (IsHangarTile(v->tile) && v->vehstatus & VS_HIDDEN) {
+			if (IsAircraftInHangar(v)) {
 				str = STR_021F;
 			} else {
 				str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;