(svn r8759) -Feature: Allow airports to have up to 4 entry points depending on approach direction. Note: they're not yet used, but will be soon

This commit is contained in:
celestar 2007-02-16 12:10:19 +00:00
parent 5adb5315bb
commit a8e88ae7cc
4 changed files with 78 additions and 23 deletions

View File

@ -1443,6 +1443,50 @@ static void AircraftLandAirplane(Vehicle *v)
MaybeCrashAirplane(v);
}
/**
* Find the entry point to an airport depending on direction which
* the airport is being approached from. Each airport can have up to
* four entry points for its approach system so that approaching
* aircraft do not fly through each other or are forced to do 180
* degree turns during the approach. The arrivals are grouped into
* four sectors dependent on the DiagDirection from which the airport
* is approached.
*
* @param v The vehicle that is approaching the airport
* @param apc The Airport Class being approached.
* @returns The index of the entry point
*/
static byte AircraftGetEntryPoint(const Vehicle *v, const AirportFTAClass *apc)
{
const Station *st = NULL;
int delta_x = 0;
int delta_y = 0;
TileIndex tile = INVALID_TILE;
assert(v != NULL);
assert(apc != NULL);
st = GetStation(v->u.air.targetairport);
/* Make sure we don't go to 0,0 if the airport has been removed. */
tile = (st->airport_tile != 0) ? st->airport_tile : st->xy;
delta_x = v->x_pos - TileX(tile) * TILE_SIZE;
delta_y = v->y_pos - TileY(tile) * TILE_SIZE;
if (abs(delta_y) < abs(delta_x)) {
/* We are northeast or southwest of the airport */
if (delta_x < 0) return apc->entry_points[DIAGDIR_NE];
return apc->entry_points[DIAGDIR_SW];
}
/* We're either northwest or southeast of the airport */
if (delta_y < 0) return apc->entry_points[DIAGDIR_NW];
return apc->entry_points[DIAGDIR_SE];
}
// set the right pos when heading to other airports after takeoff
static void AircraftNextAirportPos_and_Order(Vehicle *v)
{
@ -1451,7 +1495,7 @@ static void AircraftNextAirportPos_and_Order(Vehicle *v)
v->u.air.targetairport = v->current_order.dest;
const AirportFTAClass *apc = GetStation(v->u.air.targetairport)->Airport();
v->u.air.pos = v->u.air.previous_pos = apc->entry_point;
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, apc);
}
static void AircraftLeaveHangar(Vehicle *v)
@ -1817,8 +1861,7 @@ static bool AirportMove(Vehicle *v, const AirportFTAClass *apc)
current = current->next;
} while (current != NULL);
DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d)", v->u.air.pos, v->u.air.state);
DEBUG(misc, 0, "[Ap] airport entry point: %d, Vehicle: %d", apc->entry_point, v->index);
DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->u.air.pos, v->u.air.state, v->index);
assert(0);
return false;
}
@ -2118,7 +2161,7 @@ void UpdateAirplanesOnNewStation(Station *st)
*you cannot delete airport, so it doesn't matter
*/
if (v->u.air.state >= FLYING) { // circle around
v->u.air.pos = v->u.air.previous_pos = ap->entry_point;
v->u.air.pos = v->u.air.previous_pos = AircraftGetEntryPoint(v, ap);
v->u.air.state = FLYING;
// landing plane needs to be reset to flying height (only if in pause mode upgrade,
// in normal mode, plane is reset in AircraftController. It doesn't hurt for FLYING

View File

@ -36,7 +36,7 @@ void InitializeAirports(void)
_airport_moving_data_country,
_airport_terminal_country,
NULL,
16,
_airport_entries_country,
AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
_airport_fta_country,
_airport_depots_country,
@ -49,7 +49,7 @@ void InitializeAirports(void)
_airport_moving_data_town,
_airport_terminal_city,
NULL,
19,
_airport_entries_city,
AirportFTAClass::ALL,
_airport_fta_city,
_airport_depots_city,
@ -62,7 +62,7 @@ void InitializeAirports(void)
_airport_moving_data_metropolitan,
_airport_terminal_metropolitan,
NULL,
20,
_airport_entries_metropolitan,
AirportFTAClass::ALL,
_airport_fta_metropolitan,
_airport_depots_metropolitan,
@ -75,7 +75,7 @@ void InitializeAirports(void)
_airport_moving_data_international,
_airport_terminal_international,
_airport_helipad_international,
37,
_airport_entries_international,
AirportFTAClass::ALL,
_airport_fta_international,
_airport_depots_international,
@ -88,7 +88,7 @@ void InitializeAirports(void)
_airport_moving_data_intercontinental,
_airport_terminal_intercontinental,
_airport_helipad_intercontinental,
43,
_airport_entries_intercontinental,
AirportFTAClass::ALL,
_airport_fta_intercontinental,
_airport_depots_intercontinental,
@ -101,7 +101,7 @@ void InitializeAirports(void)
_airport_moving_data_heliport,
NULL,
_airport_helipad_heliport_oilrig,
7,
_airport_entries_heliport_oilrig,
AirportFTAClass::HELICOPTERS,
_airport_fta_heliport_oilrig,
NULL,
@ -114,7 +114,7 @@ void InitializeAirports(void)
_airport_moving_data_oilrig,
NULL,
_airport_helipad_heliport_oilrig,
7,
_airport_entries_heliport_oilrig,
AirportFTAClass::HELICOPTERS,
_airport_fta_heliport_oilrig,
NULL,
@ -127,7 +127,7 @@ void InitializeAirports(void)
_airport_moving_data_commuter,
_airport_terminal_commuter,
_airport_helipad_commuter,
22,
_airport_entries_commuter,
AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
_airport_fta_commuter,
_airport_depots_commuter,
@ -140,7 +140,7 @@ void InitializeAirports(void)
_airport_moving_data_helidepot,
NULL,
_airport_helipad_helidepot,
4,
_airport_entries_helidepot,
AirportFTAClass::HELICOPTERS,
_airport_fta_helidepot,
_airport_depots_helidepot,
@ -153,7 +153,7 @@ void InitializeAirports(void)
_airport_moving_data_helistation,
NULL,
_airport_helipad_helistation,
25,
_airport_entries_helistation,
AirportFTAClass::HELICOPTERS,
_airport_fta_helistation,
_airport_depots_helistation,
@ -191,7 +191,7 @@ AirportFTAClass::AirportFTAClass(
const AirportMovingData *moving_data_,
const byte *terminals_,
const byte *helipads_,
const byte entry_point_,
const byte *entry_points_,
Flags flags_,
const AirportFTAbuildup *apFA,
const TileIndexDiffC *depots_,
@ -207,7 +207,7 @@ AirportFTAClass::AirportFTAClass(
flags(flags_),
nof_depots(nof_depots_),
nofelements(AirportGetNofElements(apFA)),
entry_point(entry_point_),
entry_points(entry_points_),
size_x(size_x_),
size_y(size_y_),
delta_z(delta_z_)
@ -232,15 +232,18 @@ AirportFTAClass::AirportFTAClass(
/* Get the number of elements from the source table. We also double check this
* with the entry point which must be within bounds and use this information
* later on to build and validate the state machine */
if (entry_point >= nofelements) {
DEBUG(misc, 0, "[Ap] entry (%d) must be within the airport (maximum %d)", entry_point, nofelements);
assert(entry_point < nofelements);
for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
if (entry_points[i] >= nofelements) {
DEBUG(misc, 0, "[Ap] entry (%d) must be within the airport (maximum %d)", entry_points[i], nofelements);
assert(entry_points[i] < nofelements);
}
}
/* Build the state machine itself */
layout = AirportBuildAutomata(nofelements, apFA);
DEBUG(misc, 2, "[Ap] #count %3d; #term %2d (%dgrp); #helipad %2d (%dgrp); entry %3d",
nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, entry_point);
DEBUG(misc, 2, "[Ap] #count %3d; #term %2d (%dgrp); #helipad %2d (%dgrp); entries %3d, %3d, %3d, %3d",
nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups,
entry_points[DIAGDIR_NE], entry_points[DIAGDIR_SE], entry_points[DIAGDIR_SW], entry_points[DIAGDIR_NW]);
/* Test if everything went allright. This is only a rude static test checking
* the symantic correctness. By no means does passing the test mean that the

View File

@ -132,7 +132,7 @@ typedef struct AirportFTAClass {
const AirportMovingData *moving_data,
const byte *terminals,
const byte *helipads,
byte entry_point,
const byte *entry_points,
Flags flags,
const AirportFTAbuildup *apFA,
const TileIndexDiffC *depots,
@ -158,7 +158,7 @@ typedef struct AirportFTAClass {
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
const byte *entry_points; ///< when an airplane arrives at this airport, enter it at position entry_point, index depends on direction
byte size_x;
byte size_y;
byte delta_z; // Z adjustment for helicopter pads

View File

@ -373,6 +373,7 @@ static const AirportMovingData _airport_moving_data_oilrig[9] = {
* this may be changed later when airports are moved to external file */
static const TileIndexDiffC _airport_depots_country[] = {{3, 0}};
static const byte _airport_terminal_country[] = {1, 2};
static const byte _airport_entries_country[] = {16, 16, 16, 16};
static const AirportFTAbuildup _airport_fta_country[] = {
{ 0, HANGAR, NOTHING_block, 1 },
{ 1, 255, AIRPORT_BUSY_block, 0 }, { 1, HANGAR, 0, 0 }, { 1, TERM1, TERM1_block, 2 }, { 1, TERM2, 0, 4 }, { 1, HELITAKEOFF, 0, 19 }, { 1, 0, 0, 6 },
@ -405,6 +406,7 @@ static const AirportFTAbuildup _airport_fta_country[] = {
static const TileIndexDiffC _airport_depots_commuter[] = { { 4, 0 } };
static const byte _airport_terminal_commuter[] = { 1, 3 };
static const byte _airport_helipad_commuter[] = { 1, 2 };
static const byte _airport_entries_commuter[] = {7, 7, 7, 7};
static const AirportFTAbuildup _airport_fta_commuter[] = {
{ 0, HANGAR, NOTHING_block, 1 }, { 0, HELITAKEOFF, HELIPAD2_block, 1 }, { 0, 0, 0, 1 },
{ 1, 255, TAXIWAY_BUSY_block, 0 }, { 1, HANGAR, 0, 0 }, { 1, TAKEOFF, 0, 11 }, { 1, TERM1, TAXIWAY_BUSY_block, 10 }, { 1, TERM2, TAXIWAY_BUSY_block, 10 }, { 1, TERM3, TAXIWAY_BUSY_block, 10 }, { 1, HELIPAD1, TAXIWAY_BUSY_block, 10 }, { 1, HELIPAD2, TAXIWAY_BUSY_block, 10 }, { 1, HELITAKEOFF, TAXIWAY_BUSY_block, 10 }, { 1, 0, 0, 0 },
@ -454,6 +456,7 @@ static const AirportFTAbuildup _airport_fta_commuter[] = {
static const TileIndexDiffC _airport_depots_city[] = { { 5, 0 } };
static const byte _airport_terminal_city[] = { 1, 3 };
static const byte _airport_entries_city[] = {19, 19, 19, 19};
static const AirportFTAbuildup _airport_fta_city[] = {
{ 0, HANGAR, NOTHING_block, 1 }, { 0, TAKEOFF, OUT_WAY_block, 1 }, { 0, 0, 0, 1 },
{ 1, 255, TAXIWAY_BUSY_block, 0 }, { 1, HANGAR, 0, 0 }, { 1, TERM2, 0, 6 }, { 1, TERM3, 0, 6 }, { 1, 0, 0, 7 }, // for all else, go to 7
@ -489,6 +492,7 @@ static const AirportFTAbuildup _airport_fta_city[] = {
static const TileIndexDiffC _airport_depots_metropolitan[] = { { 5, 0 } };
static const byte _airport_terminal_metropolitan[] = { 1, 3 };
static const byte _airport_entries_metropolitan[] = {20, 20, 20, 20};
static const AirportFTAbuildup _airport_fta_metropolitan[] = {
{ 0, HANGAR, NOTHING_block, 1 },
{ 1, 255, TAXIWAY_BUSY_block, 0 }, { 1, HANGAR, 0, 0 }, { 1, TERM2, 0, 6 }, { 1, TERM3, 0, 6 }, { 1, 0, 0, 7 }, // for all else, go to 7
@ -527,6 +531,7 @@ static const AirportFTAbuildup _airport_fta_metropolitan[] = {
static const TileIndexDiffC _airport_depots_international[] = { { 0, 3 }, { 6, 1 } };
static const byte _airport_terminal_international[] = { 2, 3, 3 };
static const byte _airport_helipad_international[] = { 1, 2 };
static const byte _airport_entries_international[] = { 37, 37, 37, 37 };
static const AirportFTAbuildup _airport_fta_international[] = {
{ 0, HANGAR, NOTHING_block, 2 }, { 0, 255, TERM_GROUP1_block, 0 }, { 0, 255, TERM_GROUP2_ENTER1_block, 1 }, { 0, HELITAKEOFF, HELIPAD1_block, 2 }, { 0, 0, 0, 2 },
{ 1, HANGAR, NOTHING_block, 3 }, { 1, 255, HANGAR2_AREA_block, 1 }, { 1, HELITAKEOFF, HELIPAD2_block, 3 }, { 1, 0, 0, 3 },
@ -592,6 +597,7 @@ static const AirportFTAbuildup _airport_fta_international[] = {
static const TileIndexDiffC _airport_depots_intercontinental[] = { { 0, 5 }, { 8, 4 } };
static const byte _airport_terminal_intercontinental[] = { 2, 4, 4 };
static const byte _airport_helipad_intercontinental[] = { 1, 2 };
static const byte _airport_entries_intercontinental[] = { 43, 43, 43, 43 };
static const AirportFTAbuildup _airport_fta_intercontinental[] = {
{ 0, HANGAR, NOTHING_block, 2 }, { 0, 255, HANGAR1_AREA_block | TERM_GROUP1_block, 0 }, { 0, 255, HANGAR1_AREA_block | TERM_GROUP1_block, 1 }, { 0, TAKEOFF, HANGAR1_AREA_block | TERM_GROUP1_block, 2 }, { 0, 0, 0, 2 },
{ 1, HANGAR, NOTHING_block, 3 }, { 1, 255, HANGAR2_AREA_block, 1 }, { 1, 255, HANGAR2_AREA_block, 0 }, { 1, 0, 0, 3 },
@ -684,6 +690,7 @@ static const AirportFTAbuildup _airport_fta_intercontinental[] = {
// heliports, oilrigs don't have depots
static const byte _airport_helipad_heliport_oilrig[] = { 1, 1 };
static const byte _airport_entries_heliport_oilrig[] = { 7, 7, 7, 7 };
static const AirportFTAbuildup _airport_fta_heliport_oilrig[] = {
{ 0, HELIPAD1, HELIPAD1_block, 1 },
{ 1, HELITAKEOFF, NOTHING_block, 0 }, // takeoff
@ -701,6 +708,7 @@ static const AirportFTAbuildup _airport_fta_heliport_oilrig[] = {
// helidepots
static const TileIndexDiffC _airport_depots_helidepot[] = { { 1, 0 } };
static const byte _airport_helipad_helidepot[] = { 1, 1 };
static const byte _airport_entries_helidepot[] = { 4, 4, 4, 4 };
static const AirportFTAbuildup _airport_fta_helidepot[] = {
{ 0, HANGAR, NOTHING_block, 1 },
{ 1, 255, HANGAR2_AREA_block, 0 }, { 1, HANGAR, 0, 0 }, { 1, HELIPAD1, HELIPAD1_block, 14 }, { 1, HELITAKEOFF, 0, 15 }, { 1, 0, 0, 0 },
@ -730,6 +738,7 @@ static const AirportFTAbuildup _airport_fta_helidepot[] = {
// helistation
static const TileIndexDiffC _airport_depots_helistation[] = { { 0, 0 } };
static const byte _airport_helipad_helistation[] = { 1, 3 };
static const byte _airport_entries_helistation[] = { 25, 25, 25, 25 };
static const AirportFTAbuildup _airport_fta_helistation[] = {
{ 0, HANGAR, NOTHING_block, 8 }, { 0, HELIPAD1, 0, 1 }, { 0, HELIPAD2, 0, 1 }, { 0, HELIPAD3, 0, 1 }, { 0, HELITAKEOFF, 0, 1 }, { 0, 0, 0, 0 },
{ 1, 255, HANGAR2_AREA_block, 0 }, { 1, HANGAR, 0, 0 }, { 1, HELITAKEOFF, 0, 3 }, { 1, 0, 0, 4 },