src/airport.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10374 3c10a7e9f831
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8270
diff changeset
     3
/** @file airport.cpp Functions related to airports. */
6117
6507b2a7e71d (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: 6087
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1299
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1093
diff changeset
     7
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "airport.h"
3701
fdbb6bcab8a2 (svn r4642) - Codechange: reorganise airport.h and airport_movement.h to avoid having 8 copies of the airport FTAs, and make the enums used available elsewhere.
peter1138
parents: 2752
diff changeset
     9
#include "airport_movement.h"
8113
31b7784db761 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8001
diff changeset
    10
#include "core/bitmath_func.hpp"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8113
diff changeset
    11
#include "core/alloc_func.hpp"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    12
#include "date_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8140
diff changeset
    13
#include "settings_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    15
/* Uncomment this to print out a full report of the airport-structure
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    16
 * You should either use
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    17
 * - true: full-report, print out every state and choice with string-names
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    18
 * OR
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    19
 * - false: give a summarized report which only shows current and next position */
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    20
//#define DEBUG_AIRPORT false
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
    21
6394
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    22
static AirportFTAClass *DummyAirport;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    23
static AirportFTAClass *CountryAirport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    24
static AirportFTAClass *CityAirport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    25
static AirportFTAClass *Oilrig;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    26
static AirportFTAClass *Heliport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    27
static AirportFTAClass *MetropolitanAirport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    28
static AirportFTAClass *InternationalAirport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    29
static AirportFTAClass *CommuterAirport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    30
static AirportFTAClass *HeliDepot;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    31
static AirportFTAClass *IntercontinentalAirport;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    32
static AirportFTAClass *HeliStation;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
    35
void InitializeAirports()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
{
6394
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    37
	DummyAirport = new AirportFTAClass(
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    38
		_airport_moving_data_dummy,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    39
		NULL,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    40
		NULL,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    41
		_airport_entries_dummy,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    42
		AirportFTAClass::ALL,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    43
		_airport_fta_dummy,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    44
		NULL,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    45
		0,
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
    46
		0, 0, 0,
6394
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    47
		0,
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    48
		0
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    49
	);
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
    50
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
    51
	CountryAirport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
    52
		_airport_moving_data_country,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    53
		_airport_terminal_country,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    54
		NULL,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
    55
		_airport_entries_country,
6025
414b34699e87 (svn r8748) -Fix
tron
parents: 6024
diff changeset
    56
		AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    57
		_airport_fta_country,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    58
		_airport_depots_country,
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3701
diff changeset
    59
		lengthof(_airport_depots_country),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
    60
		4, 3, 3,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
    61
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
    62
		4
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    63
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
    65
	CityAirport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
    66
		_airport_moving_data_town,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    67
		_airport_terminal_city,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    68
		NULL,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
    69
		_airport_entries_city,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
    70
		AirportFTAClass::ALL,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    71
		_airport_fta_city,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    72
		_airport_depots_city,
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3701
diff changeset
    73
		lengthof(_airport_depots_city),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
    74
		6, 6, 5,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
    75
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
    76
		5
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    77
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
    79
	MetropolitanAirport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
    80
		_airport_moving_data_metropolitan,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    81
		_airport_terminal_metropolitan,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    82
		NULL,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
    83
		_airport_entries_metropolitan,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
    84
		AirportFTAClass::ALL,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    85
		_airport_fta_metropolitan,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    86
		_airport_depots_metropolitan,
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3701
diff changeset
    87
		lengthof(_airport_depots_metropolitan),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
    88
		6, 6, 8,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
    89
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
    90
		6
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
    91
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
    93
	InternationalAirport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
    94
		_airport_moving_data_international,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    95
		_airport_terminal_international,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    96
		_airport_helipad_international,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
    97
		_airport_entries_international,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
    98
		AirportFTAClass::ALL,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
    99
		_airport_fta_international,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   100
		_airport_depots_international,
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3701
diff changeset
   101
		lengthof(_airport_depots_international),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   102
		7, 7, 17,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   103
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   104
		8
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   105
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   107
	IntercontinentalAirport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   108
		_airport_moving_data_intercontinental,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   109
		_airport_terminal_intercontinental,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   110
		_airport_helipad_intercontinental,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   111
		_airport_entries_intercontinental,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   112
		AirportFTAClass::ALL,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   113
		_airport_fta_intercontinental,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   114
		_airport_depots_intercontinental,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   115
		lengthof(_airport_depots_intercontinental),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   116
		9, 11, 25,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   117
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   118
		10
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   119
	);
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   120
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   121
	Heliport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   122
		_airport_moving_data_heliport,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   123
		NULL,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   124
		_airport_helipad_heliport_oilrig,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   125
		_airport_entries_heliport_oilrig,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   126
		AirportFTAClass::HELICOPTERS,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   127
		_airport_fta_heliport_oilrig,
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   128
		NULL,
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3701
diff changeset
   129
		0,
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   130
		1, 1, 1,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   131
		60,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   132
		4
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   133
	);
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   134
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   135
	Oilrig = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   136
		_airport_moving_data_oilrig,
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   137
		NULL,
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   138
		_airport_helipad_heliport_oilrig,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   139
		_airport_entries_heliport_oilrig,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   140
		AirportFTAClass::HELICOPTERS,
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   141
		_airport_fta_heliport_oilrig,
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   142
		NULL,
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   143
		0,
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   144
		1, 1, 0,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   145
		54,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   146
		3
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   147
	);
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   148
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   149
	CommuterAirport = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   150
		_airport_moving_data_commuter,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   151
		_airport_terminal_commuter,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   152
		_airport_helipad_commuter,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   153
		_airport_entries_commuter,
