summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-08-13 00:21:03 +0000
committeryexo <yexo@openttd.org>2010-08-13 00:21:03 +0000
commite4117dbfb7c940180eb8aab7f9d0a726364078ab (patch)
treee0002846625fbb2d70754311692d3401cdc3130f /src
parent6babc602542ebb2b6fb43fd2f2f46cc7ed4c2236 (diff)
downloadopenttd-e4117dbfb7c940180eb8aab7f9d0a726364078ab.tar.xz
(svn r20477) -Codechange: remove some airport-related constants/functions and add some documentation
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp91
-rw-r--r--src/airport.cpp1
-rw-r--r--src/airport.h10
-rw-r--r--src/newgrf_engine.cpp3
4 files changed, 36 insertions, 69 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 6664cef72..6dc0e05ee 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -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)
diff --git a/src/airport.cpp b/src/airport.cpp
index 6be9c0039..bb4957681 100644
--- a/src/airport.cpp
+++ b/src/airport.cpp
@@ -393,7 +393,6 @@ static const char * const _airport_heading_strings[] = {
"TERM7",
"TERM8",
"HELIPAD3",
- "HELIPAD4",
"DUMMY" // extra heading for 255
};
diff --git a/src/airport.h b/src/airport.h
index e91bdb1bd..b96c0939f 100644
--- a/src/airport.h
+++ b/src/airport.h
@@ -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,
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 92f6f0eb2..fd8835b8a 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -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