author | richk |
Tue, 17 Jun 2008 13:41:57 +0000 | |
branch | NewGRF_ports |
changeset 10995 | 311b38c7f9a7 |
parent 10724 | 68a692eacf22 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10724
68a692eacf22
(svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents:
6872
diff
changeset
|
3 |
/** @file airport.cpp Functions related to airports. */ |
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6413
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1299
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1093
diff
changeset
|
7 |
#include "debug.h" |
0 | 8 |
#include "airport.h" |
6872
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
9 |
#include "core/bitmath_func.hpp" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
10 |
#include "core/alloc_func.hpp" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
11 |
#include "date_func.h" |
1c4a4a609f85
(svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents:
6871
diff
changeset
|
12 |
#include "settings_type.h" |
6818
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
13 |
#include "newgrf_fsmports.h" |
0 | 14 |
|
6854
92ca286e9466
(svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents:
6853
diff
changeset
|
15 |
/* static */ AirportFTAClass *AirportFTAClass::oil_rig; ///< "Special" holding pattern used for oil rigs. |
92ca286e9466
(svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents:
6853
diff
changeset
|
16 |
/* static */ AirportFTAClass *AirportFTAClass::dummy; ///< A dummy holding pattern to be used when an airport has been removed, but the order to go to the airport has not been removed. |
92ca286e9466
(svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents:
6853
diff
changeset
|
17 |
|
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
18 |
/* Uncomment this to print out a full report of the airport-structure |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
19 |
* You should either use |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
20 |
* - true: full-report, print out every state and choice with string-names |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
21 |
* OR |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
22 |
* - false: give a summarized report which only shows current and next position */ |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
23 |
//#define DEBUG_AIRPORT false |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
24 |
|
6856
0e8e4ebf23ff
(svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents:
6854
diff
changeset
|
25 |
static byte AirportTestFTA(uint num_positions, const AirportFTA *layout, const byte *terminals); |
6183 | 26 |
|
27 |
#ifdef DEBUG_AIRPORT |
|
6853
b3b8bb6c0a48
(svn r10956) [NewGRF_ports] -Codechange: start refactoring the airport specific code to be more generic so it can be used for non-aircraft ports too.
rubidium
parents:
6837
diff
changeset
|
28 |
static void AirportPrintOut(uint nof_elements, const AirportFTA *layout, bool full_report); |
6183 | 29 |
#endif |
30 |
||
31 |
||
32 |
AirportFTAClass::~AirportFTAClass() |
|
0 | 33 |
{ |
6856
0e8e4ebf23ff
(svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents:
6854
diff
changeset
|
34 |
for (uint i = 0; i < num_positions; i++) { |
6183 | 35 |
AirportFTA *current = layout[i].next; |
0 | 36 |
while (current != NULL) { |
6183 | 37 |
AirportFTA *next = current->next; |
0 | 38 |
free(current); |
39 |
current = next; |
|
40 |
}; |
|
41 |
} |
|
6183 | 42 |
free(layout); |
0 | 43 |
} |
44 |
||
6856
0e8e4ebf23ff
(svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents:
6854
diff
changeset
|
45 |
static byte AirportTestFTA(uint num_positions, const AirportFTA *layout, const byte *terminals) |
0 | 46 |
{ |
6183 | 47 |
uint next_position = 0; |
0 | 48 |
|
6856
0e8e4ebf23ff
(svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents:
6854
diff
changeset
|
49 |
for (uint i = 0; i < num_positions; i++) { |
6183 | 50 |
uint position = layout[i].position; |
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
51 |
if (position != next_position) return i; |
6183 | 52 |
const AirportFTA *first = &layout[i]; |
0 | 53 |
|
6413 | 54 |
for (const AirportFTA *current = first; current != NULL; current = current->next) { |
4844
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
55 |
/* A heading must always be valid. The only exceptions are |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
56 |
* - multiple choices as start, identified by a special value of 255 |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
57 |
* - terminal group which is identified by a special value of 255 */ |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
58 |
if (current->heading > MAX_HEADINGS) { |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
59 |
if (current->heading != 255) return i; |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
60 |
if (current == first && current->next == NULL) return i; |
6183 | 61 |
if (current != first && current->next_position > terminals[0]) return i; |
4844
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
62 |
} |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
63 |
|
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
64 |
/* If there is only one choice, it must be at the end */ |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
65 |
if (current->heading == 0 && current->next != NULL) return i; |
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
66 |
/* Obviously the elements of the linked list must have the same identifier */ |
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
67 |
if (position != current->position) return i; |
4844
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
68 |
/* A next position must be within bounds */ |
6856
0e8e4ebf23ff
(svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents:
6854
diff
changeset
|
69 |
if (current->next_position >= num_positions) return i; |
4844
15faacbff622
(svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents:
4843
diff
changeset
|
70 |
} |
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
71 |
next_position++; |
0 | 72 |
} |
73 |
return MAX_ELEMENTS; |
|
74 |
} |
|
75 |
||
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
76 |
#ifdef DEBUG_AIRPORT |
2549 | 77 |
static const char* const _airport_heading_strings[] = { |
0 | 78 |
"TO_ALL", |
79 |
"HANGAR", |
|
80 |
"TERM1", |
|
81 |
"TERM2", |
|
82 |
"TERM3", |
|
83 |
"TERM4", |
|
84 |
"TERM5", |
|
85 |
"TERM6", |
|
86 |
"HELIPAD1", |
|
87 |
"HELIPAD2", |
|
88 |
"TAKEOFF", |
|
89 |
"STARTTAKEOFF", |
|
90 |
"ENDTAKEOFF", |
|
91 |
"HELITAKEOFF", |
|
92 |
"FLYING", |
|
93 |
"LANDING", |
|
94 |
"ENDLANDING", |
|
95 |
"HELILANDING", |
|
96 |
"HELIENDLANDING", |
|
4059
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
3876
diff
changeset
|
97 |
"TERM7", |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
3876
diff
changeset
|
98 |
"TERM8", |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
3876
diff
changeset
|
99 |
"HELIPAD3", |
f1442dfe1c8a
(svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents:
3876
diff
changeset
|
100 |
"HELIPAD4", |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4294
diff
changeset
|
101 |
"DUMMY" // extra heading for 255 |
0 | 102 |
}; |
103 |
||
6853
b3b8bb6c0a48
(svn r10956) [NewGRF_ports] -Codechange: start refactoring the airport specific code to be more generic so it can be used for non-aircraft ports too.
rubidium
parents:
6837
diff
changeset
|
104 |
static void AirportPrintOut(uint nof_elements, const AirportFTA *layout, bool full_report) |
0 | 105 |
{ |
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
106 |
if (!full_report) printf("(P = Current Position; NP = Next Position)\n"); |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
107 |
|
6853
b3b8bb6c0a48
(svn r10956) [NewGRF_ports] -Codechange: start refactoring the airport specific code to be more generic so it can be used for non-aircraft ports too.
rubidium
parents:
6837
diff
changeset
|
108 |
for (uint i = 0; i < nof_elements; i++) { |
6413 | 109 |
for (const AirportFTA *current = &layout[i]; current != NULL; current = current->next) { |
0 | 110 |
if (full_report) { |
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
111 |
byte heading = (current->heading == 255) ? MAX_HEADINGS + 1 : current->heading; |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
112 |
printf("\tPos:%2d NPos:%2d Heading:%15s Block:%2d\n", current->position, |
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
113 |
current->next_position, _airport_heading_strings[heading], |
6871
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6856
diff
changeset
|
114 |
FindLastBit(current->block)); |
2549 | 115 |
} else { |
4843
724322df355a
(svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents:
4842
diff
changeset
|
116 |
printf("P:%2d NP:%2d", current->position, current->next_position); |
0 | 117 |
} |
118 |
} |
|
119 |
printf("\n"); |
|
120 |
} |
|
121 |
} |
|
2549 | 122 |
#endif |
0 | 123 |
|
6818
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
124 |
std::list<uint16> GetAvailableAirports() |
0 | 125 |
{ |
6818
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
126 |
std::list<uint16> airports; |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
127 |
|
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
128 |
for (uint i = 0; i < GetNumFSMportsClasses(); i++) { |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
129 |
for (uint j = 0; j < GetNumCustomFSMports((FSMportsClassID)i); j++) { |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
130 |
const FSMportsSpec *spec = GetCustomFSMportsSpec((FSMportsClassID)i, j); |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
131 |
|
6871
5a9dc001e1ad
(svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents:
6856
diff
changeset
|
132 |
if (!HasBit(spec->callbackmask, CBM_STATION_AVAIL) || |
6818
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
133 |
GetFSMportsCallback(CBID_STATION_AVAILABILITY, 0, 0, spec, NULL, INVALID_TILE) != 0) { |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
134 |
airports.push_back(i << 8 | j); |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
135 |
} |
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
136 |
} |
0 | 137 |
} |
6818
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
138 |
|
8c977ca780fe
(svn r10898) [NewGRF_ports] -Codechange: replace GetAirport and GetValidAiports by GetAvailableAirports which gives a list of available airports that (primarily) AIs can iterate over.
rubidium
parents:
6769
diff
changeset
|
139 |
return airports; |
0 | 140 |
} |