OpenTTD Source 20260206-master-g4d4e37dbf1
newgrf_act3.cpp
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#include "../stdafx.h"
11
12#include "../debug.h"
13#include "../house.h"
14#include "../newgrf_engine.h"
15#include "../newgrf_badge.h"
17#include "../newgrf_cargo.h"
18#include "../newgrf_house.h"
19#include "../newgrf_station.h"
20#include "../industrytype.h"
21#include "../newgrf_canal.h"
23#include "../newgrf_airport.h"
24#include "../newgrf_object.h"
25#include "../error.h"
26#include "../vehicle_base.h"
27#include "../road.h"
28#include "../newgrf_roadstop.h"
29#include "newgrf_bytereader.h"
31#include "newgrf_internal.h"
32
33#include "../safeguards.h"
34
35
36static CargoType TranslateCargo(GrfSpecFeature feature, uint8_t ctype)
37{
38 /* Special cargo types for purchase list and stations */
39 if ((feature == GSF_STATIONS || feature == GSF_ROADSTOPS) && ctype == 0xFE) return CargoGRFFileProps::SG_DEFAULT_NA;
40 if (ctype == 0xFF) return CargoGRFFileProps::SG_PURCHASE;
41
42 auto cargo_list = GetCargoTranslationTable(*_cur_gps.grffile);
43
44 /* Check if the cargo type is out of bounds of the cargo translation table */
45 if (ctype >= cargo_list.size()) {
46 GrfMsg(1, "TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (unsigned int)_cur_gps.grffile->cargo_list.size() - 1);
47 return INVALID_CARGO;
48 }
49
50 /* Look up the cargo label from the translation table */
51 CargoLabel cl = cargo_list[ctype];
52 if (cl == CT_INVALID) {
53 GrfMsg(5, "TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
54 return INVALID_CARGO;
55 }
56
57 CargoType cargo_type = GetCargoTypeByLabel(cl);
58 if (!IsValidCargoType(cargo_type)) {
59 GrfMsg(5, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' unsupported, skipping.", GB(cl.base(), 24, 8), GB(cl.base(), 16, 8), GB(cl.base(), 8, 8), GB(cl.base(), 0, 8));
60 return INVALID_CARGO;
61 }
62
63 GrfMsg(6, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' mapped to cargo type {}.", GB(cl.base(), 24, 8), GB(cl.base(), 16, 8), GB(cl.base(), 8, 8), GB(cl.base(), 0, 8), cargo_type);
64 return cargo_type;
65}
66
67
68static bool IsValidGroupID(uint16_t groupid, std::string_view function)
69{
70 if (groupid > MAX_SPRITEGROUP || _cur_gps.spritegroups[groupid] == nullptr) {
71 GrfMsg(1, "{}: Spritegroup 0x{:04X} out of range or empty, skipping.", function, groupid);
72 return false;
73 }
74
75 return true;
76}
77
78static void VehicleMapSpriteGroup(ByteReader &buf, GrfSpecFeature feature, uint8_t idcount)
79{
80 static std::vector<EngineID> last_engines; // Engine IDs are remembered in case the next action is a wagon override.
81 bool wagover = false;
82
83 /* Test for 'wagon override' flag */
84 if (HasBit(idcount, 7)) {
85 wagover = true;
86 /* Strip off the flag */
87 idcount = GB(idcount, 0, 7);
88
89 if (last_engines.empty()) {
90 GrfMsg(0, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
91 return;
92 }
93
94 GrfMsg(6, "VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons", last_engines.size(), idcount);
95 } else {
96 last_engines.resize(idcount);
97 }
98
99 std::vector<EngineID> engines;
100 engines.reserve(idcount);
101 for (uint i = 0; i < idcount; i++) {
102 Engine *e = GetNewEngine(_cur_gps.grffile, (VehicleType)feature, buf.ReadExtendedByte());
103 if (e == nullptr) {
104 /* No engine could be allocated?!? Deal with it. Okay,
105 * this might look bad. Also make sure this NewGRF
106 * gets disabled, as a half loaded one is bad. */
107 HandleChangeInfoResult("VehicleMapSpriteGroup", CIR_INVALID_ID, feature, 0);
108 return;
109 }
110
111 engines.push_back(e->index);
112 if (!wagover) last_engines[i] = engines[i];
113 }
114
115 uint8_t cidcount = buf.ReadByte();
116 for (uint c = 0; c < cidcount; c++) {
117 uint8_t ctype = buf.ReadByte();
118 uint16_t groupid = buf.ReadWord();
119 if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) continue;
120
121 GrfMsg(8, "VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
122
123 CargoType cargo_type = TranslateCargo(feature, ctype);
124 if (!IsValidCargoType(cargo_type)) continue;
125
126 for (uint i = 0; i < idcount; i++) {
127 EngineID engine = engines[i];
128
129 GrfMsg(7, "VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
130
131 if (wagover) {
132 SetWagonOverrideSprites(engine, cargo_type, _cur_gps.spritegroups[groupid], last_engines);
133 } else {
134 SetCustomEngineSprites(engine, cargo_type, _cur_gps.spritegroups[groupid]);
135 }
136 }
137 }
138
139 uint16_t groupid = buf.ReadWord();
140 if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) return;
141
142 GrfMsg(8, "-- Default group id 0x{:04X}", groupid);
143
144 for (uint i = 0; i < idcount; i++) {
145 EngineID engine = engines[i];
146
147 if (wagover) {
148 SetWagonOverrideSprites(engine, CargoGRFFileProps::SG_DEFAULT, _cur_gps.spritegroups[groupid], last_engines);
149 } else {
150 SetCustomEngineSprites(engine, CargoGRFFileProps::SG_DEFAULT, _cur_gps.spritegroups[groupid]);
151 SetEngineGRF(engine, _cur_gps.grffile);
152 }
153 }
154}
155
158 virtual ~MapSpriteGroupHandler() = default;
159
166 virtual void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) = 0;
167
173 virtual void MapDefault(uint16_t local_id, const SpriteGroup *group) = 0;
174};
175
177template <typename T> static auto *GetSpec(GRFFile *, uint16_t);
178
180template <typename T>
182 void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
183 {
184 if (cid != 0xFF) {
185 GrfMsg(1, "MapSpriteGroup: Invalid cargo bitnum {}, skipping.", cid);
186 } else if (T *spec = GetSpec<T>(_cur_gps.grffile, local_id); spec == nullptr) {
187 GrfMsg(1, "MapSpriteGroup: {} undefined, skipping.", local_id);
188 } else {
189 spec->grf_prop.SetSpriteGroup(StandardSpriteGroup::Purchase, group);
190 }
191 }
192
193 void MapDefault(uint16_t local_id, const SpriteGroup *group) override
194 {
195 if (T *spec = GetSpec<T>(_cur_gps.grffile, local_id); spec == nullptr) {
196 GrfMsg(1, "MapSpriteGroup: {} undefined, skipping.", local_id);
197 } else {
198 spec->grf_prop.SetSpriteGroup(StandardSpriteGroup::Default, group);
199 spec->grf_prop.SetGRFFile(_cur_gps.grffile);
200 spec->grf_prop.local_id = local_id;
201 }
202 }
203};
204
206template <typename T, typename Tclass>
208 void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
209 {
210 CargoType cargo_type = TranslateCargo(GSF_STATIONS, cid);
211 if (!IsValidCargoType(cargo_type)) return;
212
213 if (T *spec = GetSpec<T>(_cur_gps.grffile, local_id); spec == nullptr) {
214 GrfMsg(1, "MapSpriteGroup: {} undefined, skipping", local_id);
215 } else {
216 spec->grf_prop.SetSpriteGroup(cargo_type, group);
217 }
218 }
219
220 void MapDefault(uint16_t local_id, const SpriteGroup *group) override
221 {
222 if (T *spec = GetSpec<T>(_cur_gps.grffile, local_id); spec == nullptr) {
223 GrfMsg(1, "MapSpriteGroup: {} undefined, skipping", local_id);
224 } else if (spec->grf_prop.HasGrfFile()) {
225 GrfMsg(1, "MapSpriteGroup: {} mapped multiple times, skipping", local_id);
226 } else {
227 spec->grf_prop.SetSpriteGroup(CargoGRFFileProps::SG_DEFAULT, group);
228 spec->grf_prop.SetGRFFile(_cur_gps.grffile);
229 spec->grf_prop.local_id = local_id;
230 Tclass::Assign(spec);
231 }
232 }
233};
234
236 void MapSpecific(uint16_t, uint8_t, const SpriteGroup *) override {}
237
238 void MapDefault(uint16_t local_id, const SpriteGroup *group) override
239 {
240 if (local_id >= CF_END) {
241 GrfMsg(1, "CanalMapSpriteGroup: Canal subset {} out of range, skipping", local_id);
242 } else {
243 _water_feature[local_id].grffile = _cur_gps.grffile;
244 _water_feature[local_id].group = group;
245 }
246 }
247};
248
249template <> auto *GetSpec<StationSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->stations.size() ? grffile->stations[local_id].get() : nullptr; }
251
252template <> auto *GetSpec<HouseSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->housespec.size() ? grffile->housespec[local_id].get() : nullptr; }
254
255template <> auto *GetSpec<IndustrySpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->industryspec.size() ? grffile->industryspec[local_id].get() : nullptr; }
257
258template <> auto *GetSpec<IndustryTileSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->indtspec.size() ? grffile->indtspec[local_id].get() : nullptr; }
260
262 void MapSpecific(uint16_t, uint8_t, const SpriteGroup *) override {}
263
264 void MapDefault(uint16_t local_id, const SpriteGroup *group) override
265 {
266 if (local_id >= NUM_CARGO) {
267 GrfMsg(1, "CargoMapSpriteGroup: Cargo type {} out of range, skipping", local_id);
268 } else {
269 CargoSpec *cs = CargoSpec::Get(local_id);
270 cs->grffile = _cur_gps.grffile;
271 cs->group = group;
272 }
273 }
274};
275
276template <> auto *GetSpec<ObjectSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->objectspec.size() ? grffile->objectspec[local_id].get() : nullptr; }
278
280 void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
281 {
282 if (cid >= RTSG_END) return;
283
284 const auto &type_map = _cur_gps.grffile->railtype_map;
285 RailType railtype = local_id < std::size(type_map) ? type_map[local_id] : INVALID_RAILTYPE;
286 if (railtype == INVALID_RAILTYPE) return;
287
288 extern RailTypeInfo _railtypes[RAILTYPE_END];
289 RailTypeInfo &rti = _railtypes[railtype];
290 rti.grffile[cid] = _cur_gps.grffile;
291 rti.group[cid] = group;
292 }
293
294 void MapDefault(uint16_t, const SpriteGroup *) override {}
295};
296
297template <RoadTramType TRoadTramType>
299 void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
300 {
301 if (cid >= ROTSG_END) return;
302
303 const auto &type_map = (TRoadTramType == RTT_TRAM) ? _cur_gps.grffile->tramtype_map : _cur_gps.grffile->roadtype_map;
304 RoadType roadtype = local_id < std::size(type_map) ? type_map[local_id] : INVALID_ROADTYPE;
305 if (roadtype == INVALID_ROADTYPE) return;
306
307 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
308 RoadTypeInfo &rti = _roadtypes[roadtype];
309 rti.grffile[cid] = _cur_gps.grffile;
310 rti.group[cid] = group;
311 }
312
313 void MapDefault(uint16_t, const SpriteGroup *) override {}
314};
315
316template <> auto *GetSpec<AirportSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->airportspec.size() ? grffile->airportspec[local_id].get() : nullptr; }
318
319template <> auto *GetSpec<AirportTileSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->airtspec.size() ? grffile->airtspec[local_id].get() : nullptr; }
321
322template <> auto *GetSpec<RoadStopSpec>(GRFFile *grffile, uint16_t local_id) { return local_id < grffile->roadstops.size() ? grffile->roadstops[local_id].get() : nullptr; }
323struct RoadStopMapSpriteGroupHandler : CargoTypeMapSpriteGroupHandler<RoadStopSpec, RoadStopClass> {};
324
326 void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
327 {
328 if (cid >= GSF_END) return;
329
330 auto found = _cur_gps.grffile->badge_map.find(local_id);
331 if (found == std::end(_cur_gps.grffile->badge_map)) {
332 GrfMsg(1, "BadgeMapSpriteGroup: Badge {} undefined, skipping", local_id);
333 } else {
334 auto &badge = *GetBadge(found->second);
335 badge.grf_prop.SetSpriteGroup(static_cast<GrfSpecFeature>(cid), group);
336 }
337 }
338
339 void MapDefault(uint16_t local_id, const SpriteGroup *group) override
340 {
341 auto found = _cur_gps.grffile->badge_map.find(local_id);
342 if (found == std::end(_cur_gps.grffile->badge_map)) {
343 GrfMsg(1, "BadgeMapSpriteGroup: Badge {} undefined, skipping", local_id);
344 } else {
345 auto &badge = *GetBadge(found->second);
346 badge.grf_prop.SetSpriteGroup(GSF_DEFAULT, group);
347 badge.grf_prop.SetGRFFile(_cur_gps.grffile);
348 badge.grf_prop.local_id = local_id;
349 }
350 }
351};
352
353static void MapSpriteGroup(ByteReader &buf, uint8_t idcount, MapSpriteGroupHandler &&handler)
354{
355 /* Read IDs to map into memory. */
356 std::array<uint16_t, 256> local_ids_buffer;
357 for (uint i = 0; i != idcount; ++i) {
358 local_ids_buffer[i] = buf.ReadExtendedByte();
359 }
360 std::span<const uint16_t> local_ids{local_ids_buffer.begin(), idcount};
361
362 /* Handle specific mappings. */
363 uint8_t cidcount = buf.ReadByte();
364 for (uint c = 0; c != cidcount; ++c) {
365 uint8_t cid = buf.ReadByte();
366 uint16_t groupid = buf.ReadWord();
367 if (!IsValidGroupID(groupid, "MapSpriteGroup")) continue;
368 for (uint16_t local_id : local_ids) {
369 handler.MapSpecific(local_id, cid, _cur_gps.spritegroups[groupid]);
370 }
371 }
372
373 /* Handle default mapping. */
374 uint16_t groupid = buf.ReadWord();
375 if (!IsValidGroupID(groupid, "MapSpriteGroup")) return;
376 for (uint16_t local_id : local_ids) {
377 handler.MapDefault(local_id, _cur_gps.spritegroups[groupid]);
378 }
379}
380
381/* Action 0x03 */
382static void FeatureMapSpriteGroup(ByteReader &buf)
383{
384 /* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
385 * id-list := [<id>] [id-list]
386 * cargo-list := <cargo-type> <cid> [cargo-list]
387 *
388 * B feature see action 0
389 * B n-id bits 0-6: how many IDs this definition applies to
390 * bit 7: if set, this is a wagon override definition (see below)
391 * E ids the IDs for which this definition applies
392 * B num-cid number of cargo IDs (sprite group IDs) in this definition
393 * can be zero, in that case the def-cid is used always
394 * B cargo-type type of this cargo type (e.g. mail=2, wood=7, see below)
395 * W cid cargo ID (sprite group ID) for this type of cargo
396 * W def-cid default cargo ID (sprite group ID) */
397
398 GrfSpecFeature feature{buf.ReadByte()};
399 uint8_t idcount = buf.ReadByte();
400
401 if (feature >= GSF_END) {
402 GrfMsg(1, "FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
403 return;
404 }
405
406 /* If idcount is zero, this is a feature callback */
407 if (idcount == 0) {
408 /* Skip number of cargo ids? */
409 buf.ReadByte();
410 uint16_t groupid = buf.ReadWord();
411 if (!IsValidGroupID(groupid, "FeatureMapSpriteGroup")) return;
412
413 GrfMsg(6, "FeatureMapSpriteGroup: Adding generic feature callback for feature 0x{:02X}", feature);
414
415 AddGenericCallback(feature, _cur_gps.grffile, _cur_gps.spritegroups[groupid]);
416 return;
417 }
418
419 /* Mark the feature as used by the grf (generic callbacks do not count) */
420 _cur_gps.grffile->grf_features.Set(feature);
421
422 GrfMsg(6, "FeatureMapSpriteGroup: Feature 0x{:02X}, {} ids", feature, idcount);
423
424 switch (feature) {
425 case GSF_TRAINS:
426 case GSF_ROADVEHICLES:
427 case GSF_SHIPS:
428 case GSF_AIRCRAFT: VehicleMapSpriteGroup(buf, feature, idcount); return;
429 case GSF_CANALS: MapSpriteGroup(buf, idcount, CanalMapSpriteGroupHandler{}); return;
430 case GSF_STATIONS: MapSpriteGroup(buf, idcount, StationMapSpriteGroupHandler{}); return;
431 case GSF_HOUSES: MapSpriteGroup(buf, idcount, TownHouseMapSpriteGroupHandler{}); return;
432 case GSF_INDUSTRIES: MapSpriteGroup(buf, idcount, IndustryMapSpriteGroupHandler{}); return;
433 case GSF_INDUSTRYTILES: MapSpriteGroup(buf, idcount, IndustryTileMapSpriteGroupHandler{}); return;
434 case GSF_CARGOES: MapSpriteGroup(buf, idcount, CargoMapSpriteGroupHandler{}); return;
435 case GSF_AIRPORTS: MapSpriteGroup(buf, idcount, AirportMapSpriteGroupHandler{}); return;
436 case GSF_OBJECTS: MapSpriteGroup(buf, idcount, ObjectMapSpriteGroupHandler{}); return;
437 case GSF_RAILTYPES: MapSpriteGroup(buf, idcount, RailTypeMapSpriteGroupHandler{}); return;
438 case GSF_ROADTYPES: MapSpriteGroup(buf, idcount, RoadTypeMapSpriteGroupHandler<RTT_ROAD>{}); return;
439 case GSF_TRAMTYPES: MapSpriteGroup(buf, idcount, RoadTypeMapSpriteGroupHandler<RTT_TRAM>{}); return;
440 case GSF_AIRPORTTILES: MapSpriteGroup(buf, idcount, AirportTileMapSpriteGroupHandler{}); return;
441 case GSF_ROADSTOPS: MapSpriteGroup(buf, idcount, RoadStopMapSpriteGroupHandler{}); return;
442 case GSF_BADGES: MapSpriteGroup(buf, idcount, BadgeMapSpriteGroupHandler{}); return;
443
444 default:
445 GrfMsg(1, "FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
446 return;
447 }
448}
449
450template <> void GrfActionHandler<0x03>::FileScan(ByteReader &) { }
451template <> void GrfActionHandler<0x03>::SafetyScan(ByteReader &buf) { GRFUnsafe(buf); }
452template <> void GrfActionHandler<0x03>::LabelScan(ByteReader &) { }
453template <> void GrfActionHandler<0x03>::Init(ByteReader &) { }
454template <> void GrfActionHandler<0x03>::Reserve(ByteReader &) { }
455template <> void GrfActionHandler<0x03>::Activation(ByteReader &buf) { FeatureMapSpriteGroup(buf); }
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static constexpr CargoLabel CT_INVALID
Invalid cargo type.
Definition cargo_type.h:70
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
StrongType::Typedef< uint32_t, struct CargoLabelTag, StrongType::Compare > CargoLabel
Globally unique label of a cargo type.
Definition cargo_type.h:16
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
Class to read from a NewGRF file.
uint16_t ReadWord()
Read a single Word (16 bits).
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:115
const SpriteGroup * group[RTSG_END]
Sprite groups for resolving sprites.
Definition rail.h:270
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
Definition rail.h:265
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition road.h:166
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition road.h:161
Functions related to debugging.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
Definition engine_type.h:26
Functions related to errors.
Definition of HouseSpec and accessors.
Industry type specs.
std::span< const CargoLabel > GetCargoTranslationTable(const GRFFile &grffile)
Get the cargo translation table to use for the given GRF file.
Definition newgrf.cpp:522
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
Definition newgrf.cpp:374
Engine * GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access)
Returns the engine associated to a certain internal_id, resp.
Definition newgrf.cpp:215
GrfSpecFeature
Definition newgrf.h:71
@ GSF_DEFAULT
Unspecified feature, default badge.
Definition newgrf.h:96
static auto * GetSpec(GRFFile *, uint16_t)
Specializable function to retrieve a NewGRF spec of a particular type.
NewGRF handling of airports.
NewGRF handling of airport tiles.
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
Functions related to NewGRF badges.
Types related to NewGRF badges.
NewGRF buffer reader definition.
std::array< WaterFeature, CF_END > _water_feature
Table of canal 'feature' sprite groups.
Handling of NewGRF canals.
Cargo support for NewGRFs.
@ Purchase
Used before an entity exists.
@ Default
Default type used when no more-specific group matches.
void SetEngineGRF(EngineID engine, const GRFFile *file)
Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game.
Functions for NewGRF engines.
void AddGenericCallback(GrfSpecFeature feature, const GRFFile *file, const SpriteGroup *group)
Add a generic feature callback sprite group to the appropriate feature list.
Functions related to NewGRF houses.
NewGRF internal processing state.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
static constexpr uint MAX_SPRITEGROUP
Maximum GRF-local ID for a spritegroup.
NewGRF internal processing state for vehicles.
Functions related to NewGRF objects.
NewGRF definitions and structures for road stops.
Header file for NewGRF stations.
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
@ RAILTYPE_END
Used for iterations.
Definition rail_type.h:31
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:32
Road specific functions.
@ RTT_TRAM
Tram road type.
Definition road_type.h:39
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:27
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
void MapDefault(uint16_t local_id, const SpriteGroup *group) override
Map default/fallback SpriteGroup to a specification.
void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
Map a SpriteGroup to specific 'cargo type' of a specification.
void MapSpecific(uint16_t, uint8_t, const SpriteGroup *) override
Map a SpriteGroup to specific 'cargo type' of a specification.
void MapDefault(uint16_t local_id, const SpriteGroup *group) override
Map default/fallback SpriteGroup to a specification.
static constexpr CargoType SG_PURCHASE
Used in purchase lists before an item exists.
static constexpr CargoType SG_DEFAULT
Default type used when no more-specific cargo matches.
static constexpr CargoType SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
void MapDefault(uint16_t local_id, const SpriteGroup *group) override
Map default/fallback SpriteGroup to a specification.
void MapSpecific(uint16_t, uint8_t, const SpriteGroup *) override
Map a SpriteGroup to specific 'cargo type' of a specification.
Specification of a cargo type.
Definition cargotype.h:74
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
Definition cargotype.h:137
const struct GRFFile * grffile
NewGRF where group belongs to.
Definition cargotype.h:99
Common handler for mapping sprite groups for features which support cargo-type specific sprites.
void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
Map a SpriteGroup to specific 'cargo type' of a specification.
void MapDefault(uint16_t local_id, const SpriteGroup *group) override
Map default/fallback SpriteGroup to a specification.
Dynamic data of a loaded NewGRF.
Definition newgrf.h:117
Handler interface for mapping sprite groups to their respective feature specific specifications.
virtual void MapDefault(uint16_t local_id, const SpriteGroup *group)=0
Map default/fallback SpriteGroup to a specification.
virtual void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group)=0
Map a SpriteGroup to specific 'cargo type' of a specification.
Common handler for mapping sprite groups for features which only support "Purchase" and "Default" spr...
void MapDefault(uint16_t local_id, const SpriteGroup *group) override
Map default/fallback SpriteGroup to a specification.
void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
Map a SpriteGroup to specific 'cargo type' of a specification.
void MapDefault(uint16_t, const SpriteGroup *) override
Map default/fallback SpriteGroup to a specification.
void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
Map a SpriteGroup to specific 'cargo type' of a specification.
void MapSpecific(uint16_t local_id, uint8_t cid, const SpriteGroup *group) override
Map a SpriteGroup to specific 'cargo type' of a specification.
void MapDefault(uint16_t, const SpriteGroup *) override
Map default/fallback SpriteGroup to a specification.
Base class for all vehicles.
VehicleType
Available vehicle types.