(svn r8747) -Fix
authortron
Thu, 15 Feb 2007 20:16:33 +0000
changeset 6350 c644e180cdf8
parent 6349 c22327023623
child 6351 afb1e3960181
(svn r8747) -Fix

-Codechange: Make the encoding of accepted aircraft types of airports a bit more sensible and move the enum into struct AirportFTAClass
src/ai/default/default.cpp
src/aircraft_cmd.cpp
src/airport.cpp
src/airport.h
src/build_vehicle_gui.cpp
src/window.h
--- a/src/ai/default/default.cpp	Thu Feb 15 17:51:39 2007 +0000
+++ b/src/ai/default/default.cpp	Thu Feb 15 20:16:33 2007 +0000
@@ -3244,7 +3244,6 @@
 static void AiStateAirportStuff(Player *p)
 {
 	const Station* st;
-	byte acc_planes;
 	int i;
 	AiBuildRec *aib;
 	byte rule;
@@ -3268,16 +3267,11 @@
 			// Do we own the airport? (Oilrigs aren't owned, though.)
 			if (st->owner != OWNER_NONE && st->owner != _current_player) continue;
 
-			acc_planes = GetAirport(st->airport_type)->acc_planes;
-
-			// Dismiss heliports, unless we are checking an oilrig.
-			if (acc_planes == HELICOPTERS_ONLY && (p->ai.build_kind != 1 || i != 1))
+			AirportFTAClass::Flags flags = GetAirport(st->airport_type)->flags;
+
+			if (!(flags & (p->ai.build_kind == 1 && i == 0 ? AirportFTAClass::HELICOPTERS : AirportFTAClass::PLANES))) {
 				continue;
-
-			// Dismiss country airports if we are doing the other
-			// endpoint of an oilrig route.
-			if (acc_planes == AIRCRAFT_ONLY && (p->ai.build_kind == 1 && i == 0))
-				continue;
+			}
 
 			// Dismiss airports too far away.
 			if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng)
@@ -3298,7 +3292,7 @@
 			 * broken because they will probably need different
 			 * tileoff values etc), no matter that
 			 * IsHangarTile() makes no sense. --pasky */
-			if (acc_planes == HELICOPTERS_ONLY) {
+			if (!(flags & AirportFTAClass::PLANES)) {
 				/* Heliports should have maybe own rulesets but
 				 * OTOH we don't want AI to pick them up when
 				 * looking for a suitable airport type to build.
@@ -3372,7 +3366,7 @@
 	for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
 		// If we are doing a helicopter service, avoid building
 		// airports where they can't land.
-		if (heli && GetAirport(p->attr)->acc_planes == AIRCRAFT_ONLY) continue;
+		if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue;
 
 		*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
 		if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo))
--- a/src/aircraft_cmd.cpp	Thu Feb 15 17:51:39 2007 +0000
+++ b/src/aircraft_cmd.cpp	Thu Feb 15 20:16:33 2007 +0000
@@ -250,7 +250,7 @@
 	// Prevent building aircraft types at places which can't handle them
 	const Station* st = GetStationByTile(tile);
 	const AirportFTAClass* apc = GetAirport(st->airport_type);
-	if ((avi->subtype & AIR_CTOL ? HELICOPTERS_ONLY : AIRCRAFT_ONLY) == apc->acc_planes) {
+	if (!(apc->flags & (avi->subtype & AIR_CTOL ? AirportFTAClass::PLANES : AirportFTAClass::HELICOPTERS))) {
 		return CMD_ERROR;
 	}
 
@@ -1636,12 +1636,8 @@
 	uint16 tcur_speed, tsubspeed;
 
 	st = GetStation(v->u.air.targetairport);
-	// flying device is accepted at this station
-	// small airport --> no helicopters (AIRCRAFT_ONLY)
-	// all other airports --> all types of flying devices (ALL)
-	// heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY)
 	// runway busy or not allowed to use this airstation, circle
-	if (v->subtype != apc->acc_planes &&
+	if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::PLANES) &&
 			st->airport_tile != 0 &&
 			(st->owner == OWNER_NONE || st->owner == v->owner)) {
 		// {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
--- a/src/airport.cpp	Thu Feb 15 17:51:39 2007 +0000
+++ b/src/airport.cpp	Thu Feb 15 20:16:33 2007 +0000
@@ -37,7 +37,7 @@
 		_airport_terminal_country,
 		NULL,
 		16,
-		ALL,
+		AirportFTAClass::ALL,
 		_airport_fta_country,
 		_airport_depots_country,
 		lengthof(_airport_depots_country),
@@ -50,7 +50,7 @@
 		_airport_terminal_city,
 		NULL,
 		19,
-		ALL,
+		AirportFTAClass::ALL,
 		_airport_fta_city,
 		_airport_depots_city,
 		lengthof(_airport_depots_city),
@@ -63,7 +63,7 @@
 		_airport_terminal_metropolitan,
 		NULL,
 		20,
-		ALL,
+		AirportFTAClass::ALL,
 		_airport_fta_metropolitan,
 		_airport_depots_metropolitan,
 		lengthof(_airport_depots_metropolitan),
@@ -76,7 +76,7 @@
 		_airport_terminal_international,
 		_airport_helipad_international,
 		37,
-		ALL,
+		AirportFTAClass::ALL,
 		_airport_fta_international,
 		_airport_depots_international,
 		lengthof(_airport_depots_international),
@@ -89,7 +89,7 @@
 		_airport_terminal_intercontinental,
 		_airport_helipad_intercontinental,
 		43,
-		ALL,
+		AirportFTAClass::ALL,
 		_airport_fta_intercontinental,
 		_airport_depots_intercontinental,
 		lengthof(_airport_depots_intercontinental),
@@ -102,7 +102,7 @@
 		NULL,
 		_airport_helipad_heliport_oilrig,
 		7,
-		HELICOPTERS_ONLY,
+		AirportFTAClass::HELICOPTERS,
 		_airport_fta_heliport_oilrig,
 		NULL,
 		0,
@@ -115,7 +115,7 @@
 		NULL,
 		_airport_helipad_heliport_oilrig,
 		7,
-		HELICOPTERS_ONLY,
+		AirportFTAClass::HELICOPTERS,
 		_airport_fta_heliport_oilrig,
 		NULL,
 		0,
@@ -128,7 +128,7 @@
 		_airport_terminal_commuter,
 		_airport_helipad_commuter,
 		22,
-		ALL,
+		AirportFTAClass::ALL,
 		_airport_fta_commuter,
 		_airport_depots_commuter,
 		lengthof(_airport_depots_commuter),
@@ -141,7 +141,7 @@
 		NULL,
 		_airport_helipad_helidepot,
 		4,
-		HELICOPTERS_ONLY,
+		AirportFTAClass::HELICOPTERS,
 		_airport_fta_helidepot,
 		_airport_depots_helidepot,
 		lengthof(_airport_depots_helidepot),
@@ -154,7 +154,7 @@
 		NULL,
 		_airport_helipad_helistation,
 		25,
-		HELICOPTERS_ONLY,
+		AirportFTAClass::HELICOPTERS,
 		_airport_fta_helistation,
 		_airport_depots_helistation,
 		lengthof(_airport_depots_helistation),
@@ -192,7 +192,7 @@
 	const byte *terminals_,
 	const byte *helipads_,
 	const byte entry_point_,
-	const AcceptPlanes acc_planes_,
+	Flags flags_,
 	const AirportFTAbuildup *apFA,
 	const TileIndexDiffC *depots_,
 	const byte nof_depots_,
@@ -204,6 +204,7 @@
 	terminals(terminals_),
 	helipads(helipads_),
 	airport_depots(depots_),
+	flags(flags_),
 	nof_depots(nof_depots_),
 	nofelements(AirportGetNofElements(apFA)),
 	entry_point(entry_point_),
@@ -213,8 +214,6 @@
 {
 	byte nofterminalgroups, nofhelipadgroups;
 
-	acc_planes = acc_planes_; // XXX TinyEnumT has no initialisation, only assignment
-
 	/* Set up the terminal and helipad count for an airport.
 	 * TODO: If there are more than 10 terminals or 4 helipads, internal variables
 	 * need to be changed, so don't allow that for now */
--- a/src/airport.h	Thu Feb 15 17:51:39 2007 +0000
+++ b/src/airport.h	Thu Feb 15 20:16:33 2007 +0000
@@ -24,18 +24,6 @@
 	AT_OILRIG        = 15
 };
 
-// do not change unless you change v->subtype too. This aligns perfectly with its current setting
-enum AcceptPlanes {
-	ACC_BEGIN        = 0,
-	AIRCRAFT_ONLY    = 0,
-	ALL              = 1,
-	HELICOPTERS_ONLY = 2,
-	ACC_END
-};
-
-/** Define basic enum properties */
-template <> struct EnumPropsT<AcceptPlanes> : MakeEnumPropsT<AcceptPlanes, byte, ACC_BEGIN, ACC_END, ACC_END> {};
-typedef TinyEnumT<AcceptPlanes> AcceptPlanesByte;
 
 enum {
 	AMED_NOSPDCLAMP = 1 << 0,
@@ -133,12 +121,18 @@
 // Finite sTate mAchine --> FTA
 typedef struct AirportFTAClass {
 	public:
+		enum Flags {
+			PLANES      = 0x1,
+			HELICOPTERS = 0x2,
+			ALL         = PLANES | HELICOPTERS,
+		};
+
 		AirportFTAClass(
 			const AirportMovingData *moving_data,
 			const byte *terminals,
 			const byte *helipads,
 			byte entry_point,
-			AcceptPlanes acc_planes,
+			Flags flags,
 			const AirportFTAbuildup *apFA,
 			const TileIndexDiffC *depots,
 			byte nof_depots,
@@ -160,10 +154,10 @@
 	const byte *terminals;
 	const byte *helipads;
 	const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
+	Flags flags;
 	byte nof_depots;                      // number of depots this airport has
 	byte nofelements;                     // number of positions the airport consists of
 	byte entry_point;                     // when an airplane arrives at this airport, enter it at position entry_point
-	AcceptPlanesByte acc_planes;          // accept airplanes or helicopters or both
 	byte size_x;
 	byte size_y;
 	byte delta_z;                         // Z adjustment for helicopter pads
--- a/src/build_vehicle_gui.cpp	Thu Feb 15 17:51:39 2007 +0000
+++ b/src/build_vehicle_gui.cpp	Thu Feb 15 20:16:33 2007 +0000
@@ -984,8 +984,8 @@
 			ResizeWindow(w, 27, 0);
 			break;
 		case VEH_Aircraft:
-			AcceptPlanes acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
-			bv->filter.acc_planes = acc_planes;
+			bv->filter.flags =
+				tile == 0 ? AirportFTAClass::ALL : GetAirport(GetStationByTile(tile)->airport_type)->flags;
 			ResizeWindow(w, 12, 0);
 			break;
 	}
--- a/src/window.h	Thu Feb 15 17:51:39 2007 +0000
+++ b/src/window.h	Thu Feb 15 20:16:33 2007 +0000
@@ -321,7 +321,7 @@
 	byte vehicle_type;
 	union {
 		RailTypeByte railtype;
-		AcceptPlanesByte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY
+		AirportFTAClass::Flags flags;
 	} filter;
 	byte sel_index;  // deprecated value, used for 'unified' ship and road
 	bool descending_sort_order;