6025
414b34699e87 (svn r8748) -Fix
tron
parents: 6024
diff changeset
   154
		AirportFTAClass::ALL | AirportFTAClass::SHORT_STRIP,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   155
		_airport_fta_commuter,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   156
		_airport_depots_commuter,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   157
		lengthof(_airport_depots_commuter),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   158
		5, 4, 4,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   159
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   160
		4
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   161
	);
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   162
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   163
	HeliDepot = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   164
		_airport_moving_data_helidepot,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   165
		NULL,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   166
		_airport_helipad_helidepot,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   167
		_airport_entries_helidepot,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   168
		AirportFTAClass::HELICOPTERS,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   169
		_airport_fta_helidepot,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   170
		_airport_depots_helidepot,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   171
		lengthof(_airport_depots_helidepot),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   172
		2, 2, 2,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   173
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   174
		4
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   175
	);
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   176
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   177
	HeliStation = new AirportFTAClass(
5924
f9e5c4f44bc5 (svn r8559) -Fix
tron
parents: 5609
diff changeset
   178
		_airport_moving_data_helistation,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   179
		NULL,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   180
		_airport_helipad_helistation,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   181
		_airport_entries_helistation,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   182
		AirportFTAClass::HELICOPTERS,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   183
		_airport_fta_helistation,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   184
		_airport_depots_helistation,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   185
		lengthof(_airport_depots_helistation),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   186
		4, 2, 3,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   187
		0,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   188
		4
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   189
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
   192
void UnInitializeAirports()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
{
7804
fc2d1522f741 (svn r11354) -Codechange [FS#1379]: one variable wasn't freed whereas all others were. It's not causing any problems as it happens during the shutdown of OpenTTD. So basically it is only for consistency.
rubidium
parents: 6394
diff changeset
   194
	delete DummyAirport;
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   195
	delete CountryAirport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   196
	delete CityAirport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   197
	delete Heliport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   198
	delete MetropolitanAirport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   199
	delete InternationalAirport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   200
	delete CommuterAirport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   201
	delete HeliDepot;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   202
	delete IntercontinentalAirport;
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   203
	delete HeliStation;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   206
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   207
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA);
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   208
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA);
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   209
static byte AirportGetTerminalCount(const byte *terminals, byte *groups);
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   210
static byte AirportTestFTA(uint nofelements, const AirportFTA *layout, const byte *terminals);
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   211
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   212
#ifdef DEBUG_AIRPORT
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   213
static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool full_report);
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   214
#endif
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   215
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   216
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   217
AirportFTAClass::AirportFTAClass(
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   218
	const AirportMovingData *moving_data_,
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   219
	const byte *terminals_,
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   220
	const byte *helipads_,
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   221
	const byte *entry_points_,
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   222
	Flags flags_,
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   223
	const AirportFTAbuildup *apFA,
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   224
	const TileIndexDiffC *depots_,
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   225
	const byte nof_depots_,
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   226
	uint size_x_,
6020
a7463b7eb894 (svn r8743) -Fix
tron
parents: 5971
diff changeset
   227
	uint size_y_,
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   228
	byte noise_level_,
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   229
	byte delta_z_,
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   230
	byte catchment_
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   231
) :
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   232
	moving_data(moving_data_),
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   233
	terminals(terminals_),
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   234
	helipads(helipads_),
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   235
	airport_depots(depots_),
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 6020
diff changeset
   236
	flags(flags_),
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   237
	nof_depots(nof_depots_),
