mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r20477) -Codechange: remove some airport-related constants/functions and add some documentation
This commit is contained in:
parent
6babc60254
commit
e4117dbfb7
|
@ -71,14 +71,6 @@ void Aircraft::UpdateDeltaXY(Direction direction)
|
|||
this->y_extent = GB(x, 24, 8);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this maps the terminal to its corresponding state and block flag
|
||||
* currently set for 10 terms, 4 helipads
|
||||
*/
|
||||
static const byte _airport_terminal_state[] = {2, 3, 4, 5, 6, 7, 19, 20, 0, 0, 8, 9, 21, 22};
|
||||
static const byte _airport_terminal_flag[] = {0, 1, 2, 3, 4, 5, 22, 23, 0, 0, 6, 7, 24, 25};
|
||||
|
||||
static bool AirportMove(Aircraft *v, const AirportFTAClass *apc);
|
||||
static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
|
||||
static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc);
|
||||
|
@ -1638,7 +1630,6 @@ static AircraftStateHandler * const _aircraft_state_handlers[] = {
|
|||
AircraftEventHandler_AtTerminal, // TERM7 = 19
|
||||
AircraftEventHandler_AtTerminal, // TERM8 = 20
|
||||
AircraftEventHandler_AtTerminal, // HELIPAD3 = 21
|
||||
AircraftEventHandler_AtTerminal, // HELIPAD4 = 22
|
||||
};
|
||||
|
||||
static void AirportClearBlock(const Aircraft *v, const AirportFTAClass *apc)
|
||||
|
@ -1780,14 +1771,39 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combination of aircraft state for going to a certain terminal and the
|
||||
* airport flag for that terminal block.
|
||||
*/
|
||||
struct MovementTerminalMapping {
|
||||
AirportMovementStates state; ///< Aircraft movement state when going to this terminal.
|
||||
uint64 airport_flag; ///< Bitmask in the airport flags that need to be free for this terminal.
|
||||
};
|
||||
|
||||
/** A list of all valid terminals and their associated blocks. */
|
||||
static const MovementTerminalMapping _airport_terminal_mapping[] = {
|
||||
{TERM1, TERM1_block},
|
||||
{TERM2, TERM2_block},
|
||||
{TERM3, TERM3_block},
|
||||
{TERM4, TERM4_block},
|
||||
{TERM5, TERM5_block},
|
||||
{TERM6, TERM6_block},
|
||||
{TERM7, TERM7_block},
|
||||
{TERM8, TERM8_block},
|
||||
{HELIPAD1, HELIPAD1_block},
|
||||
{HELIPAD2, HELIPAD2_block},
|
||||
{HELIPAD3, HELIPAD3_block},
|
||||
};
|
||||
|
||||
static bool FreeTerminal(Aircraft *v, byte i, byte last_terminal)
|
||||
{
|
||||
assert(last_terminal <= lengthof(_airport_terminal_mapping));
|
||||
Station *st = Station::Get(v->targetairport);
|
||||
for (; i < last_terminal; i++) {
|
||||
if (!HasBit(st->airport.flags, _airport_terminal_flag[i])) {
|
||||
if ((st->airport.flags & _airport_terminal_mapping[i].airport_flag) == 0) {
|
||||
/* TERMINAL# HELIPAD# */
|
||||
v->state = _airport_terminal_state[i]; // start moving to that terminal/helipad
|
||||
SetBit(st->airport.flags, _airport_terminal_flag[i]); // occupy terminal/helipad
|
||||
v->state = _airport_terminal_mapping[i].state; // start moving to that terminal/helipad
|
||||
SETBITS(st->airport.flags, _airport_terminal_mapping[i].airport_flag); // occupy terminal/helipad
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1850,58 +1866,15 @@ static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc)
|
|||
return FreeTerminal(v, 0, GetNumTerminals(apc));
|
||||
}
|
||||
|
||||
static uint GetNumHelipads(const AirportFTAClass *apc)
|
||||
{
|
||||
uint num = 0;
|
||||
|
||||
for (uint i = apc->helipads[0]; i > 0; i--) num += apc->helipads[i];
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
static bool AirportFindFreeHelipad(Aircraft *v, const AirportFTAClass *apc)
|
||||
{
|
||||
/* if an airport doesn't have helipads, use terminals */
|
||||
if (apc->helipads == NULL) return AirportFindFreeTerminal(v, apc);
|
||||
|
||||
/* if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal() */
|
||||
if (apc->helipads[0] > 1) {
|
||||
const Station *st = Station::Get(v->targetairport);
|
||||
const AirportFTA *temp = apc->layout[v->pos].next;
|
||||
|
||||
while (temp != NULL) {
|
||||
if (temp->heading == 255) {
|
||||
if (!(st->airport.flags & temp->block)) {
|
||||
|
||||
/* read which group do we want to go to?
|
||||
* (the first free group) */
|
||||
uint target_group = temp->next_position + 1;
|
||||
|
||||
/* at what terminal does the group start?
|
||||
* that means, sum up all terminals of
|
||||
* groups with lower number */
|
||||
uint group_start = 0;
|
||||
for (uint i = 1; i < target_group; i++) {
|
||||
group_start += apc->helipads[i];
|
||||
}
|
||||
|
||||
uint group_end = group_start + apc->helipads[target_group];
|
||||
if (FreeTerminal(v, group_start, group_end)) return true;
|
||||
}
|
||||
} else {
|
||||
/* once the heading isn't 255, we've exhausted the possible blocks.
|
||||
* So we cannot move */
|
||||
return false;
|
||||
}
|
||||
temp = temp->next;
|
||||
}
|
||||
} else {
|
||||
/* only 1 helicoptergroup, check all helipads
|
||||
* The blocks for helipads start after the last terminal (MAX_TERMINALS) */
|
||||
return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(apc) + MAX_TERMINALS);
|
||||
}
|
||||
return false; // it shouldn't get here anytime, but just to be sure
|
||||
assert(apc->helipads[0] == 1);
|
||||
/* only 1 helicoptergroup, check all helipads
|
||||
* The blocks for helipads start after the last terminal (MAX_TERMINALS) */
|
||||
return FreeTerminal(v, MAX_TERMINALS, apc->helipads[1] + MAX_TERMINALS);
|
||||
}
|
||||
|
||||
static bool AircraftEventHandler(Aircraft *v, int loop)
|
||||
|
|
|
@ -393,7 +393,6 @@ static const char * const _airport_heading_strings[] = {
|
|||
"TERM7",
|
||||
"TERM8",
|
||||
"HELIPAD3",
|
||||
"HELIPAD4",
|
||||
"DUMMY" // extra heading for 255
|
||||
};
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include "tile_type.h"
|
||||
|
||||
/** Some airport-related constants */
|
||||
static const uint MAX_TERMINALS = 10; ///< maximum number of terminals per airport
|
||||
static const uint MAX_HELIPADS = 4; ///< maximum number of helipads per airport
|
||||
static const uint MAX_TERMINALS = 8; ///< maximum number of terminals per airport
|
||||
static const uint MAX_HELIPADS = 3; ///< maximum number of helipads per airport
|
||||
static const uint MAX_ELEMENTS = 255; ///< maximum number of aircraft positions at airport
|
||||
|
||||
static const uint NUM_AIRPORTTILES = 256; ///< total number of airport tiles
|
||||
|
@ -78,8 +78,7 @@ enum AirportMovementStates {
|
|||
TERM7 = 19,
|
||||
TERM8 = 20,
|
||||
HELIPAD3 = 21,
|
||||
HELIPAD4 = 22,
|
||||
MAX_HEADINGS = 22,
|
||||
MAX_HEADINGS = 21,
|
||||
};
|
||||
|
||||
/* Movement Blocks on Airports
|
||||
|
@ -113,10 +112,7 @@ static const uint64
|
|||
/* blocks for new airports */
|
||||
TERM7_block = 1ULL << 22,
|
||||
TERM8_block = 1ULL << 23,
|
||||
TERM9_block = 1ULL << 24,
|
||||
HELIPAD3_block = 1ULL << 24,
|
||||
TERM10_block = 1ULL << 25,
|
||||
HELIPAD4_block = 1ULL << 25,
|
||||
HANGAR1_AREA_block = 1ULL << 26,
|
||||
OUT_WAY2_block = 1ULL << 27,
|
||||
IN_WAY2_block = 1ULL << 28,
|
||||
|
|
|
@ -242,7 +242,7 @@ static byte MapAircraftMovementState(const Aircraft *v)
|
|||
case HELIPAD1:
|
||||
case HELIPAD2:
|
||||
case HELIPAD3:
|
||||
case HELIPAD4: // Will only occur for helicopters.
|
||||
/* Will only occur for helicopters.*/
|
||||
if (amdflag & AMED_HELI_LOWER) return AMS_TTDP_HELI_LAND_AIRPORT; // Descending.
|
||||
if (amdflag & AMED_SLOWTURN) return AMS_TTDP_FLIGHT_TO_TOWER; // Still hasn't started descent.
|
||||
return AMS_TTDP_TO_JUNCTION; // On the ground.
|
||||
|
@ -340,7 +340,6 @@ static byte MapAircraftMovementAction(const Aircraft *v)
|
|||
case TERM7:
|
||||
case TERM8:
|
||||
case HELIPAD3:
|
||||
case HELIPAD4:
|
||||
return (v->current_order.IsType(OT_LOADING)) ? AMA_TTDP_ON_PAD3 : AMA_TTDP_LANDING_TO_PAD3;
|
||||
|
||||
case TAKEOFF: // Moving to takeoff position
|
||||
|
|
Loading…
Reference in New Issue