27 const size_t size = layout.
tiles.size();
28 if (size == 0)
return false;
30 for (
size_t i = 0; i < size - 1; i++) {
31 for (
size_t j = i + 1; j < size; j++) {
32 if (layout.
tiles[i].ti.x == layout.
tiles[j].ti.x &&
33 layout.
tiles[i].ti.y == layout.
tiles[j].ti.y) {
55 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", last,
NUM_AIRPORTS_PER_GRF);
60 if (_cur_gps.grffile->airportspec.size() < last) _cur_gps.grffile->airportspec.resize(last);
62 for (uint
id = first;
id < last; ++id) {
63 auto &as = _cur_gps.grffile->airportspec[id];
65 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
66 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring",
id);
73 if (subs_id == 0xFF) {
80 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id,
id);
91 as->grf_prop.local_id = id;
92 as->grf_prop.subst_id = subs_id;
93 as->grf_prop.SetGRFFile(_cur_gps.grffile);
95 _airport_mngr.Add(
id, _cur_gps.grffile->grfid, subs_id);
101 uint8_t num_layouts = buf.
ReadByte();
102 size_t definition_size = buf.
ReadDWord();
103 size_t definition_end = definition_size + buf.
GetBytesRead();
107 std::vector<AirportTileLayout> layouts;
108 layouts.reserve(num_layouts);
112 for (uint8_t j = 0; j != num_layouts; ++j) {
113 bool invalid_layout =
false;
114 layout.
tiles.clear();
119 GrfMsg(3,
"AirportChangeInfo: Incorrect size for airport tile layout definition for airport {}.",
id);
121 definition_end = SIZE_MAX;
124 auto &tile = layout.
tiles.emplace_back();
127 if (tile.ti.x == 0 && tile.ti.y == 0x80) {
129 layout.
tiles.pop_back();
135 if (tile.gfx == 0xFE) {
140 uint16_t tempid = _airporttile_mngr.GetID(local_tile_id, _cur_gps.grffile->grfid);
143 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id,
id);
144 invalid_layout =
true;
149 }
else if (tile.gfx == 0xFF) {
150 tile.ti.x =
static_cast<int8_t
>(
GB(tile.ti.x, 0, 8));
151 tile.ti.y =
static_cast<int8_t
>(
GB(tile.ti.y, 0, 8));
153 GrfMsg(2,
"AirportChangeInfo: Attempt to use invalid airport tile {} with airport id {}. Ignoring.", tile.gfx,
id);
154 invalid_layout =
true;
159 size_x = std::max<uint8_t>(size_x, tile.ti.y + 1);
160 size_y = std::max<uint8_t>(size_y, tile.ti.x + 1);
162 size_x = std::max<uint8_t>(size_x, tile.ti.x + 1);
163 size_y = std::max<uint8_t>(size_y, tile.ti.y + 1);
167 if (invalid_layout)
continue;
171 GrfMsg(1,
"AirportChangeInfo: Invalid airport layout for airport id {}. Ignoring",
id);
173 layouts.push_back(layout);
176 as->layouts = std::move(layouts);
205 as->maintenance_cost = buf.
ReadWord();
226 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", last,
NUM_AIRPORTTILES_PER_GRF);
231 if (_cur_gps.grffile->airtspec.size() < last) _cur_gps.grffile->airtspec.resize(last);
233 for (uint
id = first;
id < last; ++id) {
234 auto &tsp = _cur_gps.grffile->airtspec[id];
236 if (prop != 0x08 && tsp ==
nullptr) {
237 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.",
id);
246 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id,
id);
251 if (tsp ==
nullptr) {
258 tsp->grf_prop.local_id = id;
259 tsp->grf_prop.subst_id = subs_id;
260 tsp->grf_prop.SetGRFFile(_cur_gps.grffile);
261 _airporttile_mngr.AddEntityID(
id, _cur_gps.grffile->grfid, subs_id);
267 uint8_t override_id = buf.
ReadByte();
271 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.", override_id,
id);
275 _airporttile_mngr.Add(
id, _cur_gps.grffile->grfid, override_id);
284 tsp->animation.frames = buf.
ReadByte();
289 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).
size_t GetBytesRead() const
Get number of already read bytes.
uint8_t ReadByte()
Read a single byte (8 bits).
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
StrongType::Typedef< int32_t, struct YearTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Year
Functions related to debugging.
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.
@ TramTypes
Tram types feature.
@ Airports
Airports feature.
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.
static bool ValidateAirportLayout(const AirportTileLayout &layout)
Validate the airport layout; e.g.
NewGRF handling of airports.
TTDPAirportType
TTDP airport types.
NewGRF handling of airport tiles.
AnimationStatus
Statuses of animation within NewGRFs.
NewGRF buffer reader definition.
EnumBitSet< AirportTileCallbackMask, uint8_t > AirportTileCallbackMasks
Bitset of AirportTileCallbackMask elements.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ Success
Variable was parsed and read.
@ Unhandled
Variable was parsed but unread.
@ Unknown
Variable is unknown.
@ InvalidId
Attempt to modify an invalid ID.
void AddStringForMapping(GRFStringID source, std::function< void(StringID)> &&func)
Record a static StringID for getting translated later.
NewGRF string mapping definition.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
A number of safeguards to prevent using unsafe methods.
EnumBitSet< AirportAnimationTrigger, uint8_t > AirportAnimationTriggers
Bitset of AirportAnimationTrigger elements.
static constexpr uint MAX_CATCHMENT
Maximum catchment for airports with "modified catchment" enabled.
Definition of base types and functions in a cross-platform compatible way.
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.
std::vector< AirportTileTable > tiles
List of all tiles in this layout.
Direction rotation
The rotation of this layout.
static const AirportTileSpec * Get(StationGfx gfx)
Retrieve airport tile spec for the given airport tile.
static ChangeInfoResult Reserve(uint first, uint last, int prop, ByteReader &buf)
Implementation of the GrfLoadingStage::Reserve stage of this feature.
static ChangeInfoResult Activation(uint first, uint last, int prop, ByteReader &buf)
Implementation of the GrfLoadingStage::Activation stage of this feature.