5938
e84a886e6514 (svn r8582) -Fix
tron
parents: 5932
diff changeset
   238
	nofelements(AirportGetNofElements(apFA)),
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   239
	entry_points(entry_points_),
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   240
	size_x(size_x_),
6020
a7463b7eb894 (svn r8743) -Fix
tron
parents: 5971
diff changeset
   241
	size_y(size_y_),
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9111
diff changeset
   242
	noise_level(noise_level_),
6041
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   243
	delta_z(delta_z_),
bba4112e5daa (svn r8767) -Fix
tron
parents: 6036
diff changeset
   244
	catchment(catchment_)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
{
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   246
	byte nofterminalgroups, nofhelipadgroups;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 950
diff changeset
   247
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   248
	/* Set up the terminal and helipad count for an airport.
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   249
	 * TODO: If there are more than 10 terminals or 4 helipads, internal variables
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   250
	 * need to be changed, so don't allow that for now */
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   251
	uint nofterminals = AirportGetTerminalCount(terminals, &nofterminalgroups);
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   252
	if (nofterminals > MAX_TERMINALS) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4844
diff changeset
   253
		DEBUG(misc, 0, "[Ap] only a maximum of %d terminals are supported (requested %d)", MAX_TERMINALS, nofterminals);
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   254
		assert(nofterminals <= MAX_TERMINALS);
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   255
	}
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   256
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   257
	uint nofhelipads = AirportGetTerminalCount(helipads, &nofhelipadgroups);
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   258
	if (nofhelipads > MAX_HELIPADS) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 4844
diff changeset
   259
		DEBUG(misc, 0, "[Ap] only a maximum of %d helipads are supported (requested %d)", MAX_HELIPADS, nofhelipads);
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   260
		assert(nofhelipads <= MAX_HELIPADS);
950
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   261
	}
