OpenTTD Source 20260311-master-g511d3794ce
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
9
10#ifndef NEWGRF_AIRPORT_H
11#define NEWGRF_AIRPORT_H
12
13#include "airport.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
23typedef uint8_t StationGfx;
24
30
33private:
34 std::span<const AirportTileTable> att;
36 std::span<const AirportTileTable>::iterator iter;
37
38public:
44 AirportTileTableIterator(std::span<const AirportTileTable> att, TileIndex base_tile)
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
66 {
67 return this->iter->gfx;
68 }
69
70 std::unique_ptr<TileIterator> Clone() const override
71 {
72 return std::make_unique<AirportTileTableIterator>(*this);
73 }
74};
75
78
79static constexpr AirportClassID APC_SMALL{0};
80static constexpr AirportClassID APC_LARGE{1};
81static constexpr AirportClassID APC_HUB{2};
82static constexpr AirportClassID APC_HELIPORT{3};
83
91
98
100 std::vector<AirportTileTable> tiles;
102};
103
107struct AirportSpec : NewGRFSpecBase<AirportClassID> {
108 const struct AirportFTAClass *fsm;
109 std::vector<AirportTileLayout> layouts;
110 std::span<const HangarTileTable> depots;
111 uint8_t size_x;
112 uint8_t size_y;
113 uint8_t noise_level;
114 uint8_t catchment;
115 TimerGameCalendar::Year min_year;
116 TimerGameCalendar::Year max_year;
121 /* Newgrf data */
122 bool enabled;
124 std::vector<BadgeID> badges;
125
126 static const AirportSpec *Get(uint8_t type);
127 static AirportSpec *GetWithoutOverride(uint8_t type);
128
129 bool IsAvailable() const;
130 bool IsWithinMapBounds(uint8_t table, TileIndex index) const;
131
132 static void ResetAirports();
133
138 uint8_t GetIndex() const
139 {
140 assert(this >= std::begin(specs) && this < std::end(specs));
141 return static_cast<uint8_t>(std::distance(std::cbegin(specs), this));
142 }
143
144 static const AirportSpec dummy;
145
146private:
148
149 friend void AirportOverrideManager::SetEntitySpec(AirportSpec &&as);
150};
151
154
155void BindAirportSpecs();
156
158struct AirportScopeResolver : public ScopeResolver {
159 struct Station *st;
161 uint8_t layout;
163
173 : ScopeResolver(ro), st(st), spec(spec), layout(layout), tile(tile)
174 {
175 }
176
177 uint32_t GetRandomBits() const override;
178 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
179 void StorePSA(uint pos, int32_t value) override;
180};
181
182
185 AirportScopeResolver airport_scope;
186 std::optional<TownScopeResolver> town_scope = std::nullopt;
187
188 AirportResolverObject(TileIndex tile, Station *st, const AirportSpec *spec, uint8_t layout,
190
192
193 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override
194 {
195 switch (scope) {
196 case VSG_SCOPE_SELF: return &this->airport_scope;
197 case VSG_SCOPE_PARENT:
198 {
199 TownScopeResolver *tsr = this->GetTown();
200 if (tsr != nullptr) return tsr;
201 [[fallthrough]];
202 }
203 default: return ResolverObject::GetScope(scope, relative);
204 }
205 }
206
207 GrfSpecFeature GetFeature() const override;
208 uint32_t GetDebugID() const override;
209};
210
211StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback);
212
213#endif /* NEWGRF_AIRPORT_H */
Various declarations for airports.
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition airport.h:41
TileIndex base_tile
The tile we base the offsets off.
std::span< const AirportTileTable > att
The offsets.
AirportTileTableIterator(std::span< const AirportTileTable > att, TileIndex base_tile)
Construct the iterator.
StationGfx GetStationGfx() const
Get the StationGfx for the current tile.
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
Struct containing information relating to NewGRF classes for stations and airports.
TileIterator(TileIndex tile=INVALID_TILE)
Initialise the iterator starting at this tile.
TileIndex tile
The current tile we are at.
Direction
Defines the 8 directions on the map.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition map_func.h:444
GrfSpecFeature
Definition newgrf.h:71
static constexpr AirportClassID APC_HUB
id for hub airports class.
static constexpr AirportClassID APC_LARGE
id for large airports class.
void BindAirportSpecs()
Tie all airportspecs to their class.
PoolID< uint8_t, struct AirportClassIDTag, 16, UINT8_MAX > AirportClassID
Class IDs for airports.
static constexpr AirportClassID APC_SMALL
id for small airports class.
NewGRFClass< AirportSpec, AirportClassID > AirportClass
Information related to airport classes.
TTDPAirportType
TTDP airport types.
@ ATP_TTDP_HELIPORT
Same as AT_HELIPORT.
@ ATP_TTDP_OILRIG
Same as AT_OILRIG.
@ ATP_TTDP_SMALL
Same as AT_SMALL.
@ ATP_TTDP_LARGE
Same as AT_LARGE.
uint8_t StationGfx
Copy from station_map.h.
static constexpr AirportClassID APC_HELIPORT
id for heliports.
StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback)
Get a custom text for the airport.
Types related to NewGRF badges.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Header file for classes to be used by for example, NewGRF stations and airports.
This file simplifies and embeds a common mechanism of loading/saving and mapping of grf entities.
Action 2 handling.
VarSpriteGroupScope
Shared by deterministic and random groups.
@ VSG_SCOPE_SELF
Resolved object itself.
@ VSG_SCOPE_PARENT
Related object of the resolved one.
Functions to handle the town part of NewGRF towns.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Finite sTate mAchine (FTA) of an airport.
Definition airport.h:158
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
AirportResolverObject(TileIndex tile, Station *st, const AirportSpec *spec, uint8_t layout, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Constructor of the airport resolver.
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
Resolver for the airport scope.
uint32_t GetRandomBits() const override
Get a few random bits.
const AirportSpec * spec
AirportSpec for which the callback is run.
uint8_t layout
Layout of the airport to build.
void StorePSA(uint pos, int32_t value) override
Store a value into the object's persistent storage.
TileIndex tile
Tile for the callback, only valid for airporttile callbacks.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
struct Station * st
Station of the airport for which the callback is run, or nullptr for build gui.
AirportScopeResolver(ResolverObject &ro, TileIndex tile, Station *st, const AirportSpec *spec, uint8_t layout)
Constructor of the scope resolver for an airport.
Defines the data structure for an airport.
StringID name
name of this airport
SubstituteGRFFileProps grf_prop
Properties related to the grf file.
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
SpriteID preview_sprite
preview sprite for this airport
TimerGameCalendar::Year min_year
first year the airport is available
static void ResetAirports()
This function initializes the airportspec array.
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
static AirportSpec specs[NUM_AIRPORTS]
Specs of the airports.
uint8_t catchment
catchment area of this airport
static const AirportSpec dummy
The dummy airport.
uint16_t maintenance_cost
maintenance cost multiplier
bool IsWithinMapBounds(uint8_t table, TileIndex index) const
Check if the airport would be within the map bounds at the given tile.
static AirportSpec * GetWithoutOverride(uint8_t type)
Retrieve airport spec for the given airport.
const struct AirportFTAClass * fsm
the finite statemachine for the default airports
TimerGameCalendar::Year max_year
last year the airport is available
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
uint8_t size_y
size of airport in y direction
uint8_t size_x
size of airport in x direction
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
std::span< const HangarTileTable > depots
Position of the depots on the airports.
uint8_t GetIndex() const
Get the index of this spec.
bool IsAvailable() const
Check whether this airport is available to build.
uint8_t noise_level
noise that this airport generates
std::vector< AirportTileTable > tiles
List of all tiles in this layout.
Direction rotation
The rotation of this layout.
Tile-offset / AirportTileID pair.
StationGfx gfx
AirportTile to use for this tile.
TileIndexDiffC ti
Tile offset from the top-most airport tile.
A list of all hangar tiles in an airport.
Direction dir
Direction of the exit.
TileIndexDiffC ti
Tile offset from the top-most airport tile.
uint8_t hangar_num
The hangar to which this tile belongs.
Base for each type of NewGRF spec to be used with NewGRFClass.
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:47
Interface for SpriteGroup-s to access the gamestate.
uint32_t callback_param2
Second parameter (var 18) of the callback.
ResolverObject(const GRFFile *grffile, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Resolver constructor.
CallbackID callback
Callback being resolved.
uint32_t callback_param1
First parameter (var 10) of the callback.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0)
Get a resolver for the scope.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
Station data structure.
NewGRF entities which can replace default entities.
A pair-construct of a TileIndexDiff.
Definition map_type.h:31
Scope resolver for a town.
Definition newgrf_town.h:22
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
Type for storing the 'area' of something uses on the map.
Definition of the game-calendar-timer.