Changeset - r5924:db4ab5a5371a
[Not reviewed]
master
0 5 0
tron - 18 years ago 2007-02-03 13:03:11
tron@openttd.org
(svn r8559) -Fix

-Codechange: Put the airport movement data into struct AirportFTAClass
5 files changed with 35 insertions and 32 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -913,13 +913,12 @@ static byte GetAircraftFlyingAltitude(co
 
	return base_altitude;
 
}
 

	
 
static bool AircraftController(Vehicle *v)
 
{
 
	Station *st;
 
	const AirportMovingData *amd;
 
	Vehicle *u;
 
	byte z, maxz, curz;
 
	Direction newdir;
 
	GetNewVehiclePosResult gp;
 
	uint dist;
 
	int x,y;
 
@@ -934,13 +933,13 @@ static bool AircraftController(Vehicle *
 
		// xy of destination
 
		x = TileX(tile) * TILE_SIZE;
 
		y = TileY(tile) * TILE_SIZE;
 
	}
 

	
 
	// 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) {
 
		u = v->next->next;
 

	
 
		// Make sure the rotors don't rotate too fast
src/airport.cpp
Show inline comments
 
@@ -27,12 +27,13 @@ static AirportFTAClass *InternationalAir
 
static AirportFTAClass *CommuterAirport;
 
static AirportFTAClass *HeliDepot;
 
static AirportFTAClass *IntercontinentalAirport;
 
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,
 
	const TileIndexDiffC *depots, const byte nof_depots,
 
	uint size_x, uint size_y
 
);
 
@@ -51,12 +52,13 @@ void InitializeAirports(void)
 
{
 
	// country airport
 
	CountryAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		CountryAirport,
 
		_airport_moving_data_country,
 
		_airport_terminal_country,
 
		NULL,
 
		16,
 
		ALL,
 
		_airport_fta_country,
 
		_airport_depots_country,
 
@@ -66,12 +68,13 @@ void InitializeAirports(void)
 

	
 
	// city airport
 
	CityAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		CityAirport,
 
		_airport_moving_data_town,
 
		_airport_terminal_city,
 
		NULL,
 
		19,
 
		ALL,
 
		_airport_fta_city,
 
		_airport_depots_city,
 
@@ -81,12 +84,13 @@ void InitializeAirports(void)
 

	
 
	// metropolitan airport
 
	MetropolitanAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		MetropolitanAirport,
 
		_airport_moving_data_metropolitan,
 
		_airport_terminal_metropolitan,
 
		NULL,
 
		20,
 
		ALL,
 
		_airport_fta_metropolitan,
 
		_airport_depots_metropolitan,
 
@@ -96,12 +100,13 @@ void InitializeAirports(void)
 

	
 
	// international airport
 
	InternationalAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		InternationalAirport,
 
		_airport_moving_data_international,
 
		_airport_terminal_international,
 
		_airport_helipad_international,
 
		37,
 
		ALL,
 
		_airport_fta_international,
 
		_airport_depots_international,
 
@@ -111,44 +116,58 @@ void InitializeAirports(void)
 

	
 
	// intercontintental airport
 
	IntercontinentalAirport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		IntercontinentalAirport,
 
		_airport_moving_data_intercontinental,
 
		_airport_terminal_intercontinental,
 
		_airport_helipad_intercontinental,
 
		43,
 
		ALL,
 
		_airport_fta_intercontinental,
 
		_airport_depots_intercontinental,
 
		lengthof(_airport_depots_intercontinental),
 
		9,11
 
	);
 

	
 
	// heliport, oilrig
 
	Heliport = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		Heliport,
 
		_airport_moving_data_heliport,
 
		NULL,
 
		_airport_helipad_heliport_oilrig,
 
		7,
 
		HELICOPTERS_ONLY,
 
		_airport_fta_heliport_oilrig,
 
		NULL,
 
		0,
 
		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,
 
		ALL,
 
		_airport_fta_commuter,
 
		_airport_depots_commuter,
 
@@ -158,12 +177,13 @@ void InitializeAirports(void)
 

	
 
	// helidepot airport
 
	HeliDepot = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		HeliDepot,
 
		_airport_moving_data_helidepot,
 
		NULL,
 
		_airport_helipad_helidepot,
 
		4,
 
		HELICOPTERS_ONLY,
 
		_airport_fta_helidepot,
 
		_airport_depots_helidepot,
 
@@ -173,12 +193,13 @@ void InitializeAirports(void)
 

	
 
	// helistation airport
 
	HeliStation = MallocT<AirportFTAClass>(1);
 

	
 
	AirportFTAClass_Constructor(
 
		HeliStation,
 
		_airport_moving_data_helistation,
 
		NULL,
 
		_airport_helipad_helistation,
 
		25,
 
		HELICOPTERS_ONLY,
 
		_airport_fta_helistation,
 
		_airport_depots_helistation,
 
@@ -199,22 +220,24 @@ void UnInitializeAirports(void)
 
	AirportFTAClass_Destructor(HeliDepot);
 
	AirportFTAClass_Destructor(IntercontinentalAirport);
 
	AirportFTAClass_Destructor(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,
 
	const TileIndexDiffC *depots, const byte nof_depots,
 
	uint size_x, uint size_y
 
)
 
{
 
	byte nofterminals, nofhelipads;
 
	byte nofterminalgroups, nofhelipadgroups;
 

	
 
	apc->moving_data = moving_data;
 
	apc->size_x = size_x;
 
	apc->size_y = size_y;
 

	
 
	/* 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 */
 
@@ -466,18 +489,12 @@ const AirportFTAClass *GetAirport(const 
 
		case AT_HELIDEPOT:     return HeliDepot;
 
		case AT_INTERCON:      return IntercontinentalAirport;
 
		case AT_HELISTATION:   return HeliStation;
 
	}
 
}
 

	
 
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)
 
{
 
	uint32 bytemask = _avail_aircraft; /// sets the first 3 bytes, 0 - 2, @see AdjustAvailAircraft()
 

	
 
	if (_cur_year >= 1980) SETBIT(bytemask, 3); // metropolitan airport
src/airport.h
Show inline comments
 
@@ -127,12 +127,20 @@ typedef struct AirportMovingData {
 
	byte flag;
 
	DirectionByte direction;
 
} AirportMovingData;
 

	
 
// 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;
 
	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
 
	const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
 
@@ -151,13 +159,12 @@ typedef struct AirportFTA {
 
	struct AirportFTA *next; // possible extra movement choices from this position
 
} AirportFTA;
 

	
 
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.
 
 * Bit 0 means the small airport is buildable, etc.
 
 * @todo set availability of airports by year, instead of airplane
 
 */
src/airport_movement.h
Show inline comments
 
@@ -768,27 +768,7 @@ static const AirportFTAbuildup _airport_
 
	{ 30, 0, NOTHING_block, 31 },
 
	{ 31, 0, NOTHING_block, 32 },
 
	{ 32, 0, NOTHING_block, 25 },
 
	{ 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 */
src/newgrf_engine.cpp
Show inline comments
 
@@ -285,13 +285,13 @@ enum {
 
 * Map OTTD aircraft movement states to TTDPatch style movement states
 
 * (VarAction 2 Variable 0xE2)
 
 */
 
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:
 
			/* The international airport is a special case as helicopters can land in
 
			 * front of the hanger. Helicopters also change their air.state to
 
			 * AMED_HELI_LOWER some time before actually descending. */
0 comments (0 inline, 0 general)