src/airport.cpp
changeset 6175 26674ca57aac
parent 5860 7fdc9b423ba1
child 6183 5d864a25ae2b
equal deleted inserted replaced
6174:7871038cdebb 6175:26674ca57aac
    28 static AirportFTAClass *HeliDepot;
    28 static AirportFTAClass *HeliDepot;
    29 static AirportFTAClass *IntercontinentalAirport;
    29 static AirportFTAClass *IntercontinentalAirport;
    30 static AirportFTAClass *HeliStation;
    30 static AirportFTAClass *HeliStation;
    31 
    31 
    32 static void AirportFTAClass_Constructor(AirportFTAClass *apc,
    32 static void AirportFTAClass_Constructor(AirportFTAClass *apc,
       
    33 	const AirportMovingData *moving_data,
    33 	const byte *terminals, const byte *helipads,
    34 	const byte *terminals, const byte *helipads,
    34 	const byte entry_point,  const AcceptPlanes acc_planes,
    35 	const byte entry_point,  const AcceptPlanes acc_planes,
    35 	const AirportFTAbuildup *apFA,
    36 	const AirportFTAbuildup *apFA,
    36 	const TileIndexDiffC *depots, const byte nof_depots,
    37 	const TileIndexDiffC *depots, const byte nof_depots,
    37 	uint size_x, uint size_y
    38 	uint size_x, uint size_y
    52 	// country airport
    53 	// country airport
    53 	CountryAirport = MallocT<AirportFTAClass>(1);
    54 	CountryAirport = MallocT<AirportFTAClass>(1);
    54 
    55 
    55 	AirportFTAClass_Constructor(
    56 	AirportFTAClass_Constructor(
    56 		CountryAirport,
    57 		CountryAirport,
       
    58 		_airport_moving_data_country,
    57 		_airport_terminal_country,
    59 		_airport_terminal_country,
    58 		NULL,
    60 		NULL,
    59 		16,
    61 		16,
    60 		ALL,
    62 		ALL,
    61 		_airport_fta_country,
    63 		_airport_fta_country,
    67 	// city airport
    69 	// city airport
    68 	CityAirport = MallocT<AirportFTAClass>(1);
    70 	CityAirport = MallocT<AirportFTAClass>(1);
    69 
    71 
    70 	AirportFTAClass_Constructor(
    72 	AirportFTAClass_Constructor(
    71 		CityAirport,
    73 		CityAirport,
       
    74 		_airport_moving_data_town,
    72 		_airport_terminal_city,
    75 		_airport_terminal_city,
    73 		NULL,
    76 		NULL,
    74 		19,
    77 		19,
    75 		ALL,
    78 		ALL,
    76 		_airport_fta_city,
    79 		_airport_fta_city,
    82 	// metropolitan airport
    85 	// metropolitan airport
    83 	MetropolitanAirport = MallocT<AirportFTAClass>(1);
    86 	MetropolitanAirport = MallocT<AirportFTAClass>(1);
    84 
    87 
    85 	AirportFTAClass_Constructor(
    88 	AirportFTAClass_Constructor(
    86 		MetropolitanAirport,
    89 		MetropolitanAirport,
       
    90 		_airport_moving_data_metropolitan,
    87 		_airport_terminal_metropolitan,
    91 		_airport_terminal_metropolitan,
    88 		NULL,
    92 		NULL,
    89 		20,
    93 		20,
    90 		ALL,
    94 		ALL,
    91 		_airport_fta_metropolitan,
    95 		_airport_fta_metropolitan,
    97 	// international airport
   101 	// international airport
    98 	InternationalAirport = MallocT<AirportFTAClass>(1);
   102 	InternationalAirport = MallocT<AirportFTAClass>(1);
    99 
   103 
   100 	AirportFTAClass_Constructor(
   104 	AirportFTAClass_Constructor(
   101 		InternationalAirport,
   105 		InternationalAirport,
       
   106 		_airport_moving_data_international,
   102 		_airport_terminal_international,
   107 		_airport_terminal_international,
   103 		_airport_helipad_international,
   108 		_airport_helipad_international,
   104 		37,
   109 		37,
   105 		ALL,
   110 		ALL,
   106 		_airport_fta_international,
   111 		_airport_fta_international,
   112 	// intercontintental airport
   117 	// intercontintental airport
   113 	IntercontinentalAirport = MallocT<AirportFTAClass>(1);
   118 	IntercontinentalAirport = MallocT<AirportFTAClass>(1);
   114 
   119 
   115 	AirportFTAClass_Constructor(
   120 	AirportFTAClass_Constructor(
   116 		IntercontinentalAirport,
   121 		IntercontinentalAirport,
       
   122 		_airport_moving_data_intercontinental,
   117 		_airport_terminal_intercontinental,
   123 		_airport_terminal_intercontinental,
   118 		_airport_helipad_intercontinental,
   124 		_airport_helipad_intercontinental,
   119 		43,
   125 		43,
   120 		ALL,
   126 		ALL,
   121 		_airport_fta_intercontinental,
   127 		_airport_fta_intercontinental,
   122 		_airport_depots_intercontinental,
   128 		_airport_depots_intercontinental,
   123 		lengthof(_airport_depots_intercontinental),
   129 		lengthof(_airport_depots_intercontinental),
   124 		9,11
   130 		9,11
   125 	);
   131 	);
   126 
   132 
   127 	// heliport, oilrig
       
   128 	Heliport = MallocT<AirportFTAClass>(1);
   133 	Heliport = MallocT<AirportFTAClass>(1);
   129 
   134 
   130 	AirportFTAClass_Constructor(
   135 	AirportFTAClass_Constructor(
   131 		Heliport,
   136 		Heliport,
       
   137 		_airport_moving_data_heliport,
   132 		NULL,
   138 		NULL,
   133 		_airport_helipad_heliport_oilrig,
   139 		_airport_helipad_heliport_oilrig,
   134 		7,
   140 		7,
   135 		HELICOPTERS_ONLY,
   141 		HELICOPTERS_ONLY,
   136 		_airport_fta_heliport_oilrig,
   142 		_airport_fta_heliport_oilrig,
   137 		NULL,
   143 		NULL,
   138 		0,
   144 		0,
   139 		1, 1
   145 		1, 1
   140 	);
   146 	);
   141 
   147 
   142 	Oilrig = Heliport;  // exactly the same structure for heliport/oilrig, so share state machine
   148 	Oilrig = MallocT<AirportFTAClass>(1);
       
   149 	AirportFTAClass_Constructor(
       
   150 		Oilrig,
       
   151 		_airport_moving_data_oilrig,
       
   152 		NULL,
       
   153 		_airport_helipad_heliport_oilrig,
       
   154 		7,
       
   155 		HELICOPTERS_ONLY,
       
   156 		_airport_fta_heliport_oilrig,
       
   157 		NULL,
       
   158 		0,
       
   159 		1, 1
       
   160 	);
   143 
   161 
   144 	// commuter airport
   162 	// commuter airport
   145 	CommuterAirport = MallocT<AirportFTAClass>(1);
   163 	CommuterAirport = MallocT<AirportFTAClass>(1);
   146 
   164 
   147 	AirportFTAClass_Constructor(
   165 	AirportFTAClass_Constructor(
   148 		CommuterAirport,
   166 		CommuterAirport,
       
   167 		_airport_moving_data_commuter,
   149 		_airport_terminal_commuter,
   168 		_airport_terminal_commuter,
   150 		_airport_helipad_commuter,
   169 		_airport_helipad_commuter,
   151 		22,
   170 		22,
   152 		ALL,
   171 		ALL,
   153 		_airport_fta_commuter,
   172 		_airport_fta_commuter,
   159 	// helidepot airport
   178 	// helidepot airport
   160 	HeliDepot = MallocT<AirportFTAClass>(1);
   179 	HeliDepot = MallocT<AirportFTAClass>(1);
   161 
   180 
   162 	AirportFTAClass_Constructor(
   181 	AirportFTAClass_Constructor(
   163 		HeliDepot,
   182 		HeliDepot,
       
   183 		_airport_moving_data_helidepot,
   164 		NULL,
   184 		NULL,
   165 		_airport_helipad_helidepot,
   185 		_airport_helipad_helidepot,
   166 		4,
   186 		4,
   167 		HELICOPTERS_ONLY,
   187 		HELICOPTERS_ONLY,
   168 		_airport_fta_helidepot,
   188 		_airport_fta_helidepot,
   174 	// helistation airport
   194 	// helistation airport
   175 	HeliStation = MallocT<AirportFTAClass>(1);
   195 	HeliStation = MallocT<AirportFTAClass>(1);
   176 
   196 
   177 	AirportFTAClass_Constructor(
   197 	AirportFTAClass_Constructor(
   178 		HeliStation,
   198 		HeliStation,
       
   199 		_airport_moving_data_helistation,
   179 		NULL,
   200 		NULL,
   180 		_airport_helipad_helistation,
   201 		_airport_helipad_helistation,
   181 		25,
   202 		25,
   182 		HELICOPTERS_ONLY,
   203 		HELICOPTERS_ONLY,
   183 		_airport_fta_helistation,
   204 		_airport_fta_helistation,
   200 	AirportFTAClass_Destructor(IntercontinentalAirport);
   221 	AirportFTAClass_Destructor(IntercontinentalAirport);
   201 	AirportFTAClass_Destructor(HeliStation);
   222 	AirportFTAClass_Destructor(HeliStation);
   202 }
   223 }
   203 
   224 
   204 static void AirportFTAClass_Constructor(AirportFTAClass *apc,
   225 static void AirportFTAClass_Constructor(AirportFTAClass *apc,
       
   226 	const AirportMovingData *moving_data,
   205 	const byte *terminals, const byte *helipads,
   227 	const byte *terminals, const byte *helipads,
   206 	const byte entry_point, const AcceptPlanes acc_planes,
   228 	const byte entry_point, const AcceptPlanes acc_planes,
   207 	const AirportFTAbuildup *apFA,
   229 	const AirportFTAbuildup *apFA,
   208 	const TileIndexDiffC *depots, const byte nof_depots,
   230 	const TileIndexDiffC *depots, const byte nof_depots,
   209 	uint size_x, uint size_y
   231 	uint size_x, uint size_y
   210 )
   232 )
   211 {
   233 {
   212 	byte nofterminals, nofhelipads;
   234 	byte nofterminals, nofhelipads;
   213 	byte nofterminalgroups, nofhelipadgroups;
   235 	byte nofterminalgroups, nofhelipadgroups;
   214 
   236 
       
   237 	apc->moving_data = moving_data;
   215 	apc->size_x = size_x;
   238 	apc->size_x = size_x;
   216 	apc->size_y = size_y;
   239 	apc->size_y = size_y;
   217 
   240 
   218 	/* Set up the terminal and helipad count for an airport.
   241 	/* Set up the terminal and helipad count for an airport.
   219 	 * TODO: If there are more than 10 terminals or 4 helipads, internal variables
   242 	 * TODO: If there are more than 10 terminals or 4 helipads, internal variables
   467 		case AT_INTERCON:      return IntercontinentalAirport;
   490 		case AT_INTERCON:      return IntercontinentalAirport;
   468 		case AT_HELISTATION:   return HeliStation;
   491 		case AT_HELISTATION:   return HeliStation;
   469 	}
   492 	}
   470 }
   493 }
   471 
   494 
   472 const AirportMovingData *GetAirportMovingData(byte airport_type, byte position)
       
   473 {
       
   474 	assert(airport_type < lengthof(_airport_moving_datas));
       
   475 	assert(position < GetAirport(airport_type)->nofelements);
       
   476 	return &_airport_moving_datas[airport_type][position];
       
   477 }
       
   478 
   495 
   479 uint32 GetValidAirports(void)
   496 uint32 GetValidAirports(void)
   480 {
   497 {
   481 	uint32 bytemask = _avail_aircraft; /// sets the first 3 bytes, 0 - 2, @see AdjustAvailAircraft()
   498 	uint32 bytemask = _avail_aircraft; /// sets the first 3 bytes, 0 - 2, @see AdjustAvailAircraft()
   482 
   499