src/airport.h
author richk
Mon, 13 Aug 2007 20:01:30 +0000
branchNewGRF_ports
changeset 6805 2b3ed8e47662
parent 6771 5bb52a8ad34e
child 6818 8c977ca780fe
permissions -rw-r--r--
(svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
7B - force change of heading to <data>
7D - choose helipad from nominated group <data>
7E - choose terminal from nominated group <data>
-Change: Recoded terminal and helipad selection to default to All terms, or use the specific named one.
-Add: Added supporting function CanReserveBlocks. This has different logic to HasBlocks, where if the vehicle already owns some of the blocks, but the "missing" ones are free, then it can reserve those too. HasBlocks was all-or-fail.
-Change: updated airportsbasic.grf to match.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     2
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: 6367
diff changeset
     3
/** @file airport.h Various declarations for airports */
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: 6367
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#ifndef AIRPORT_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#define AIRPORT_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
     8
#include "direction.h"
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
     9
#include "fsmblockmap.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    10
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
    11
enum {MAX_TERMINALS =  36};
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
    12
enum {MAX_HELIPADS  =  24};
3701
13911c5df3e7 (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: 3697
diff changeset
    13
enum {MAX_ELEMENTS  = 255};
6715
ce1614834bc3 (svn r9507) [NewGRF_ports] -Codechange: Moved airport state definitions into their own separate file to permit better logical grouping of state machine related data & code.
richk
parents: 6574
diff changeset
    14
enum {MAX_HEADINGS  =  30};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
// Airport types
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
enum {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    18
	AT_SMALL         =  0,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    19
	AT_LARGE         =  1,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    20
	AT_HELIPORT      =  2,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    21
	AT_METROPOLITAN  =  3,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    22
	AT_INTERNATIONAL =  4,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    23
	AT_COMMUTER      =  5,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    24
	AT_HELIDEPOT     =  6,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    25
	AT_INTERCON      =  7,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4171
diff changeset
    26
	AT_HELISTATION   =  8,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6715
diff changeset
    27
	AT_OILRIG        = 15,
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6715
diff changeset
    28
	AT_DUMMY         = 255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    31
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    32
struct AirportMovingData {
6189
2b1ae5e373e9 (svn r8582) -Fix
tron
parents: 6183
diff changeset
    33
	int16 x;
2b1ae5e373e9 (svn r8582) -Fix
tron
parents: 6183
diff changeset
    34
	int16 y;
6766
99de9dc45509 (svn r10816) [NewGRF_ports] -Change: Vertical movement now based on difference in heights between current position and target position, rather than just being in particular states.
richk
parents: 6740
diff changeset
    35
	int16 z;
6740
0dec022fa01a (svn r10740) [NewGRF_ports] -Change: Order of vars in MovingData struct modified for gcc compilation.
richk
parents: 6739
diff changeset
    36
	uint16 flag;
0dec022fa01a (svn r10740) [NewGRF_ports] -Change: Order of vars in MovingData struct modified for gcc compilation.
richk
parents: 6739
diff changeset
    37
	DirectionByte direction;
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
    38
	byte state;
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
    39
	byte block;  //block number for this specific location
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    40
};
3701
13911c5df3e7 (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: 3697
diff changeset
    41
6183
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    42
struct AirportFTAbuildup;
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    43
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
// Finite sTate mAchine --> FTA
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    45
struct AirportFTAClass {
6175
26674ca57aac (svn r8559) -Fix
tron
parents: 6005
diff changeset
    46
	public:
6350
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6346
diff changeset
    47
		enum Flags {
6353
75b086ef8ef1 (svn r8750) -Fix (r8747): PLANES defined in wingdi.h caused compilation error under Win32. Changed to AIRPLANES
KUDr
parents: 6351
diff changeset
    48
			AIRPLANES   = 0x1,
6350
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6346
diff changeset
    49
			HELICOPTERS = 0x2,
6353
75b086ef8ef1 (svn r8750) -Fix (r8747): PLANES defined in wingdi.h caused compilation error under Win32. Changed to AIRPLANES
KUDr
parents: 6351
diff changeset
    50
			ALL         = AIRPLANES | HELICOPTERS,
6771
5bb52a8ad34e (svn r10825) [NewGRF_ports] -Feature: Airport subtype (prop 20) is now read. This restricts buildlist and usage of airports to the selected vehicle subtype.
richk
parents: 6769
diff changeset
    51
			SHORT_STRIP = 0x4,
5bb52a8ad34e (svn r10825) [NewGRF_ports] -Feature: Airport subtype (prop 20) is now read. This restricts buildlist and usage of airports to the selected vehicle subtype.
richk
parents: 6769
diff changeset
    52
			SEAPLANES   = 0x8
6350
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6346
diff changeset
    53
		};
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6346
diff changeset
    54
6183
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    55
		AirportFTAClass(
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    56
			AirportMovingData *moving_data,
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    57
			byte *terminals,
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    58
			byte *helipads,
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    59
			byte *entry_points,
6350
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6346
diff changeset
    60
			Flags flags,
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    61
			AirportFTAbuildup *apFA,
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6719
diff changeset
    62
			TileIndexDiffC *depots,
6183
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    63
			byte nof_depots,
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    64
			uint size_x,
6346
4aad704385e1 (svn r8743) -Fix
tron
parents: 6337
diff changeset
    65
			uint size_y,
6367
2f569d554980 (svn r8767) -Fix
tron
parents: 6362
diff changeset
    66
			byte delta_z,
2f569d554980 (svn r8767) -Fix
tron
parents: 6362
diff changeset
    67
			byte catchment
6183
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    68
		);
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    69
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    70
		~AirportFTAClass();
5d864a25ae2b (svn r8570) -Fix
tron
parents: 6175
diff changeset
    71
6738
72d1a2997952 (svn r10683) [NewGRF_ports] -Revert: Too eager to un-const... global search/replace removed too many. Restores necessary ones... for the moment ;)
richk
parents: 6737
diff changeset
    72
		const AirportMovingData *MovingData(byte position) const
6175
26674ca57aac (svn r8559) -Fix
tron
parents: 6005
diff changeset
    73
		{
26674ca57aac (svn r8559) -Fix
tron
parents: 6005
diff changeset
    74
			assert(position < nofelements);
26674ca57aac (svn r8559) -Fix
tron
parents: 6005
diff changeset
    75
			return &moving_data[position];
26674ca57aac (svn r8559) -Fix
tron
parents: 6005
diff changeset
    76
		}
26674ca57aac (svn r8559) -Fix
tron
parents: 6005
diff changeset
    77
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    78
	AirportMovingData *moving_data;
6189
2b1ae5e373e9 (svn r8582) -Fix
tron
parents: 6183
diff changeset
    79
	struct AirportFTA *layout;            // state machine for airport
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    80
	byte *terminals;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    81
	byte *helipads;
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6719
diff changeset
    82
	TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
6350
c644e180cdf8 (svn r8747) -Fix
tron
parents: 6346
diff changeset
    83
	Flags flags;
3697
bd03de677555 (svn r4638) - Codestyle: replacing aligning tabs with spaces
peter1138
parents: 2186
diff changeset
    84
	byte nof_depots;                      // number of depots this airport has
6189
2b1ae5e373e9 (svn r8582) -Fix
tron
parents: 6183
diff changeset
    85
	byte nofelements;                     // number of positions the airport consists of
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
    86
	byte *entry_points;             ///< when an airplane arrives at this airport, enter it at position entry_point, index depends on direction
3876
c0d426e78b56 (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
	byte size_x;
c0d426e78b56 (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
    88
	byte size_y;
6346
4aad704385e1 (svn r8743) -Fix
tron
parents: 6337
diff changeset
    89
	byte delta_z;                         // Z adjustment for helicopter pads
6367
2f569d554980 (svn r8767) -Fix
tron
parents: 6362
diff changeset
    90
	byte catchment;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    91
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
6351
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    93
DECLARE_ENUM_AS_BIT_SET(AirportFTAClass::Flags)
afb1e3960181 (svn r8748) -Fix
tron
parents: 6350
diff changeset
    94
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
// internal structure used in openttd - Finite sTate mAchine --> FTA
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    96
struct AirportFTA {
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    97
	AirportFTA *next;        // possible extra movement choices from this position
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
    98
	FSMblockmap reserveblock;       // 2 64 bit blocks
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
    99
	FSMblockmap releaseblock;       // 2 64 bit blocks
4842
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4344
diff changeset
   100
	byte position;           // the position that an airplane is at
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4344
diff changeset
   101
	byte next_position;      // next position from this position
0757e12896c5 (svn r6768) -Cleanup: For airports change *Airport to *apc (variable naming coding style
Darkvater
parents: 4344
diff changeset
   102
	byte heading;            // heading (current orders), guiding an airplane to its target on an airport
6805
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6771
diff changeset
   103
	byte special;            // used as extra data for special orders 7B, 7C, 7D, 7E
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   104
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6519
diff changeset
   106
void InitializeAirports();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6519
diff changeset
   107
void UnInitializeAirports();
6738
72d1a2997952 (svn r10683) [NewGRF_ports] -Revert: Too eager to un-const... global search/replace removed too many. Restores necessary ones... for the moment ;)
richk
parents: 6737
diff changeset
   108
const AirportFTAClass *GetAirport(const byte airport_type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1093
diff changeset
   110
/** Get buildable airport bitmask.
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1093
diff changeset
   111
 * @return get all buildable airports at this given time, bitmasked.
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1093
diff changeset
   112
 * Bit 0 means the small airport is buildable, etc.
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1093
diff changeset
   113
 * @todo set availability of airports by year, instead of airplane
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1093
diff changeset
   114
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6519
diff changeset
   115
uint32 GetValidAirports();
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1093
diff changeset
   116
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
#endif /* AIRPORT_H */