OpenTTD Source: src/newgrf_airport.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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_badge_type.h"
16#include "newgrf_class.h"
17#include "newgrf_commons.h"
18#include "newgrf_spritegroup.h"
19#include "newgrf_town.h"
20#include "tilearea_type.h"
21
23 typedef uint8_t StationGfx;
24
26 struct AirportTileTable {
27 TileIndexDiffC ti;
28 StationGfx gfx;
29};
30
32 class AirportTileTableIterator : public TileIterator {
33private:
34 std::span<const AirportTileTable> att;
35 TileIndex base_tile;
36 std::span<const AirportTileTable>::iterator iter;
37
38public:
44 AirportTileTableIterator(std::span<const AirportTileTable> att, TileIndex base_tile)
45 : TileIterator(base_tile + ToTileIndexDiff(att.front().ti))
46 , att(att), base_tile(base_tile), iter(att.begin())
47 {
48 }
49
50 inline TileIterator& operator ++() override
51 {
52 ++this->iter;
53 if (this->iter == std::end(att)) {
54 this->tile = INVALID_TILE;
55 } else {
56 this->tile = this->base_tile + ToTileIndexDiff(this->iter->ti);
57 }
58 return *this;
59 }
60
62 StationGfx GetStationGfx() const
63 {
64 return this->iter->gfx;
65 }
66
67 std::unique_ptr<TileIterator> Clone() const override
68 {
69 return std::make_unique<AirportTileTableIterator>(*this);
70 }
71};
72
74 enum AirportClassID : uint8_t {
75 APC_BEGIN = 0,
76 APC_SMALL = 0,
77 APC_LARGE,
78 APC_HUB,
79 APC_HELIPORT,
80 APC_MAX = 16,
81};
82
84 DECLARE_INCREMENT_DECREMENT_OPERATORS(AirportClassID)
85
86
87enum TTDPAirportType : uint8_t {
88 ATP_TTDP_SMALL,
89 ATP_TTDP_LARGE,
90 ATP_TTDP_HELIPORT,
91 ATP_TTDP_OILRIG,
92};
93
95 struct HangarTileTable {
96 TileIndexDiffC ti;
97 Direction dir;
98 uint8_t hangar_num;
99};
100
101 struct AirportTileLayout {
102 std::vector<AirportTileTable> tiles;
103 Direction rotation;
104};
105
109 struct AirportSpec : NewGRFSpecBase<AirportClassID> {
110 const struct AirportFTAClass *fsm;
111 std::vector<AirportTileLayout> layouts;
112 std::span<const HangarTileTable> depots;
113 uint8_t size_x;
114 uint8_t size_y;
115 uint8_t noise_level;
116 uint8_t catchment;
117 TimerGameCalendar::Year min_year;
118 TimerGameCalendar::Year max_year;
119 StringID name;
120 TTDPAirportType ttd_airport_type;
121 SpriteID preview_sprite;
122 uint16_t maintenance_cost;
123 /* Newgrf data */
124 bool enabled;
125 SubstituteGRFFileProps grf_prop;
126 std::vector<BadgeID> badges;
127
128 static const AirportSpec *Get(uint8_t type);
129 static AirportSpec *GetWithoutOverride(uint8_t type);
130
131 bool IsAvailable() const;
132 bool IsWithinMapBounds(uint8_t table, TileIndex index) const;
133
134 static void ResetAirports();
135
137 uint8_t GetIndex() const
138 {
139 assert(this >= std::begin(specs) && this < std::end(specs));
140 return static_cast<uint8_t>(std::distance(std::cbegin(specs), this));
141 }
142
143 static const AirportSpec dummy;
144
145private:
146 static AirportSpec specs[NUM_AIRPORTS];
147
148 friend void AirportOverrideManager::SetEntitySpec(AirportSpec &&as);
149};
150
152 using AirportClass = NewGRFClass<AirportSpec, AirportClassID, APC_MAX>;
153
154void BindAirportSpecs();
155
157 struct AirportScopeResolver : public ScopeResolver {
158 struct Station *st;
159 const AirportSpec *spec;
160 uint8_t layout;
161 TileIndex tile;
162
171 AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, const AirportSpec *spec, uint8_t layout)
172 : ScopeResolver(ro), st(st), spec(spec), layout(layout), tile(tile)
173 {
174 }
175
176 uint32_t GetRandomBits() const override;
177 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
178 void StorePSA(uint pos, int32_t value) override;
179};
180
181
183 struct AirportResolverObject : public ResolverObject {
184 AirportScopeResolver airport_scope;
185 std::optional<TownScopeResolver> town_scope = std::nullopt;
186
187 AirportResolverObject(TileIndex tile, Station *st, const AirportSpec *spec, uint8_t layout,
188 CallbackID callback = CBID_NO_CALLBACK, uint32_t callback_param1 = 0, uint32_t callback_param2 = 0);
189
190 TownScopeResolver *GetTown();
191
192 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
193 {
194 switch (scope) {
195 case VSG_SCOPE_SELF: return &this->airport_scope;
196 case VSG_SCOPE_PARENT:
197 {
198 TownScopeResolver *tsr = this->GetTown();
199 if (tsr != nullptr) return tsr;
200 [[fallthrough]];
201 }
202 default: return ResolverObject::GetScope(scope, relative);
203 }
204 }
205
206 GrfSpecFeature GetFeature() const override;
207 uint32_t GetDebugID() const override;
208};
209
210 StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback);
211
212#endif /* NEWGRF_AIRPORT_H */
airport.h
Various declarations for airports.
NUM_AIRPORTS
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition airport.h:41
AirportTileTableIterator
Iterator to iterate over all tiles belonging to an airport spec.
Definition newgrf_airport.h:32
AirportTileTableIterator::base_tile
TileIndex base_tile
The tile we base the offsets off.
Definition newgrf_airport.h:35
AirportTileTableIterator::att
std::span< const AirportTileTable > att
The offsets.
Definition newgrf_airport.h:34
AirportTileTableIterator::AirportTileTableIterator
AirportTileTableIterator(std::span< const AirportTileTable > att, TileIndex base_tile)
Construct the iterator.
Definition newgrf_airport.h:44
AirportTileTableIterator::GetStationGfx
StationGfx GetStationGfx() const
Get the StationGfx for the current tile.
Definition newgrf_airport.h:62
AirportTileTableIterator::operator++
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
Definition newgrf_airport.h:50
AirportTileTableIterator::Clone
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
Definition newgrf_airport.h:67
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition newgrf_class.h:26
TileIterator
Base class for tile iterators.
Definition tilearea_type.h:105
TileIterator::tile
TileIndex tile
The current tile we are at.
Definition tilearea_type.h:107
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
DECLARE_INCREMENT_DECREMENT_OPERATORS
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:63
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
ToTileIndexDiff
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition map_func.h:452
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
AirportClassID
AirportClassID
List of default airport classes.
Definition newgrf_airport.h:74
APC_MAX
@ APC_MAX
maximum number of airport classes
Definition newgrf_airport.h:80
APC_HELIPORT
@ APC_HELIPORT
id for heliports
Definition newgrf_airport.h:79
APC_SMALL
@ APC_SMALL
id for small airports class
Definition newgrf_airport.h:76
APC_BEGIN
@ APC_BEGIN
Lowest valid airport class id.
Definition newgrf_airport.h:75
APC_LARGE
@ APC_LARGE
id for large airports class
Definition newgrf_airport.h:77
APC_HUB
@ APC_HUB
id for hub airports class
Definition newgrf_airport.h:78
BindAirportSpecs
void BindAirportSpecs()
Tie all airportspecs to their class.
Definition newgrf_airport.cpp:128
TTDPAirportType
TTDPAirportType
Allow incrementing of AirportClassID variables.
Definition newgrf_airport.h:87
ATP_TTDP_HELIPORT
@ ATP_TTDP_HELIPORT
Same as AT_HELIPORT.
Definition newgrf_airport.h:90
ATP_TTDP_OILRIG
@ ATP_TTDP_OILRIG
Same as AT_OILRIG.
Definition newgrf_airport.h:91
ATP_TTDP_SMALL
@ ATP_TTDP_SMALL
Same as AT_SMALL.
Definition newgrf_airport.h:88
ATP_TTDP_LARGE
@ ATP_TTDP_LARGE
Same as AT_LARGE.
Definition newgrf_airport.h:89
StationGfx
uint8_t StationGfx
Copy from station_map.h.
Definition newgrf_airport.h:23
GetAirportTextCallback
StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback)
Get a custom text for the airport.
Definition newgrf_airport.cpp:280
newgrf_badge_type.h
Types related to NewGRF badges.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition newgrf_callbacks.h:24
newgrf_class.h
Header file for classes to be used by e.g.
newgrf_commons.h
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
newgrf_spritegroup.h
Action 2 handling.
VarSpriteGroupScope
VarSpriteGroupScope
Definition newgrf_spritegroup.h:82
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition newgrf_spritegroup.h:85
VSG_SCOPE_PARENT
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Definition newgrf_spritegroup.h:86
newgrf_town.h
Functions to handle the town part of NewGRF towns.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition airport.h:159
AirportResolverObject
Resolver object for airports.
Definition newgrf_airport.h:183
AirportResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_airport.cpp:185
AirportResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
Definition newgrf_airport.cpp:226
AirportResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
Definition newgrf_airport.h:192
AirportResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_airport.cpp:190
AirportResolverObject::town_scope
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
Definition newgrf_airport.h:185
AirportScopeResolver
Resolver for the airport scope.
Definition newgrf_airport.h:157
AirportScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_airport.cpp:195
AirportScopeResolver::spec
const AirportSpec * spec
AirportSpec for which the callback is run.
Definition newgrf_airport.h:159
AirportScopeResolver::layout
uint8_t layout
Layout of the airport to build.
Definition newgrf_airport.h:160
AirportScopeResolver::StorePSA
void StorePSA(uint pos, int32_t value) override
Store a value into the object's persistent storage.
Definition newgrf_airport.cpp:205
AirportScopeResolver::tile
TileIndex tile
Tile for the callback, only valid for airporttile callbacks.
Definition newgrf_airport.h:161
AirportScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Definition newgrf_airport.cpp:161
AirportScopeResolver::st
struct Station * st
Station of the airport for which the callback is run, or nullptr for build gui.
Definition newgrf_airport.h:158
AirportScopeResolver::AirportScopeResolver
AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, const AirportSpec *spec, uint8_t layout)
Constructor of the scope resolver for an airport.
Definition newgrf_airport.h:171
AirportSpec
Defines the data structure for an airport.
Definition newgrf_airport.h:109
AirportSpec::name
StringID name
name of this airport
Definition newgrf_airport.h:119
AirportSpec::grf_prop
SubstituteGRFFileProps grf_prop
Properties related to the grf file.
Definition newgrf_airport.h:125
AirportSpec::ttd_airport_type
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Definition newgrf_airport.h:120
AirportSpec::preview_sprite
SpriteID preview_sprite
preview sprite for this airport
Definition newgrf_airport.h:121
AirportSpec::min_year
TimerGameCalendar::Year min_year
first year the airport is available
Definition newgrf_airport.h:117
AirportSpec::ResetAirports
static void ResetAirports()
This function initializes the airportspec array.
Definition newgrf_airport.cpp:115
AirportSpec::layouts
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
Definition newgrf_airport.h:111
AirportSpec::specs
static AirportSpec specs[NUM_AIRPORTS]
Specs of the airports.
Definition newgrf_airport.h:146
AirportSpec::catchment
uint8_t catchment
catchment area of this airport
Definition newgrf_airport.h:116
AirportSpec::dummy
static const AirportSpec dummy
The dummy airport.
Definition newgrf_airport.h:143
AirportSpec::maintenance_cost
uint16_t maintenance_cost
maintenance cost multiplier
Definition newgrf_airport.h:122
AirportSpec::IsWithinMapBounds
bool IsWithinMapBounds(uint8_t table, TileIndex index) const
Check if the airport would be within the map bounds at the given tile.
Definition newgrf_airport.cpp:100
AirportSpec::GetWithoutOverride
static AirportSpec * GetWithoutOverride(uint8_t type)
Retrieve airport spec for the given airport.
Definition newgrf_airport.cpp:79
AirportSpec::fsm
const struct AirportFTAClass * fsm
the finite statemachine for the default airports
Definition newgrf_airport.h:110
AirportSpec::max_year
TimerGameCalendar::Year max_year
last year the airport is available
Definition newgrf_airport.h:118
AirportSpec::enabled
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
Definition newgrf_airport.h:124
AirportSpec::size_y
uint8_t size_y
size of airport in y direction
Definition newgrf_airport.h:114
AirportSpec::size_x
uint8_t size_x
size of airport in x direction
Definition newgrf_airport.h:113
AirportSpec::Get
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
Definition newgrf_airport.cpp:59
AirportSpec::depots
std::span< const HangarTileTable > depots
Position of the depots on the airports.
Definition newgrf_airport.h:112
AirportSpec::GetIndex
uint8_t GetIndex() const
Get the index of this spec.
Definition newgrf_airport.h:137
AirportSpec::IsAvailable
bool IsAvailable() const
Check whether this airport is available to build.
Definition newgrf_airport.cpp:86
AirportSpec::noise_level
uint8_t noise_level
noise that this airport generates
Definition newgrf_airport.h:115
AirportTileLayout
Definition newgrf_airport.h:101
AirportTileLayout::tiles
std::vector< AirportTileTable > tiles
List of all tiles in this layout.
Definition newgrf_airport.h:102
AirportTileLayout::rotation
Direction rotation
The rotation of this layout.
Definition newgrf_airport.h:103
AirportTileTable
Tile-offset / AirportTileID pair.
Definition newgrf_airport.h:26
AirportTileTable::gfx
StationGfx gfx
AirportTile to use for this tile.
Definition newgrf_airport.h:28
AirportTileTable::ti
TileIndexDiffC ti
Tile offset from the top-most airport tile.
Definition newgrf_airport.h:27
HangarTileTable
A list of all hangar tiles in an airport.
Definition newgrf_airport.h:95
HangarTileTable::dir
Direction dir
Direction of the exit.
Definition newgrf_airport.h:97
HangarTileTable::ti
TileIndexDiffC ti
Tile offset from the top-most airport tile.
Definition newgrf_airport.h:96
HangarTileTable::hangar_num
uint8_t hangar_num
The hangar to which this tile belongs.
Definition newgrf_airport.h:98
NewGRFSpecBase
Definition newgrf_class.h:17
NewGRFSpecBase< AirportClassID >::index
uint16_t index
Index within class of this spec, invalid until inserted into class.
Definition newgrf_class.h:19
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
ResolverObject::callback_param2
uint32_t callback_param2
Second parameter (var 18) of the callback.
Definition newgrf_spritegroup.h:342
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition newgrf_spritegroup.h:340
ResolverObject::callback_param1
uint32_t callback_param1
First parameter (var 10) of the callback.
Definition newgrf_spritegroup.h:341
ResolverObject::GetScope
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Definition newgrf_spritegroup.cpp:133
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition newgrf_spritegroup.h:269
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:270
Station
Station data structure.
Definition station_base.h:500
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
SubstituteGRFFileProps
NewGRF entities which can replace default entities.
Definition newgrf_commons.h:464
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition map_type.h:31
TownScopeResolver
Scope resolver for a town.
Definition newgrf_town.h:22
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
tilearea_type.h
Type for storing the 'area' of something uses on the map.
timer_game_calendar.h
Definition of the game-calendar-timer.