changeset 5924:bdd8eb003619 draft

(svn r8559) -Fix -Codechange: Put the airport movement data into struct AirportFTAClass
author tron <tron@openttd.org>
date Sat, 03 Feb 2007 13:03:11 +0000
parents 6e3ace7b5646
children 3ec99e7f084d
files src/aircraft_cmd.cpp src/airport.cpp src/airport.h src/airport_movement.h src/newgrf_engine.cpp
diffstat 5 files changed, 35 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -916,7 +916,6 @@
 static bool AircraftController(Vehicle *v)
 {
 	Station *st;
-	const AirportMovingData *amd;
 	Vehicle *u;
 	byte z, maxz, curz;
 	Direction newdir;
@@ -937,7 +936,7 @@
 	}
 
 	// get airport moving data
-	amd = GetAirportMovingData(st->airport_type, v->u.air.pos);
+	const AirportMovingData *amd = GetAirport(st->airport_type)->MovingData(v->u.air.pos);
 
 	// Helicopter raise
 	if (amd->flag & AMED_HELI_RAISE) {
--- a/src/airport.cpp
+++ b/src/airport.cpp
@@ -30,6 +30,7 @@
 static AirportFTAClass *HeliStation;
 
 static void AirportFTAClass_Constructor(AirportFTAClass *apc,
+	const AirportMovingData *moving_data,
 	const byte *terminals, const byte *helipads,
 	const byte entry_point,  const AcceptPlanes acc_planes,
 	const AirportFTAbuildup *apFA,
@@ -54,6 +55,7 @@
 
 	AirportFTAClass_Constructor(
 		CountryAirport,
+		_airport_moving_data_country,
 		_airport_terminal_country,
 		NULL,
 		16,
@@ -69,6 +71,7 @@
 
 	AirportFTAClass_Constructor(
 		CityAirport,
+		_airport_moving_data_town,
 		_airport_terminal_city,
 		NULL,
 		19,
@@ -84,6 +87,7 @@
 
 	AirportFTAClass_Constructor(
 		MetropolitanAirport,
+		_airport_moving_data_metropolitan,
 		_airport_terminal_metropolitan,
 		NULL,
 		20,
@@ -99,6 +103,7 @@
 
 	AirportFTAClass_Constructor(
 		InternationalAirport,
+		_airport_moving_data_international,
 		_airport_terminal_international,
 		_airport_helipad_international,
 		37,
@@ -114,6 +119,7 @@
 
 	AirportFTAClass_Constructor(
 		IntercontinentalAirport,
+		_airport_moving_data_intercontinental,
 		_airport_terminal_intercontinental,
 		_airport_helipad_intercontinental,
 		43,
@@ -124,11 +130,11 @@
 		9,11
 	);
 
-	// heliport, oilrig
 	Heliport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		Heliport,
+		_airport_moving_data_heliport,
 		NULL,
 		_airport_helipad_heliport_oilrig,
 		7,
@@ -139,13 +145,26 @@
 		1, 1
 	);
 
-	Oilrig = Heliport;  // exactly the same structure for heliport/oilrig, so share state machine
+	Oilrig = MallocT<AirportFTAClass>(1);
+	AirportFTAClass_Constructor(
+		Oilrig,
+		_airport_moving_data_oilrig,
+		NULL,
+		_airport_helipad_heliport_oilrig,
+		7,
+		HELICOPTERS_ONLY,
+		_airport_fta_heliport_oilrig,
+		NULL,
+		0,
+		1, 1
+	);
 
 	// commuter airport
 	CommuterAirport = MallocT<AirportFTAClass>(1);
 
 	AirportFTAClass_Constructor(
 		CommuterAirport,
+		_airport_moving_data_commuter,
 		_airport_terminal_commuter,
 		_airport_helipad_commuter,
 		22,
@@ -161,6 +180,7 @@
 
 	AirportFTAClass_Constructor(
 		HeliDepot,
+		_airport_moving_data_helidepot,
 		NULL,
 		_airport_helipad_helidepot,
 		4,
@@ -176,6 +196,7 @@
 
 	AirportFTAClass_Constructor(
 		HeliStation,
+		_airport_moving_data_helistation,
 		NULL,
 		_airport_helipad_helistation,
 		25,
@@ -202,6 +223,7 @@
 }
 
 static void AirportFTAClass_Constructor(AirportFTAClass *apc,
+	const AirportMovingData *moving_data,
 	const byte *terminals, const byte *helipads,
 	const byte entry_point, const AcceptPlanes acc_planes,
 	const AirportFTAbuildup *apFA,
@@ -212,6 +234,7 @@
 	byte nofterminals, nofhelipads;
 	byte nofterminalgroups, nofhelipadgroups;
 
+	apc->moving_data = moving_data;
 	apc->size_x = size_x;
 	apc->size_y = size_y;
 
@@ -469,12 +492,6 @@
 	}
 }
 
-const AirportMovingData *GetAirportMovingData(byte airport_type, byte position)
-{
-	assert(airport_type < lengthof(_airport_moving_datas));
-	assert(position < GetAirport(airport_type)->nofelements);
-	return &_airport_moving_datas[airport_type][position];
-}
 
 uint32 GetValidAirports(void)
 {
--- a/src/airport.h
+++ b/src/airport.h
@@ -130,6 +130,14 @@
 
 // Finite sTate mAchine --> FTA
 typedef struct AirportFTAClass {
+	public:
+		const AirportMovingData *MovingData(byte position) const
+		{
+			assert(position < nofelements);
+			return &moving_data[position];
+		}
+
+	const AirportMovingData *moving_data;
 	byte nofelements;                     // number of positions the airport consists of
 	const byte *terminals;
 	const byte *helipads;
@@ -154,7 +162,6 @@
 void InitializeAirports(void);
 void UnInitializeAirports(void);
 const AirportFTAClass *GetAirport(const byte airport_type);
-const AirportMovingData *GetAirportMovingData(byte airport_type, byte position);
 
 /** Get buildable airport bitmask.
  * @return get all buildable airports at this given time, bitmasked.
--- a/src/airport_movement.h
+++ b/src/airport_movement.h
@@ -771,24 +771,4 @@
 	{ MAX_ELEMENTS, 0, 0, 0 } // end marker. DO NOT REMOVE
 };
 
-
-static const AirportMovingData * const _airport_moving_datas[] = {
-	_airport_moving_data_country,           // Country Airfield (small) 4x3
-	_airport_moving_data_town,              // City Airport (large) 6x6
-	_airport_moving_data_heliport,          // Heliport
-	_airport_moving_data_metropolitan,      // Metropolitain Airport (large) - 2 runways
-	_airport_moving_data_international,     // International Airport (xlarge) - 2 runways
-	_airport_moving_data_commuter,          // Commuter Airfield (small) 5x4
-	_airport_moving_data_helidepot,         // Helidepot
-	_airport_moving_data_intercontinental,  // Intercontinental Airport (xxlarge) - 4 runways
-	_airport_moving_data_helistation,       // Helistation
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	_airport_moving_data_oilrig             // Oilrig
-};
-
 #endif /* AIRPORT_MOVEMENT_H */
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -288,7 +288,7 @@
 static byte MapAircraftMovementState(const Vehicle *v)
 {
 	const Station *st = GetStation(v->u.air.targetairport);
-	byte amdflag = GetAirportMovingData(st->airport_type, v->u.air.pos)->flag;
+	byte amdflag = GetAirport(st->airport_type)->MovingData(v->u.air.pos)->flag;
 
 	switch (v->u.air.state) {
 		case HANGAR: