(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
authortron
Wed, 14 Jun 2006 11:05:30 +0000
changeset 4023 5d84c056a2b1
parent 4022 641c137f4c2d
child 4024 6b3809fd45e0
(svn r5262) Add symbolic names for the aircraft subtypes. not perfect, but better than raw numbers
aircraft_cmd.c
engine.h
newgrf_engine.c
players.c
table/engines.h
vehicle_gui.c
--- a/aircraft_cmd.c	Wed Jun 14 09:52:50 2006 +0000
+++ b/aircraft_cmd.c	Wed Jun 14 11:05:30 2006 +0000
@@ -133,7 +133,8 @@
 
 void DrawAircraftEngine(int x, int y, EngineID engine, uint32 image_ormod)
 {
-	int spritenum = AircraftVehInfo(engine)->image_index;
+	const AircraftVehicleInfo* avi = AircraftVehInfo(engine);
+	int spritenum = avi->image_index;
 	int sprite = (6 + _aircraft_sprite[spritenum]);
 
 	if (is_custom_sprite(spritenum)) {
@@ -144,7 +145,7 @@
 
 	DrawSprite(sprite | image_ormod, x, y);
 
-	if ((AircraftVehInfo(engine)->subtype & 1) == 0) {
+	if (!(avi->subtype & AIR_CTOL)) {
 		SpriteID rotor_sprite = GetCustomRotorIcon(engine);
 		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
 		DrawSprite(rotor_sprite, x, y - 5);
@@ -211,7 +212,7 @@
 
 	avi = AircraftVehInfo(p1);
 	// allocate 2 or 3 vehicle structs, depending on type
-	if (!AllocateVehicles(vl, (avi->subtype & 1) == 0 ? 3 : 2) ||
+	if (!AllocateVehicles(vl, avi->subtype & AIR_CTOL ? 2 : 3) ||
 			IsOrderPoolFull()) {
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 	}
@@ -281,7 +282,7 @@
 		v->acceleration = avi->acceleration;
 		v->engine_type = p1;
 
-		v->subtype = (avi->subtype & 1) == 0 ? 0 : 2;
+		v->subtype = (avi->subtype & AIR_CTOL ? 2 : 0);
 		v->value = value;
 
 		u->subtype = 4;
@@ -1271,7 +1272,7 @@
 
 	//FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports
 	prob = 0x10000 / 1500;
-	if (st->airport_type == AT_SMALL && (AircraftVehInfo(v->engine_type)->subtype & 2) && !_cheats.no_jetcrash.value) {
+	if (st->airport_type == AT_SMALL && AircraftVehInfo(v->engine_type)->subtype & AIR_FAST && !_cheats.no_jetcrash.value) {
 		prob = 0x10000 / 20;
 	}
 
--- a/engine.h	Wed Jun 14 09:52:50 2006 +0000
+++ b/engine.h	Wed Jun 14 11:05:30 2006 +0000
@@ -42,6 +42,12 @@
 	byte refittable;
 } ShipVehicleInfo;
 
+// Aircraft subtypes
+enum {
+	AIR_CTOL = 1, // Conventional Take Off and Landing, i.e. planes
+	AIR_FAST = 2
+};
+
 typedef struct AircraftVehicleInfo {
 	byte image_index;
 	byte base_cost;
--- a/newgrf_engine.c	Wed Jun 14 09:52:50 2006 +0000
+++ b/newgrf_engine.c	Wed Jun 14 11:05:30 2006 +0000
@@ -850,7 +850,7 @@
 	assert(engine < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES);
 
 	/* Only valid for helicopters */
-	assert((AircraftVehInfo(engine)->subtype & 1) == 0);
+	assert(!(AircraftVehInfo(engine)->subtype & AIR_CTOL));
 
 	NewVehicleResolver(&object, v);
 
--- a/players.c	Wed Jun 14 09:52:50 2006 +0000
+++ b/players.c	Wed Jun 14 11:05:30 2006 +0000
@@ -738,7 +738,8 @@
 					return CMD_ERROR;
 
 				// make sure that we do not replace a plane with a helicopter or vise versa
-				if (GetEngine(new_engine_type)->type == VEH_Aircraft && HASBIT(AircraftVehInfo(old_engine_type)->subtype, 0) != HASBIT(AircraftVehInfo(new_engine_type)->subtype, 0))
+				if (GetEngine(new_engine_type)->type == VEH_Aircraft &&
+						(AircraftVehInfo(old_engine_type)->subtype & AIR_CTOL) != (AircraftVehInfo(new_engine_type)->subtype & AIR_CTOL))
 					return CMD_ERROR;
 
 				// make sure that the player can actually buy the new engine
--- a/table/engines.h	Wed Jun 14 09:52:50 2006 +0000
+++ b/table/engines.h	Wed Jun 14 11:05:30 2006 +0000
@@ -505,8 +505,8 @@
  */
 #define AVI(a, b, c, d, e, f, g, h, i) { a, b, c, d, e, f, g, h, i }
 #define H 0
-#define P 1
-#define J 3
+#define P AIR_CTOL
+#define J AIR_CTOL | AIR_FAST
 const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES] = {
 	//    image_index         sfx                         acceleration
 	//    |   base_cost       |                           |   max_speed
--- a/vehicle_gui.c	Wed Jun 14 09:52:50 2006 +0000
+++ b/vehicle_gui.c	Wed Jun 14 11:05:30 2006 +0000
@@ -615,7 +615,7 @@
 
 				for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
 					if (HASBIT(GetEngine(i)->player_avail, _local_player) &&
-							HASBIT(subtype, 0) == HASBIT(AircraftVehInfo(i)->subtype, 0)) {
+							(subtype & AIR_CTOL) == (AircraftVehInfo(i)->subtype & AIR_CTOL)) {
 						if (sel[1] == count2) selected_id[1] = i;
 						count2++;
 					}
@@ -760,7 +760,7 @@
 						}
 						sel[0]--;
 					}
-					if (HASBIT(subtype, 0) == HASBIT(AircraftVehInfo(engine_id)->subtype, 0) &&
+					if ((subtype & AIR_CTOL) == (AircraftVehInfo(engine_id)->subtype & AIR_CTOL) &&
 							HASBIT(e->player_avail, _local_player)) {
 						if (sel[1] == 0) selected_id[1] = engine_id;
 						if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {