12#include "../newgrf_airporttiles.h"
13#include "../newgrf_airport.h"
18#include "../safeguards.h"
33 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", last,
NUM_AIRPORTS_PER_GRF);
38 if (_cur_gps.
grffile->airportspec.size() < last) _cur_gps.
grffile->airportspec.resize(last);
40 for (uint
id = first;
id < last; ++id) {
41 auto &as = _cur_gps.
grffile->airportspec[id];
43 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
44 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring",
id);
51 if (subs_id == 0xFF) {
58 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id,
id);
69 as->grf_prop.local_id = id;
70 as->grf_prop.subst_id = subs_id;
71 as->grf_prop.SetGRFFile(_cur_gps.
grffile);
73 _airport_mngr.
Add(
id, _cur_gps.
grffile->grfid, subs_id);
79 uint8_t num_layouts = buf.
ReadByte();
84 std::vector<AirportTileLayout> layouts;
85 layouts.reserve(num_layouts);
87 for (uint8_t j = 0; j != num_layouts; ++j) {
88 auto &layout = layouts.emplace_back();
92 auto &tile = layout.tiles.emplace_back();
95 if (tile.ti.x == 0 && tile.ti.y == 0x80) {
97 layout.tiles.pop_back();
103 if (tile.gfx == 0xFE) {
108 uint16_t tempid = _airporttile_mngr.
GetID(local_tile_id, _cur_gps.
grffile->grfid);
111 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id,
id);
116 }
else if (tile.gfx == 0xFF) {
117 tile.ti.x =
static_cast<int8_t
>(
GB(tile.ti.x, 0, 8));
118 tile.ti.y =
static_cast<int8_t
>(
GB(tile.ti.y, 0, 8));
122 if (layout.rotation ==
DIR_E || layout.rotation ==
DIR_W) {
123 size_x = std::max<uint8_t>(size_x, tile.ti.y + 1);
124 size_y = std::max<uint8_t>(size_y, tile.ti.x + 1);
126 size_x = std::max<uint8_t>(size_x, tile.ti.x + 1);
127 size_y = std::max<uint8_t>(size_y, tile.ti.y + 1);
131 as->layouts = std::move(layouts);
160 as->maintenance_cost = buf.
ReadWord();
181 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", last,
NUM_AIRPORTTILES_PER_GRF);
186 if (_cur_gps.
grffile->airtspec.size() < last) _cur_gps.
grffile->airtspec.resize(last);
188 for (uint
id = first;
id < last; ++id) {
189 auto &tsp = _cur_gps.
grffile->airtspec[id];
191 if (prop != 0x08 && tsp ==
nullptr) {
192 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.",
id);
201 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id,
id);
206 if (tsp ==
nullptr) {
213 tsp->grf_prop.local_id = id;
214 tsp->grf_prop.subst_id = subs_id;
215 tsp->grf_prop.SetGRFFile(_cur_gps.
grffile);
222 uint8_t override_id = buf.
ReadByte();
226 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.", override_id,
id);
230 _airporttile_mngr.
Add(
id, _cur_gps.
grffile->grfid, override_id);
239 tsp->animation.frames = buf.
ReadByte();
244 tsp->animation.speed = buf.
ReadByte();
static const uint INVALID_AIRPORTTILE
id for an invalid airport tile
static const uint NEW_AIRPORTTILE_OFFSET
offset of first newgrf airport tile
static const uint NUM_AIRPORTTILES_PER_GRF
Number of airport tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte l...
@ NEW_AIRPORT_OFFSET
Number of the first newgrf airport.
@ NUM_AIRPORTS_PER_GRF
Maximal number of airports per NewGRF.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Class to read from a NewGRF file.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint16_t ReadWord()
Read a single Word (16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
void Add(uint16_t local_id, uint32_t grfid, uint entity_type)
Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game...
virtual uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id)
Reserves a place in the mapping array for an entity to be installed.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Direction
Defines the 8 directions on the map.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
std::vector< BadgeID > ReadBadgeList(ByteReader &buf, GrfSpecFeature feature)
Read a list of badges.
static ChangeInfoResult AirportChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for airports.
TTDPAirportType
Allow incrementing of AirportClassID variables.
AnimationStatus
Statuses of animation within NewGRFs.
NewGRF buffer reader definition.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
@ CIR_UNKNOWN
Variable is unknown.
@ CIR_UNHANDLED
Variable was parsed but unread.
@ CIR_SUCCESS
Variable was parsed and read.
void AddStringForMapping(GRFStringID source, std::function< void(StringID)> &&func)
Record a static StringID for getting translated later.
NewGRF string mapping definition.
static constexpr uint MAX_CATCHMENT
Maximum catchment for airports with "modified catchment" enabled.
static AirportSpec * GetWithoutOverride(uint8_t type)
Retrieve airport spec for the given airport.
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
static const AirportTileSpec * Get(StationGfx gfx)
Retrieve airport tile spec for the given airport tile.
GRFFile * grffile
Currently processed GRF file.
Templated helper to make a type-safe 'typedef' representing a single POD value.