165341d74973 (svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents: 909
diff changeset
   262
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   263
	/* Get the number of elements from the source table. We also double check this
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   264
	 * with the entry point which must be within bounds and use this information
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   265
	 * later on to build and validate the state machine */
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   266
	for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
333637e97400 (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
celestar
parents: 6025
diff changeset
   267
		if (entry_points[i] >= nofelements) {
333637e97400 (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
celestar
parents: 6025
diff changeset
   268
			DEBUG(misc, 0, "[Ap] entry (%d) must be within the airport (maximum %d)", entry_points[i], nofelements);
333637e97400 (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
celestar
parents: 6025
diff changeset
   269
			assert(entry_points[i] < nofelements);
333637e97400 (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
celestar
parents: 6025
diff changeset
   270
		}
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   271
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   273
	/* Build the state machine itself */
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   274
	layout = AirportBuildAutomata(nofelements, apFA);
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   275
	DEBUG(misc, 6, "[Ap] #count %3d; #term %2d (%dgrp); #helipad %2d (%dgrp); entries %3d, %3d, %3d, %3d",
6036
333637e97400 (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
celestar
parents: 6025
diff changeset
   276
		nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups,
333637e97400 (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
celestar
parents: 6025
diff changeset
   277
		entry_points[DIAGDIR_NE], entry_points[DIAGDIR_SE], entry_points[DIAGDIR_SW], entry_points[DIAGDIR_NW]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   279
	/* Test if everything went allright. This is only a rude static test checking
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   280
	 * the symantic correctness. By no means does passing the test mean that the
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   281
	 * airport is working correctly or will not deadlock for example */
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   282
	uint ret = AirportTestFTA(nofelements, layout, terminals);
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   283
	if (ret != MAX_ELEMENTS) DEBUG(misc, 0, "[Ap] problem with element: %d", ret - 1);
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   284
	assert(ret == MAX_ELEMENTS);
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   285
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   286
#ifdef DEBUG_AIRPORT
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   287
	AirportPrintOut(nofelements, layout, DEBUG_AIRPORT);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   288
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   291
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   292
AirportFTAClass::~AirportFTAClass()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
{
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   294
	for (uint i = 0; i < nofelements; i++) {
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   295
		AirportFTA *current = layout[i].next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
		while (current != NULL) {
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   297
			AirportFTA *next = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
			free(current);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
			current = next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	}
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   302
	free(layout);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   305
/** Get the number of elements of a source Airport state automata
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   306
 * Since it is actually just a big array of AirportFTA types, we only
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   307
 * know one element from the other by differing 'position' identifiers */
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   308
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	uint16 nofelements = 0;
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   311
	int temp = apFA[0].position;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   312
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6041
diff changeset
   313
	for (uint i = 0; i < MAX_ELEMENTS; i++) {
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   314
		if (temp != apFA[i].position) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
			nofelements++;
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   316
			temp = apFA[i].position;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		}
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   318
		if (apFA[i].position == MAX_ELEMENTS) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	return nofelements;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   323
/** We calculate the terminal/helipod count based on the data passed to us
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   324
 * This data (terminals) contains an index as a first element as to how many
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   325
 * groups there are, and then the number of terminals for each group */
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   326
static byte AirportGetTerminalCount(const byte *terminals, byte *groups)
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   327
{
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   328
	byte nof_terminals = 0;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   329
	*groups = 0;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   330
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   331
	if (terminals != NULL) {
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6041
diff changeset
   332
		uint i = terminals[0];
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   333
		*groups = i;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   334
		while (i-- > 0) {
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   335
			terminals++;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   336
			assert(*terminals != 0); // no empty groups please
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   337
			nof_terminals += *terminals;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   338
		}
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   339
	}
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   340
	return nof_terminals;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   341
}
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   342
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   343
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   344
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
{
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   346
	AirportFTA *FAutomata = MallocT<AirportFTA>(nofelements);
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   347
	uint16 internalcounter = 0;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   348
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   349
	for (uint i = 0; i < nofelements; i++) {
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6041
diff changeset
   350
		AirportFTA *current = &FAutomata[i];
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   351
		current->position      = apFA[internalcounter].position;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   352
		current->heading       = apFA[internalcounter].heading;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   353
		current->block         = apFA[internalcounter].block;
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   354
		current->next_position = apFA[internalcounter].next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   356
		/* outgoing nodes from the same position, create linked list */
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   357
		while (current->position == apFA[internalcounter + 1].position) {
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   358
			AirportFTA *newNode = MallocT<AirportFTA>(1);
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   359
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   360
			newNode->position      = apFA[internalcounter + 1].position;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   361
			newNode->heading       = apFA[internalcounter + 1].heading;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   362
			newNode->block         = apFA[internalcounter + 1].block;
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   363
			newNode->next_position = apFA[internalcounter + 1].next;
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   364
			/* create link */
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   365
			current->next = newNode;
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   366
			current = current->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
			internalcounter++;
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6041
diff changeset
   368
		}
4842
79c4c9167d93 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4434
diff changeset
   369
		current->next = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		internalcounter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	}
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   372
	return FAutomata;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   375
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   376
static byte AirportTestFTA(uint nofelements, const AirportFTA *layout, const byte *terminals)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
{
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   378
	uint next_position = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   380
	for (uint i = 0; i < nofelements; i++) {
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   381
		uint position = layout[i].position;
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   382
		if (position != next_position) return i;
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   383
		const AirportFTA *first = &layout[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6041
diff changeset
   385
		for (const AirportFTA *current = first; current != NULL; current = current->next) {
4844
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   386
			/* A heading must always be valid. The only exceptions are
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   387
			 * - multiple choices as start, identified by a special value of 255
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   388
			 * - terminal group which is identified by a special value of 255 */
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   389
			if (current->heading > MAX_HEADINGS) {
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   390
				if (current->heading != 255) return i;
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   391
				if (current == first && current->next == NULL) return i;
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   392
				if (current != first && current->next_position > terminals[0]) return i;
4844
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   393
			}
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   394
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   395
			/* If there is only one choice, it must be at the end */
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   396
			if (current->heading == 0 && current->next != NULL) return i;
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   397
			/* Obviously the elements of the linked list must have the same identifier */
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   398
			if (position != current->position) return i;
4844
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   399
			/* A next position must be within bounds */
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   400
			if (current->next_position >= nofelements) return i;
4844
10fde6a49e04 (svn r6770) -Codechange: Make the airport checking a bit stricter...fix unnoticed errors:
Darkvater
parents: 4843
diff changeset
   401
		}
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   402
		next_position++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	return MAX_ELEMENTS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   407
#ifdef DEBUG_AIRPORT
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   408
static const char * const _airport_heading_strings[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	"TO_ALL",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	"HANGAR",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
	"TERM1",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	"TERM2",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
	"TERM3",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	"TERM4",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
	"TERM5",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	"TERM6",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	"HELIPAD1",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
	"HELIPAD2",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	"TAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	"STARTTAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	"ENDTAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	"HELITAKEOFF",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	"FLYING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	"LANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	"ENDLANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	"HELILANDING",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	"HELIENDLANDING",
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   428
	"TERM7",
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   429
	"TERM8",
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   430
	"HELIPAD3",
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 3876
diff changeset
   431
	"HELIPAD4",
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4294
diff changeset
   432
	"DUMMY" // extra heading for 255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   435
static void AirportPrintOut(uint nofelements, const AirportFTA *layout, bool full_report)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
{
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   437
	if (!full_report) printf("(P = Current Position; NP = Next Position)\n");
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   438
5932
6f742a8da016 (svn r8570) -Fix
tron
parents: 5924
diff changeset
   439
	for (uint i = 0; i < nofelements; i++) {
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6041
diff changeset
   440
		for (const AirportFTA *current = &layout[i]; current != NULL; current = current->next) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
			if (full_report) {
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   442
				byte heading = (current->heading == 255) ? MAX_HEADINGS + 1 : current->heading;
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   443
				printf("\tPos:%2d NPos:%2d Heading:%15s Block:%2d\n", current->position,
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   444
					    current->next_position, _airport_heading_strings[heading],
8001
9b2d21bf71ba (svn r11560) -Codechange: replace 'custom' version of FindLastBit with the generic.
rubidium
parents: 7931
diff changeset
   445
							FindLastBit(current->block));
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   446
			} else {
4843
4bef85baee3f (svn r6769) -Codechange: Minor syntax, const correctness, variable localization, coding
Darkvater
parents: 4842
diff changeset
   447
				printf("P:%2d NP:%2d", current->position, current->next_position);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
		printf("\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
}
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2186
diff changeset
   453
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   455
const AirportFTAClass *GetAirport(const byte airport_type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
{
10374
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   457
	/* FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code
3c10a7e9f831 (svn r14625) -Codechange: a bit of coding style.
rubidium
parents: 9413
diff changeset
   458
	 * needs constant change if more airports are added */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	switch (airport_type) {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   460
		default:               NOT_REACHED();
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   461
		case AT_SMALL:         return CountryAirport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   462
		case AT_LARGE:         return CityAirport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   463
		case AT_METROPOLITAN:  return MetropolitanAirport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   464
		case AT_HELIPORT:      return Heliport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   465
		case AT_OILRIG:        return Oilrig;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   466
		case AT_INTERNATIONAL: return InternationalAirport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   467
		case AT_COMMUTER:      return CommuterAirport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   468
		case AT_HELIDEPOT:     return HeliDepot;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   469
		case AT_INTERCON:      return IntercontinentalAirport;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4059
diff changeset
   470
		case AT_HELISTATION:   return HeliStation;
6394
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6247
diff changeset
   471
		case AT_DUMMY:         return DummyAirport;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
}
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   474
3701
fdbb6bcab8a2 (svn r4642) - Codechange: reorganise airport.h and airport_movement.h to avoid having 8 copies of the airport FTAs, and make the enums used available elsewhere.
peter1138
parents: 2752
diff changeset
   475
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6117
diff changeset
   476
uint32 GetValidAirports()
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   477
{
5971
b21fda7c7f1e (svn r8660) -Fix
tron
parents: 5938
diff changeset
   478
	uint32 mask = 0;
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   479
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9354
diff changeset
   480
	if (_cur_year <  1960 || _settings_game.station.always_small_airport) SetBit(mask, 0);  // small airport
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   481
	if (_cur_year >= 1955) SetBit(mask, 1); // city airport
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   482
	if (_cur_year >= 1963) SetBit(mask, 2); // heliport
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   483
	if (_cur_year >= 1980) SetBit(mask, 3); // metropolitan airport
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   484
	if (_cur_year >= 1990) SetBit(mask, 4); // international airport
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   485
	if (_cur_year >= 1983) SetBit(mask, 5); // commuter airport
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   486
	if (_cur_year >= 1976) SetBit(mask, 6); // helidepot
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   487
	if (_cur_year >= 2002) SetBit(mask, 7); // intercontinental airport
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7804
diff changeset
   488
	if (_cur_year >= 1980) SetBit(mask, 8); // helistation
5971
b21fda7c7f1e (svn r8660) -Fix
tron
parents: 5938
diff changeset
   489
	return mask;
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1891
diff changeset
   490
}