OpenTTD Source: src/newgrf_commons.h Source File

OpenTTD Source 15.0-RC2

newgrf_commons.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
13#ifndef NEWGRF_COMMONS_H
14#define NEWGRF_COMMONS_H
15
16#include "sprite.h"
17#include "command_type.h"
18#include "direction_type.h"
19#include "company_type.h"
20#include "cargo_type.h"
21#include "core/bitmath_func.hpp"
22
24 enum TileContext : uint8_t {
25 TCX_NORMAL,
26 TCX_UPPER_HALFTILE,
27 TCX_ON_BRIDGE,
28};
29
33 enum TileLayoutFlags : uint8_t {
34 TLF_NOTHING = 0x00,
35
36 TLF_DODRAW = 0x01,
37 TLF_SPRITE = 0x02,
38 TLF_PALETTE = 0x04,
39 TLF_CUSTOM_PALETTE = 0x08,
40
41 TLF_BB_XY_OFFSET = 0x10,
42 TLF_BB_Z_OFFSET = 0x20,
43
44 TLF_CHILD_X_OFFSET = 0x10,
45 TLF_CHILD_Y_OFFSET = 0x20,
46
47 TLF_SPRITE_VAR10 = 0x40,
48 TLF_PALETTE_VAR10 = 0x80,
49
50 TLF_KNOWN_FLAGS = 0xFF,
51
53 TLF_DRAWING_FLAGS = TLF_KNOWN_FLAGS & ~TLF_CUSTOM_PALETTE,
54
56 TLF_NON_GROUND_FLAGS = TLF_BB_XY_OFFSET | TLF_BB_Z_OFFSET | TLF_CHILD_X_OFFSET | TLF_CHILD_Y_OFFSET,
57
59 TLF_VAR10_FLAGS = TLF_SPRITE_VAR10 | TLF_PALETTE_VAR10,
60
62 TLF_SPRITE_REG_FLAGS = TLF_DODRAW | TLF_SPRITE | TLF_BB_XY_OFFSET | TLF_BB_Z_OFFSET | TLF_CHILD_X_OFFSET | TLF_CHILD_Y_OFFSET,
63
65 TLF_PALETTE_REG_FLAGS = TLF_PALETTE,
66};
67 DECLARE_ENUM_AS_BIT_SET(TileLayoutFlags)
68
69
75inline uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
76{
77 assert(num_sprites > 0);
78 if (num_sprites > 4) num_sprites = 4;
79 switch (construction_stage) {
80 case 0: return 0;
81 case 1: return num_sprites > 2 ? 1 : 0;
82 case 2: return num_sprites > 2 ? num_sprites - 2 : 0;
83 case 3: return num_sprites - 1;
84 default: NOT_REACHED();
85 }
86}
87
91 struct TileLayoutRegisters {
92 TileLayoutFlags flags;
93 uint8_t dodraw;
94 uint8_t sprite;
95 uint8_t palette;
96 uint16_t max_sprite_offset;
97 uint16_t max_palette_offset;
98 union {
99 uint8_t parent[3];
100 uint8_t child[2];
101 } delta;
102 uint8_t sprite_var10;
103 uint8_t palette_var10;
104};
105
106 static const uint TLR_MAX_VAR10 = 7;
107
113 struct NewGRFSpriteLayout : DrawTileSprites {
114 std::vector<DrawTileSeqStruct> seq{};
115 std::vector<TileLayoutRegisters> registers{};
116
121 uint consistent_max_offset = 0;
122
123 void Allocate(uint num_sprites);
124 void AllocateRegisters();
125
131 bool NeedsPreprocessing() const
132 {
133 return !this->registers.empty();
134 }
135
136 std::span<const DrawTileSeqStruct> GetSequence() const override { return {this->seq.begin(), this->seq.end()}; }
137};
138
142 class SpriteLayoutProcessor {
143 const NewGRFSpriteLayout *raw_layout = nullptr;
144 std::vector<DrawTileSeqStruct> result_seq;
145 uint32_t var10_values = 0;
146 bool separate_ground = false;
147public:
148 SpriteLayoutProcessor() = default;
149
151 SpriteLayoutProcessor(const NewGRFSpriteLayout &raw_layout) : raw_layout(&raw_layout) {}
152
153 SpriteLayoutProcessor(const NewGRFSpriteLayout &raw_layout, uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage, bool separate_ground);
154
159 SetBitIterator<uint8_t, uint32_t> Var10Values() const { return this->var10_values; }
160
161 void ProcessRegisters(const struct ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite);
162
167 DrawTileSpriteSpan GetLayout() const
168 {
169 assert(this->raw_layout != nullptr);
170 if (this->result_seq.empty()) {
171 /* Simple layout without preprocessing. */
172 return {this->raw_layout->ground, this->raw_layout->seq};
173 } else {
174 /* Dynamic layout with preprocessing. */
175 return {this->result_seq[0].image, {++this->result_seq.begin(), this->result_seq.end()}};
176 }
177 }
178};
179
192 struct EntityIDMapping {
193 uint32_t grfid;
194 uint16_t entity_id;
195 uint16_t substitute_id;
196};
197
198 class OverrideManagerBase {
199protected:
200 std::vector<uint16_t> entity_overrides;
201 std::vector<uint32_t> grfid_overrides;
202
203 uint16_t max_offset;
204 uint16_t max_entities;
205
206 uint16_t invalid_id;
207 virtual bool CheckValidNewID([[maybe_unused]] uint16_t testid) { return true; }
208
209public:
210 std::vector<EntityIDMapping> mappings;
211
212 OverrideManagerBase(uint16_t offset, uint16_t maximum, uint16_t invalid);
213 virtual ~OverrideManagerBase() = default;
214
215 void ResetOverride();
216 void ResetMapping();
217
218 void Add(uint16_t local_id, uint32_t grfid, uint entity_type);
219 virtual uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id);
220
221 uint32_t GetGRFID(uint16_t entity_id) const;
222 uint16_t GetSubstituteID(uint16_t entity_id) const;
223 virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const;
224
225 inline uint16_t GetMaxMapping() const { return this->max_entities; }
226 inline uint16_t GetMaxOffset() const { return this->max_offset; }
227};
228
229
230struct HouseSpec;
231 class HouseOverrideManager : public OverrideManagerBase {
232public:
233 HouseOverrideManager(uint16_t offset, uint16_t maximum, uint16_t invalid) :
234 OverrideManagerBase(offset, maximum, invalid) {}
235
236 void SetEntitySpec(HouseSpec &&hs);
237};
238
239
240struct IndustrySpec;
241 class IndustryOverrideManager : public OverrideManagerBase {
242public:
243 IndustryOverrideManager(uint16_t offset, uint16_t maximum, uint16_t invalid) :
244 OverrideManagerBase(offset, maximum, invalid) {}
245
246 uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id) override;
247 uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const override;
248
249 void SetEntitySpec(IndustrySpec &&inds);
250};
251
252
253struct IndustryTileSpec;
254 class IndustryTileOverrideManager : public OverrideManagerBase {
255protected:
256 bool CheckValidNewID(uint16_t testid) override { return testid != 0xFF; }
257public:
258 IndustryTileOverrideManager(uint16_t offset, uint16_t maximum, uint16_t invalid) :
259 OverrideManagerBase(offset, maximum, invalid) {}
260
261 void SetEntitySpec(IndustryTileSpec &&indts);
262};
263
264struct AirportSpec;
265 class AirportOverrideManager : public OverrideManagerBase {
266public:
267 AirportOverrideManager(uint16_t offset, uint16_t maximum, uint16_t invalid) :
268 OverrideManagerBase(offset, maximum, invalid) {}
269
270 void SetEntitySpec(AirportSpec &&inds);
271};
272
273struct AirportTileSpec;
274 class AirportTileOverrideManager : public OverrideManagerBase {
275protected:
276 bool CheckValidNewID(uint16_t testid) override { return testid != 0xFF; }
277public:
278 AirportTileOverrideManager(uint16_t offset, uint16_t maximum, uint16_t invalid) :
279 OverrideManagerBase(offset, maximum, invalid) {}
280
281 void SetEntitySpec(AirportTileSpec &&ats);
282};
283
284struct ObjectSpec;
285 class ObjectOverrideManager : public OverrideManagerBase {
286protected:
287 bool CheckValidNewID(uint16_t testid) override { return testid != 0xFF; }
288public:
289 ObjectOverrideManager(uint16_t offset, uint16_t maximum, uint16_t invalid) :
290 OverrideManagerBase(offset, maximum, invalid) {}
291
292 void SetEntitySpec(ObjectSpec &&spec);
293};
294
295extern HouseOverrideManager _house_mngr;
296extern IndustryOverrideManager _industry_mngr;
297extern IndustryTileOverrideManager _industile_mngr;
298extern AirportOverrideManager _airport_mngr;
299extern AirportTileOverrideManager _airporttile_mngr;
300extern ObjectOverrideManager _object_mngr;
301
302uint32_t GetTerrainType(TileIndex tile, TileContext context = TCX_NORMAL);
303 TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets = true, Axis axis = INVALID_AXIS);
304uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8);
305uint32_t GetCompanyInfo(CompanyID owner, const struct Livery *l = nullptr);
306 CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span<const int32_t> textstack, const GRFFile *grffile, StringID default_error);
307
308void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res);
309bool ConvertBooleanCallback(const struct GRFFile *grffile, uint16_t cbid, uint16_t cb_res);
310bool Convert8bitBooleanCallback(const struct GRFFile *grffile, uint16_t cbid, uint16_t cb_res);
311
315 struct GRFFilePropsBase {
316 uint16_t local_id = 0;
317 uint32_t grfid = 0;
318 const struct GRFFile *grffile = nullptr;
319
320 void SetGRFFile(const struct GRFFile *grffile);
321
326 inline bool HasGrfFile() const { return this->grffile != nullptr; }
327};
328
334template <class Tkey, size_t Tcount>
335 struct FixedGRFFileProps : GRFFilePropsBase {
336 std::array<const struct SpriteGroup *, Tcount> spritegroups{};
337
343 const struct SpriteGroup *GetSpriteGroup(Tkey index) const { return this->spritegroups[static_cast<size_t>(index)]; }
344
350 const struct SpriteGroup *GetFirstSpriteGroupOf(std::initializer_list<Tkey> indices) const
351 {
352 for (auto key : indices) {
353 auto *result = GetSpriteGroup(key);
354 if (result != nullptr) return result;
355 }
356 return nullptr;
357 }
358
364 void SetSpriteGroup(Tkey index, const struct SpriteGroup *spritegroup) { this->spritegroups[static_cast<size_t>(index)] = spritegroup; }
365};
366
370 enum class StandardSpriteGroup {
371 Default,
372 Purchase,
373 End
374};
375
379 struct StandardGRFFileProps : FixedGRFFileProps<StandardSpriteGroup, static_cast<size_t>(StandardSpriteGroup::End)> {
380 using FixedGRFFileProps<StandardSpriteGroup, static_cast<size_t>(StandardSpriteGroup::End)>::GetSpriteGroup;
381
385 bool HasSpriteGroups() const
386 {
387 return GetSpriteGroup(StandardSpriteGroup::Default) != nullptr;
388 }
389
394 const struct SpriteGroup *GetSpriteGroup(bool entity_exists) const
395 {
396 auto *res = entity_exists ? nullptr : GetSpriteGroup(StandardSpriteGroup::Purchase);
397 return res ? res : GetSpriteGroup(StandardSpriteGroup::Default);
398 }
399};
400
405template <class Tkey>
406 struct VariableGRFFileProps : GRFFilePropsBase {
407 using ValueType = std::pair<Tkey, const struct SpriteGroup *>;
408 std::vector<ValueType> spritegroups;
409
415 const SpriteGroup *GetSpriteGroup(Tkey index) const
416 {
417 auto it = std::ranges::lower_bound(this->spritegroups, index, std::less{}, &ValueType::first);
418 if (it == std::end(this->spritegroups) || it->first != index) return nullptr;
419 return it->second;
420 }
421
427 const struct SpriteGroup *GetFirstSpriteGroupOf(std::initializer_list<Tkey> indices) const
428 {
429 for (auto key : indices) {
430 auto *result = GetSpriteGroup(key);
431 if (result != nullptr) return result;
432 }
433 return nullptr;
434 }
435
441 void SetSpriteGroup(Tkey index, const SpriteGroup *spritegroup)
442 {
443 auto it = std::ranges::lower_bound(this->spritegroups, index, std::less{}, &ValueType::first);
444 if (it == std::end(this->spritegroups) || it->first != index) {
445 this->spritegroups.emplace(it, index, spritegroup);
446 } else {
447 it->second = spritegroup;
448 }
449 }
450};
451
455 struct CargoGRFFileProps : VariableGRFFileProps<CargoType> {
456 static constexpr CargoType SG_DEFAULT = NUM_CARGO;
457 static constexpr CargoType SG_PURCHASE = NUM_CARGO + 1;
458 static constexpr CargoType SG_DEFAULT_NA = NUM_CARGO + 2;
459};
460
464 struct SubstituteGRFFileProps : StandardGRFFileProps {
466 constexpr SubstituteGRFFileProps(uint16_t subst_id = 0) : subst_id(subst_id), override_id(subst_id) {}
467
468 uint16_t subst_id;
469 uint16_t override_id;
470};
471
473template <typename T>
474 struct LabelObject {
475 T label = {};
476 uint8_t subtype = 0;
477};
478
479#endif /* NEWGRF_COMMONS_H */
bitmath_func.hpp
Functions related to bit mathematics.
cargo_type.h
Types related to cargoes...
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
NUM_CARGO
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
AirportOverrideManager
Definition newgrf_commons.h:265
AirportTileOverrideManager
Definition newgrf_commons.h:274
CommandCost
Common return value for all commands.
Definition command_type.h:24
HouseOverrideManager
Definition newgrf_commons.h:231
HouseOverrideManager::SetEntitySpec
void SetEntitySpec(HouseSpec &&hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go.
Definition newgrf_commons.cpp:160
IndustryOverrideManager
Definition newgrf_commons.h:241
IndustryOverrideManager::AddEntityID
uint16_t AddEntityID(uint16_t grf_local_id, uint32_t grfid, uint16_t substitute_id) override
Method to find an entity ID and to mark it as reserved for the Industry to be included.
Definition newgrf_commons.cpp:213
IndustryOverrideManager::GetID
uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const override
Return the ID (if ever available) of a previously inserted entity.
Definition newgrf_commons.cpp:193
IndustryOverrideManager::SetEntitySpec
void SetEntitySpec(IndustrySpec &&inds)
Method to install the new industry data in its proper slot The slot assignment is internal of this me...
Definition newgrf_commons.cpp:248
IndustryTileOverrideManager
Definition newgrf_commons.h:254
ObjectOverrideManager
Definition newgrf_commons.h:285
ObjectOverrideManager::SetEntitySpec
void SetEntitySpec(ObjectSpec &&spec)
Method to install the new object data in its proper slot The slot assignment is internal of this meth...
Definition newgrf_commons.cpp:303
OverrideManagerBase
Definition newgrf_commons.h:198
OverrideManagerBase::GetGRFID
uint32_t GetGRFID(uint16_t entity_id) const
Gives the GRFID of the file the entity belongs to.
Definition newgrf_commons.cpp:140
OverrideManagerBase::ResetMapping
void ResetMapping()
Resets the mapping, which is used while initializing game.
Definition newgrf_commons.cpp:73
OverrideManagerBase::max_entities
uint16_t max_entities
what is the amount of entities, old and new summed
Definition newgrf_commons.h:204
OverrideManagerBase::GetID
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
Definition newgrf_commons.cpp:91
OverrideManagerBase::invalid_id
uint16_t invalid_id
ID used to detected invalid entities.
Definition newgrf_commons.h:206
OverrideManagerBase::Add
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...
Definition newgrf_commons.cpp:63
OverrideManagerBase::mappings
std::vector< EntityIDMapping > mappings
mapping of ids from grf files. Public out of convenience
Definition newgrf_commons.h:210
OverrideManagerBase::ResetOverride
void ResetOverride()
Resets the override, which is used while initializing game.
Definition newgrf_commons.cpp:79
OverrideManagerBase::GetSubstituteID
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
Definition newgrf_commons.cpp:150
OverrideManagerBase::max_offset
uint16_t max_offset
what is the length of the original entity's array of specs
Definition newgrf_commons.h:203
OverrideManagerBase::AddEntityID
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.
Definition newgrf_commons.cpp:110
SpriteLayoutProcessor
Add dynamic register values to a sprite layout.
Definition newgrf_commons.h:142
SpriteLayoutProcessor::GetLayout
DrawTileSpriteSpan GetLayout() const
Returns the result spritelayout after preprocessing.
Definition newgrf_commons.h:167
SpriteLayoutProcessor::ProcessRegisters
void ProcessRegisters(const struct ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite)
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
Definition newgrf_commons.cpp:665
SpriteLayoutProcessor::SpriteLayoutProcessor
SpriteLayoutProcessor(const NewGRFSpriteLayout &raw_layout)
Constructor for spritelayout, which do not need preprocessing.
Definition newgrf_commons.h:151
SpriteLayoutProcessor::Var10Values
SetBitIterator< uint8_t, uint32_t > Var10Values() const
Get values for variable 10 to resolve sprites for.
Definition newgrf_commons.h:159
command_type.h
Types related to commands.
CommandType::End
@ End
End marker.
company_type.h
Types related to companies.
direction_type.h
Different types to 'show' directions.
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition direction_type.h:127
DECLARE_ENUM_AS_BIT_SET
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:119
Convert8bitBooleanCallback
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition newgrf_commons.cpp:562
GetCompanyInfo
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
Definition newgrf_commons.cpp:457
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition newgrf_commons.cpp:543
TileContext
TileContext
Context for tile accesses.
Definition newgrf_commons.h:24
TCX_UPPER_HALFTILE
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
Definition newgrf_commons.h:26
TCX_ON_BRIDGE
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
Definition newgrf_commons.h:27
TCX_NORMAL
@ TCX_NORMAL
Nothing special.
Definition newgrf_commons.h:25
StandardSpriteGroup
StandardSpriteGroup
Standard sprite groups.
Definition newgrf_commons.h:370
StandardSpriteGroup::Purchase
@ Purchase
Used before an entity exists.
StandardSpriteGroup::Default
@ Default
Default type used when no more-specific group matches.
TileLayoutFlags
TileLayoutFlags
Flags to enable register usage in sprite layouts.
Definition newgrf_commons.h:33
TLF_BB_Z_OFFSET
@ TLF_BB_Z_OFFSET
Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:42
TLF_CUSTOM_PALETTE
@ TLF_CUSTOM_PALETTE
Palette is from Action 1 (moved to SPRITE_MODIFIER_CUSTOM_SPRITE in palette during loading).
Definition newgrf_commons.h:39
TLF_SPRITE
@ TLF_SPRITE
Add signed offset to sprite from register TileLayoutRegisters::sprite.
Definition newgrf_commons.h:37
TLF_CHILD_X_OFFSET
@ TLF_CHILD_X_OFFSET
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:44
TLF_DRAWING_FLAGS
@ TLF_DRAWING_FLAGS
Flags which are still required after loading the GRF.
Definition newgrf_commons.h:53
TLF_DODRAW
@ TLF_DODRAW
Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.
Definition newgrf_commons.h:36
TLF_PALETTE_REG_FLAGS
@ TLF_PALETTE_REG_FLAGS
Flags which require resolving the action-1-2-3 chain for the palette, even if it is no action-1 palet...
Definition newgrf_commons.h:65
TLF_NON_GROUND_FLAGS
@ TLF_NON_GROUND_FLAGS
Flags which do not work for the (first) ground sprite.
Definition newgrf_commons.h:56
TLF_BB_XY_OFFSET
@ TLF_BB_XY_OFFSET
Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:41
TLF_SPRITE_REG_FLAGS
@ TLF_SPRITE_REG_FLAGS
Flags which require resolving the action-1-2-3 chain for the sprite, even if it is no action-1 sprite...
Definition newgrf_commons.h:62
TLF_PALETTE_VAR10
@ TLF_PALETTE_VAR10
Resolve palette with a specific value in variable 10.
Definition newgrf_commons.h:48
TLF_SPRITE_VAR10
@ TLF_SPRITE_VAR10
Resolve sprite with a specific value in variable 10.
Definition newgrf_commons.h:47
TLF_KNOWN_FLAGS
@ TLF_KNOWN_FLAGS
Known flags. Any unknown set flag will disable the GRF.
Definition newgrf_commons.h:50
TLF_VAR10_FLAGS
@ TLF_VAR10_FLAGS
Flags which refer to using multiple action-1-2-3 chains.
Definition newgrf_commons.h:59
TLF_PALETTE
@ TLF_PALETTE
Add signed offset to palette from register TileLayoutRegisters::palette.
Definition newgrf_commons.h:38
TLF_CHILD_Y_OFFSET
@ TLF_CHILD_Y_OFFSET
Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta....
Definition newgrf_commons.h:45
TLR_MAX_VAR10
static const uint TLR_MAX_VAR10
Maximum value for var 10.
Definition newgrf_commons.h:106
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:517
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span< const int32_t > textstack, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition newgrf_commons.cpp:471
GetTerrainType
uint32_t GetTerrainType(TileIndex tile, TileContext context=TCX_NORMAL)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
Definition newgrf_commons.cpp:336
GetNearbyTileInformation
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
Definition newgrf_commons.cpp:434
GetConstructionStageOffset
uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
Definition newgrf_commons.h:75
GetNearbyTile
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets=true, Axis axis=INVALID_AXIS)
Get the tile at the given offset.
Definition newgrf_commons.cpp:411
sprite.h
Base for drawing complex sprites.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
AirportSpec
Defines the data structure for an airport.
Definition newgrf_airport.h:109
AirportTileSpec
Defines the data structure of each individual tile of an airport.
Definition newgrf_airporttiles.h:70
CargoGRFFileProps
Sprite groups indexed by CargoType.
Definition newgrf_commons.h:455
CargoGRFFileProps::SG_PURCHASE
static constexpr CargoType SG_PURCHASE
Used in purchase lists before an item exists.
Definition newgrf_commons.h:457
CargoGRFFileProps::SG_DEFAULT
static constexpr CargoType SG_DEFAULT
Default type used when no more-specific cargo matches.
Definition newgrf_commons.h:456
CargoGRFFileProps::SG_DEFAULT_NA
static constexpr CargoType SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
Definition newgrf_commons.h:458
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
EntityIDMapping
Maps an entity id stored on the map to a GRF file.
Definition newgrf_commons.h:192
EntityIDMapping::substitute_id
uint16_t substitute_id
The (original) entity ID to use if this GRF is not available.
Definition newgrf_commons.h:195
EntityIDMapping::grfid
uint32_t grfid
The GRF ID of the file the entity belongs to.
Definition newgrf_commons.h:193
EntityIDMapping::entity_id
uint16_t entity_id
The entity ID within the GRF file.
Definition newgrf_commons.h:194
FixedGRFFileProps
Fixed-length list of sprite groups for an entity.
Definition newgrf_commons.h:335
FixedGRFFileProps::GetSpriteGroup
const struct SpriteGroup * GetSpriteGroup(Tkey index) const
Get the SpriteGroup at the specified index.
Definition newgrf_commons.h:343
FixedGRFFileProps::SetSpriteGroup
void SetSpriteGroup(Tkey index, const struct SpriteGroup *spritegroup)
Set the SpriteGroup at the specified index.
Definition newgrf_commons.h:364
FixedGRFFileProps::spritegroups
std::array< const struct SpriteGroup *, Tcount > spritegroups
pointers to the different sprite groups of the entity
Definition newgrf_commons.h:336
FixedGRFFileProps::GetFirstSpriteGroupOf
const struct SpriteGroup * GetFirstSpriteGroupOf(std::initializer_list< Tkey > indices) const
Get the first existing SpriteGroup from a list of options.
Definition newgrf_commons.h:350
GRFFilePropsBase
Base data related to the handling of grf files.
Definition newgrf_commons.h:315
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:316
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFilePropsBase::SetGRFFile
void SetGRFFile(const struct GRFFile *grffile)
Set the NewGRF file, and its grfid, associated with grf props.
Definition newgrf_commons.cpp:735
GRFFilePropsBase::HasGrfFile
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Definition newgrf_commons.h:326
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
HouseSpec
Definition house.h:98
IndustrySpec
Defines the data structure for constructing industry.
Definition industrytype.h:103
IndustryTileSpec
Defines the data structure of each individual tile of an industry.
Definition industrytype.h:152
LabelObject
Container for a label for rail or road type conversion.
Definition newgrf_commons.h:474
LabelObject::subtype
uint8_t subtype
Subtype of type (road or tram).
Definition newgrf_commons.h:476
LabelObject::label
T label
Label of rail or road type.
Definition newgrf_commons.h:475
Livery
Information about a particular livery.
Definition livery.h:79
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition newgrf_commons.h:113
NewGRFSpriteLayout::Allocate
void Allocate(uint num_sprites)
Allocate a spritelayout for num_sprites building sprites.
Definition newgrf_commons.cpp:576
NewGRFSpriteLayout::consistent_max_offset
uint consistent_max_offset
Number of sprites in all referenced spritesets.
Definition newgrf_commons.h:121
NewGRFSpriteLayout::NeedsPreprocessing
bool NeedsPreprocessing() const
Tests whether this spritelayout needs preprocessing by SpriteLayoutProcessor, or whether it can be us...
Definition newgrf_commons.h:131
NewGRFSpriteLayout::AllocateRegisters
void AllocateRegisters()
Allocate memory for register modifiers.
Definition newgrf_commons.cpp:586
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition newgrf_object.h:60
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition bitmath_func.hpp:277
SpriteGroup
Definition newgrf_spritegroup.h:47
StandardGRFFileProps
Container for standard sprite groups.
Definition newgrf_commons.h:379
StandardGRFFileProps::GetSpriteGroup
const struct SpriteGroup * GetSpriteGroup(bool entity_exists) const
Get the standard sprite group.
Definition newgrf_commons.h:394
StandardGRFFileProps::HasSpriteGroups
bool HasSpriteGroups() const
Check whether the entity has sprite groups.
Definition newgrf_commons.h:385
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
SubstituteGRFFileProps::override_id
uint16_t override_id
id of the entity been replaced by
Definition newgrf_commons.h:469
SubstituteGRFFileProps::SubstituteGRFFileProps
constexpr SubstituteGRFFileProps(uint16_t subst_id=0)
Set all default data constructor for the props.
Definition newgrf_commons.h:466
TileLayoutRegisters
Additional modifiers for items in sprite layouts.
Definition newgrf_commons.h:91
TileLayoutRegisters::parent
uint8_t parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
Definition newgrf_commons.h:99
TileLayoutRegisters::flags
TileLayoutFlags flags
Flags defining which members are valid and to be used.
Definition newgrf_commons.h:92
TileLayoutRegisters::dodraw
uint8_t dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
Definition newgrf_commons.h:93
TileLayoutRegisters::max_sprite_offset
uint16_t max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
Definition newgrf_commons.h:96
TileLayoutRegisters::palette
uint8_t palette
Register specifying a signed offset for the palette.
Definition newgrf_commons.h:95
TileLayoutRegisters::sprite_var10
uint8_t sprite_var10
Value for variable 10 when resolving the sprite.
Definition newgrf_commons.h:102
TileLayoutRegisters::max_palette_offset
uint16_t max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
Definition newgrf_commons.h:97
TileLayoutRegisters::palette_var10
uint8_t palette_var10
Value for variable 10 when resolving the palette.
Definition newgrf_commons.h:103
TileLayoutRegisters::child
uint8_t child[2]
Registers for signed offsets for the position of child sprites.
Definition newgrf_commons.h:100
TileLayoutRegisters::sprite
uint8_t sprite
Register specifying a signed offset for the sprite.
Definition newgrf_commons.h:94
VariableGRFFileProps
Variable-length list of sprite groups for an entity.
Definition newgrf_commons.h:406
VariableGRFFileProps::spritegroups
std::vector< ValueType > spritegroups
pointers to the different sprite groups of the entity
Definition newgrf_commons.h:408
VariableGRFFileProps::GetFirstSpriteGroupOf
const struct SpriteGroup * GetFirstSpriteGroupOf(std::initializer_list< Tkey > indices) const
Get the first existing SpriteGroup from a list of options.
Definition newgrf_commons.h:427
VariableGRFFileProps::GetSpriteGroup
const SpriteGroup * GetSpriteGroup(Tkey index) const
Get the SpriteGroup at the specified index.
Definition newgrf_commons.h:415
VariableGRFFileProps::SetSpriteGroup
void SetSpriteGroup(Tkey index, const SpriteGroup *spritegroup)
Set the SpriteGroup at the specified index.
Definition newgrf_commons.h:441