OpenTTD Source: src/newgrf_airport.h Source File

OpenTTD Source 14.0-beta3

newgrf_airport.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef NEWGRF_AIRPORT_H
11 #define NEWGRF_AIRPORT_H
12
13 #include "airport.h"
14 #include "timer/timer_game_calendar.h"
15 #include "newgrf_class.h"
16 #include "newgrf_commons.h"
17 #include "newgrf_spritegroup.h"
18 #include "newgrf_town.h"
19 #include "tilearea_type.h"
20
22 typedef byte StationGfx;
23
25 struct AirportTileTable {
26 TileIndexDiffC ti;
27 StationGfx gfx;
28 };
29
31 class AirportTileTableIterator : public TileIterator {
32 private:
33 const AirportTileTable *att;
34 TileIndex base_tile;
35
36 public:
42 AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile) : TileIterator(base_tile + ToTileIndexDiff(att->ti)), att(att), base_tile(base_tile)
43 {
44 }
45
46 inline TileIterator& operator ++() override
47 {
48 this->att++;
49 if (this->att->ti.x == -0x80) {
50 this->tile = INVALID_TILE;
51 } else {
52 this->tile = this->base_tile + ToTileIndexDiff(this->att->ti);
53 }
54 return *this;
55 }
56
58 StationGfx GetStationGfx() const
59 {
60 return this->att->gfx;
61 }
62
63 std::unique_ptr<TileIterator> Clone() const override
64 {
65 return std::make_unique<AirportTileTableIterator>(*this);
66 }
67 };
68
70 enum AirportClassID {
71 APC_BEGIN = 0,
72 APC_SMALL = 0,
73 APC_LARGE,
74 APC_HUB,
75 APC_HELIPORT,
76 APC_MAX = 16,
77 };
78
80 DECLARE_POSTFIX_INCREMENT(AirportClassID)
81
82
83 enum TTDPAirportType {
84 ATP_TTDP_SMALL,
85 ATP_TTDP_LARGE,
86 ATP_TTDP_HELIPORT,
87 ATP_TTDP_OILRIG,
88 };
89
91 struct HangarTileTable {
92 TileIndexDiffC ti;
93 Direction dir;
94 byte hangar_num;
95 };
96
100 struct AirportSpec {
101 const struct AirportFTAClass *fsm;
102 const AirportTileTable * const *table;
103 const Direction *rotation;
104 byte num_table;
105 const HangarTileTable *depot_table;
106 byte nof_depots;
107 byte size_x;
108 byte size_y;
109 byte noise_level;
110 byte catchment;
111 TimerGameCalendar::Year min_year;
112 TimerGameCalendar::Year max_year;
113 StringID name;
114 TTDPAirportType ttd_airport_type;
115 AirportClassID cls_id;
116 SpriteID preview_sprite;
117 uint16_t maintenance_cost;
118 /* Newgrf data */
119 bool enabled;
120 struct GRFFileProps grf_prop;
121
122 static const AirportSpec *Get(byte type);
123 static AirportSpec *GetWithoutOverride(byte type);
124
125 bool IsAvailable() const;
126 bool IsWithinMapBounds(byte table, TileIndex index) const;
127
128 static void ResetAirports();
129
131 byte GetIndex() const
132 {
133 assert(this >= specs && this < endof(specs));
134 return (byte)(this - specs);
135 }
136
137 static const AirportSpec dummy;
138
139 private:
140 static AirportSpec specs[NUM_AIRPORTS];
141 };
142
144 typedef NewGRFClass<AirportSpec, AirportClassID, APC_MAX> AirportClass;
145
146 void BindAirportSpecs();
147
149 struct AirportScopeResolver : public ScopeResolver {
150 struct Station *st;
151 byte airport_id;
152 byte layout;
153 TileIndex tile;
154
163 AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout)
164 : ScopeResolver(ro), st(st), airport_id(airport_id), layout(layout), tile(tile)
165 {
166 }
167
168 uint32_t GetRandomBits() const override;
169 uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override;
170 void StorePSA(uint pos, int32_t value) override;
171 };
172
173
175 struct AirportResolverObject : public ResolverObject {
176 AirportScopeResolver airport_scope;
177 std::unique_ptr<TownScopeResolver> town_scope;
178
179 AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout,
180 CallbackID callback = CBID_NO_CALLBACK, uint32_t callback_param1 = 0, uint32_t callback_param2 = 0);
181
182 TownScopeResolver *GetTown();
183
184 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
185 {
186 switch (scope) {
187 case VSG_SCOPE_SELF: return &this->airport_scope;
188 case VSG_SCOPE_PARENT:
189 {
190 TownScopeResolver *tsr = this->GetTown();
191 if (tsr != nullptr) return tsr;
192 [[fallthrough]];
193 }
194 default: return ResolverObject::GetScope(scope, relative);
195 }
196 }
197
198 GrfSpecFeature GetFeature() const override;
199 uint32_t GetDebugID() const override;
200 };
201
202 StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16_t callback);
203
204 #endif /* NEWGRF_AIRPORT_H */
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:97
TileIterator::tile
TileIndex tile
The current tile we are at.
Definition: tilearea_type.h:107
StationGfx
byte StationGfx
Copy from station_map.h.
Definition: newgrf_airport.h:22
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
AirportSpec::IsWithinMapBounds
bool IsWithinMapBounds(byte table, TileIndex index) const
Check if the airport would be within the map bounds at the given tile.
Definition: newgrf_airport.cpp:95
AirportResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_airport.cpp:178
AirportTileTableIterator::GetStationGfx
StationGfx GetStationGfx() const
Get the StationGfx for the current tile.
Definition: newgrf_airport.h:58
AirportTileTableIterator::base_tile
TileIndex base_tile
The tile we base the offsets off.
Definition: newgrf_airport.h:34
newgrf_commons.h
timer_game_calendar.h
AirportSpec::size_y
byte size_y
size of airport in y direction
Definition: newgrf_airport.h:108
Station
Station data structure.
Definition: station_base.h:442
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
AirportSpec::name
StringID name
name of this airport
Definition: newgrf_airport.h:113
APC_HUB
@ APC_HUB
id for hub airports class
Definition: newgrf_airport.h:74
AirportSpec::noise_level
byte noise_level
noise that this airport generates
Definition: newgrf_airport.h:109
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
AirportScopeResolver::st
struct Station * st
Station of the airport for which the callback is run, or nullptr for build gui.
Definition: newgrf_airport.h:150
AirportScopeResolver::airport_id
byte airport_id
Type of airport for which the callback is run.
Definition: newgrf_airport.h:151
AirportScopeResolver::layout
byte layout
Layout of the airport to build.
Definition: newgrf_airport.h:152
AirportSpec::min_year
TimerGameCalendar::Year min_year
first year the airport is available
Definition: newgrf_airport.h:111
AirportSpec::max_year
TimerGameCalendar::Year max_year
last year the airport is available
Definition: newgrf_airport.h:112
AirportSpec::ResetAirports
static void ResetAirports()
This function initializes the airportspec array.
Definition: newgrf_airport.cpp:110
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition: newgrf_spritegroup.h:101
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition: newgrf_spritegroup.h:288
AirportSpec
Defines the data structure for an airport.
Definition: newgrf_airport.h:100
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:100
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
AirportResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0) override
Get a resolver for the scope.
Definition: newgrf_airport.h:184
AirportSpec::rotation
const Direction * rotation
the rotation of each tiletable
Definition: newgrf_airport.h:103
ToTileIndexDiff
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition: map_func.h:452
GetAirportTextCallback
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16_t callback)
Get a custom text for the airport.
Definition: newgrf_airport.cpp:273
AirportSpec::Get
static const AirportSpec * Get(byte type)
Retrieve airport spec for the given airport.
Definition: newgrf_airport.cpp:54
AirportScopeResolver::AirportScopeResolver
AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, byte airport_id, byte layout)
Constructor of the scope resolver for an airport.
Definition: newgrf_airport.h:163
AirportSpec::cls_id
AirportClassID cls_id
the class to which this airport type belongs
Definition: newgrf_airport.h:115
AirportClass
NewGRFClass< AirportSpec, AirportClassID, APC_MAX > AirportClass
Information related to airport classes.
Definition: newgrf_airport.h:144
AirportSpec::fsm
const struct AirportFTAClass * fsm
the finite statemachine for the default airports
Definition: newgrf_airport.h:101
AirportSpec::num_table
byte num_table
number of elements in the table
Definition: newgrf_airport.h:104
AirportTileTable::gfx
StationGfx gfx
AirportTile to use for this tile.
Definition: newgrf_airport.h:27
TileIterator
Base class for tile iterators.
Definition: tilearea_type.h:105
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:22
AirportTileTableIterator::Clone
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
Definition: newgrf_airport.h:63
AirportSpec::GetIndex
byte GetIndex() const
Get the index of this spec.
Definition: newgrf_airport.h:131
AirportResolverObject::AirportResolverObject
AirportResolverObject(TileIndex tile, Station *st, byte airport_id, byte layout, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Constructor of the airport resolver.
Definition: newgrf_airport.cpp:244
GRFFileProps
Data related to the handling of grf files.
Definition: newgrf_commons.h:324
AirportTileTableIterator::att
const AirportTileTable * att
The offsets.
Definition: newgrf_airport.h:33
AirportTileTableIterator
Iterator to iterate over all tiles belonging to an airport spec.
Definition: newgrf_airport.h:31
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:20
AirportSpec::ttd_airport_type
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Definition: newgrf_airport.h:114
NUM_AIRPORTS
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition: airport.h:41
AirportSpec::maintenance_cost
uint16_t maintenance_cost
maintenance cost multiplier
Definition: newgrf_airport.h:117
TTDPAirportType
TTDPAirportType
Allow incrementing of AirportClassID variables.
Definition: newgrf_airport.h:83
BindAirportSpecs
void BindAirportSpecs()
Tie all airportspecs to their class.
Definition: newgrf_airport.cpp:123
AirportResolverObject
Resolver object for airports.
Definition: newgrf_airport.h:175
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
Definition: newgrf_spritegroup.cpp:135
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition: airport.h:143
AirportSpec::dummy
static const AirportSpec dummy
The dummy airport.
Definition: newgrf_airport.h:137
AirportTileTable
Tile-offset / AirportTileID pair.
Definition: newgrf_airport.h:25
APC_HELIPORT
@ APC_HELIPORT
id for heliports
Definition: newgrf_airport.h:75
AirportSpec::specs
static AirportSpec specs[NUM_AIRPORTS]
Specs of the airports.
Definition: newgrf_airport.h:140
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
HangarTileTable::dir
Direction dir
Direction of the exit.
Definition: newgrf_airport.h:93
AirportSpec::IsAvailable
bool IsAvailable() const
Check whether this airport is available to build.
Definition: newgrf_airport.cpp:81
AirportSpec::size_x
byte size_x
size of airport in x direction
Definition: newgrf_airport.h:107
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:31
newgrf_spritegroup.h
AirportTileTableIterator::operator++
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
Definition: newgrf_airport.h:46
newgrf_town.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
AirportScopeResolver
Resolver for the airport scope.
Definition: newgrf_airport.h:149
tilearea_type.h
HangarTileTable::ti
TileIndexDiffC ti
Tile offset from the top-most airport tile.
Definition: newgrf_airport.h:92
AirportSpec::enabled
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
Definition: newgrf_airport.h:119
AirportSpec::preview_sprite
SpriteID preview_sprite
preview sprite for this airport
Definition: newgrf_airport.h:116
ResolverObject::callback_param2
uint32_t callback_param2
Second parameter (var 18) of the callback.
Definition: newgrf_spritegroup.h:327
AirportClassID
AirportClassID
List of default airport classes.
Definition: newgrf_airport.h:70
ATP_TTDP_HELIPORT
@ ATP_TTDP_HELIPORT
Same as AT_HELIPORT.
Definition: newgrf_airport.h:86
APC_LARGE
@ APC_LARGE
id for large airports class
Definition: newgrf_airport.h:73
newgrf_class.h
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:308
AirportSpec::grf_prop
struct GRFFileProps grf_prop
Properties related to the grf file.
Definition: newgrf_airport.h:120
APC_MAX
@ APC_MAX
maximum number of airport classes
Definition: newgrf_airport.h:76
APC_SMALL
@ APC_SMALL
id for small airports class
Definition: newgrf_airport.h:72
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition: newgrf_spritegroup.h:325
ResolverObject::callback_param1
uint32_t callback_param1
First parameter (var 10) of the callback.
Definition: newgrf_spritegroup.h:326
AirportResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_airport.cpp:183
AirportSpec::GetWithoutOverride
static AirportSpec * GetWithoutOverride(byte type)
Retrieve airport spec for the given airport.
Definition: newgrf_airport.cpp:74
AirportScopeResolver::GetVariable
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
Get a variable value.
Definition: newgrf_airport.cpp:156
AirportTileTableIterator::AirportTileTableIterator
AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile)
Construct the iterator.
Definition: newgrf_airport.h:42
AirportSpec::depot_table
const HangarTileTable * depot_table
gives the position of the depots on the airports
Definition: newgrf_airport.h:105
HangarTileTable::hangar_num
byte hangar_num
The hangar to which this tile belongs.
Definition: newgrf_airport.h:94
ATP_TTDP_SMALL
@ ATP_TTDP_SMALL
Same as AT_SMALL.
Definition: newgrf_airport.h:84
ATP_TTDP_LARGE
@ ATP_TTDP_LARGE
Same as AT_LARGE.
Definition: newgrf_airport.h:85
ATP_TTDP_OILRIG
@ ATP_TTDP_OILRIG
Same as AT_OILRIG.
Definition: newgrf_airport.h:87
airport.h
AirportResolverObject::town_scope
std::unique_ptr< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
Definition: newgrf_airport.h:177
AirportSpec::nof_depots
byte nof_depots
the number of hangar tiles in this airport
Definition: newgrf_airport.h:106
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
AirportTileTable::ti
TileIndexDiffC ti
Tile offset from the top-most airport tile.
Definition: newgrf_airport.h:26
AirportSpec::table
const AirportTileTable *const * table
list of the tiles composing the airport
Definition: newgrf_airport.h:102
HangarTileTable
A list of all hangar tiles in an airport.
Definition: newgrf_airport.h:91
APC_BEGIN
@ APC_BEGIN
Lowest valid airport class id.
Definition: newgrf_airport.h:71
AirportResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
Definition: newgrf_airport.cpp:219
TileIndexDiffC::x
int16_t x
The x value of the coordinate.
Definition: map_type.h:32
AirportSpec::catchment
byte catchment
catchment area of this airport
Definition: newgrf_airport.h:110
AirportScopeResolver::StorePSA
void StorePSA(uint pos, int32_t value) override
Store a value into the object's persistent storage.
Definition: newgrf_airport.cpp:198
AirportScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition: newgrf_airport.cpp:188
AirportScopeResolver::tile
TileIndex tile
Tile for the callback, only valid for airporttile callbacks.
Definition: newgrf_airport.h:153