10#ifndef NEWGRF_INTERNAL_H
11#define NEWGRF_INTERNAL_H
14#include "../newgrf_commons.h"
15#include "../newgrf_config.h"
16#include "../spriteloader/sprite_file_type.hpp"
29template <GrfSpecFeature TFeature>
36template <u
int8_t TAction>
75 std::array<const SpriteGroup *, MAX_SPRITEGROUP + 1> spritegroups{};
81 this->skip_sprites = 0;
83 for (uint i = 0; i < GSF_END; i++) {
84 this->spritesets[i].clear();
87 this->spritegroups = {};
100 assert(feature < GSF_END);
101 for (uint i = 0; i < numsets; i++) {
102 SpriteSet &set = this->spritesets[feature][first_set + i];
103 set.
sprite = first_sprite + i * numents;
116 assert(feature < GSF_END);
117 return !this->spritesets[feature].empty();
129 assert(feature < GSF_END);
130 return this->spritesets[feature].find(set) != this->spritesets[feature].end();
142 return this->spritesets[feature].find(set)->second.sprite;
154 return this->spritesets[feature].find(set)->second.num_sprites;
164 GRFLocation(uint32_t grfid, uint32_t nfoline) : grfid(grfid), nfoline(nfoline) { }
168 return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
173 return this->grfid == other.grfid && this->nfoline == other.nfoline;
177using GRFLineToSpriteOverride = std::map<GRFLocation, std::vector<uint8_t>>;
179extern std::map<GRFLocation, std::pair<SpriteID, uint16_t>> _grm_sprites;
180extern GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
201bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property);
202uint32_t GetParamVal(uint8_t param, uint32_t *cond_val);
Class to read from a NewGRF file.
RandomAccessFile with some extra information specific for sprite files.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
NewGRF buffer reader definition.
TileLayoutFlags
Flags to enable register usage in sprite layouts.
GRFError * DisableGrf(StringID message={}, GRFConfig *config=nullptr)
Disable a GRF.
std::span< const CargoLabel > GetCargoTranslationTable(const GRFFile &grffile)
Get the cargo translation table to use for the given GRF file.
GRFFile * GetCurrentGRFOverride()
Get overridden GRF for current GRF if present.
void SetNewGRFOverride(uint32_t source_grfid, uint32_t target_grfid)
Set the override for a NewGRF.
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
void InitializePatchFlags()
Initialize the TTDPatch flags.
bool ReadSpriteLayout(ByteReader &buf, uint num_building_sprites, bool use_cur_spritesets, uint8_t feature, bool allow_var10, bool no_z_position, NewGRFSpriteLayout *dts)
Read a spritelayout from the GRF.
std::vector< BadgeID > ReadBadgeList(ByteReader &buf, GrfSpecFeature feature)
Read a list of badges.
void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig &c)
Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desync...
GRFFile * GetFileByGRFID(uint32_t grfid)
Obtain a NewGRF file by its grfID.
GrfMiscBits _misc_grf_features
Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
void SkipBadgeList(ByteReader &buf)
Skip a list of badges.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
@ CIR_DISABLED
GRF was disabled due to error.
@ CIR_UNKNOWN
Variable is unknown.
@ CIR_UNHANDLED
Variable was parsed but unread.
@ CIR_SUCCESS
Variable was parsed and read.
void MapSpriteMappingRecolour(PalSpriteID *grf_sprite)
Map the colour modifiers of TTDPatch to those that Open is using.
static constexpr uint MAX_SPRITEGROUP
Maximum GRF-local ID for a spritegroup.
TileLayoutFlags ReadSpriteLayoutSprite(ByteReader &buf, bool read_flags, bool invert_action1_flag, bool use_cur_spritesets, int feature, PalSpriteID *grf_sprite, uint16_t *max_sprite_offset=nullptr, uint16_t *max_palette_offset=nullptr)
Read a sprite and a palette from the GRF and convert them into a format suitable to OpenTTD.
CargoTypes TranslateRefitMask(uint32_t refit_mask)
Translate the refit mask.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Information about GRF, used in the game and (part of it) in savegames.
Information about why GRF had problems during initialisation.
Dynamic data of a loaded NewGRF.
Definition of a single Action1 spriteset.
uint num_sprites
Number of sprites in the set.
SpriteID sprite
SpriteID of the first sprite of the set.
Temporary data during loading of GRFs.
SpriteFile * file
File of currently processed GRF file.
GRFFile * grffile
Currently processed GRF file.
void AddSpriteSets(uint8_t feature, SpriteID first_sprite, uint first_set, uint numsets, uint numents)
Records new spritesets.
uint32_t nfo_line
Currently processed pseudo sprite number in the GRF.
SpriteID spriteid
First available SpriteID for loading realsprites.
GRFConfig * grfconfig
Config of the currently processed GRF file.
SpriteID GetSprite(uint8_t feature, uint set) const
Returns the first sprite of a spriteset.
bool IsValidSpriteSet(uint8_t feature, uint set) const
Check whether a specific set is defined.
uint GetNumEnts(uint8_t feature, uint set) const
Returns the number of sprites in a spriteset.
bool HasValidSpriteSets(uint8_t feature) const
Check whether there are any valid spritesets for a feature.
std::map< uint, SpriteSet > spritesets[GSF_END]
Currently referenceable spritesets.
void ClearDataForNextFile()
Clear temporary data before processing the next file in the current loading stage.
GrfLoadingStage stage
Current loading stage.
int skip_sprites
Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file)
NewGRF supplied spritelayout.
Combination of a palette sprite and a 'real' sprite.