OpenTTD Source 20250331-master-g3c15e0c889
newgrf_internal.h File Reference

NewGRF internal processing state. More...

Go to the source code of this file.

Data Structures

struct  GrfChangeInfoHandler< TFeature >
 GRF feature handler. More...
 
struct  GrfActionHandler< TAction >
 GRF action handler. More...
 
struct  GrfProcessingState
 Temporary data during loading of GRFs. More...
 
struct  GrfProcessingState::SpriteSet
 Definition of a single Action1 spriteset. More...
 
struct  GRFLocation
 

Typedefs

using GRFLineToSpriteOverride = std::map< GRFLocation, std::vector< uint8_t > >
 

Enumerations

enum  ChangeInfoResult : uint8_t {
  CIR_SUCCESS , CIR_DISABLED , CIR_UNHANDLED , CIR_UNKNOWN ,
  CIR_INVALID_ID
}
 Possible return values for the GrfChangeInfoHandler functions. More...
 

Functions

void SetNewGRFOverride (uint32_t source_grfid, uint32_t target_grfid)
 Set the override for a NewGRF.
 
GRFFileGetCurrentGRFOverride ()
 Get overridden GRF for current GRF if present.
 
std::span< const CargoLabelGetCargoTranslationTable (const GRFFile &grffile)
 Get the cargo translation table to use for the given GRF file.
 
CargoTypes TranslateRefitMask (uint32_t refit_mask)
 Translate the refit mask.
 
void SkipBadgeList (ByteReader &buf)
 Skip a list of badges.
 
std::vector< BadgeIDReadBadgeList (ByteReader &buf, GrfSpecFeature feature)
 Read a list of badges.
 
void MapSpriteMappingRecolour (PalSpriteID *grf_sprite)
 Map the colour modifiers of TTDPatch to those that Open is using.
 
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.
 
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.
 
GRFFileGetFileByGRFID (uint32_t grfid)
 Obtain a NewGRF file by its grfID.
 
GRFErrorDisableGrf (StringID message={}, GRFConfig *config=nullptr)
 Disable a GRF.
 
void DisableStaticNewGRFInfluencingNonStaticNewGRFs (GRFConfig &c)
 Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desyncs.
 
bool HandleChangeInfoResult (const char *caller, ChangeInfoResult cir, uint8_t feature, uint8_t property)
 
uint32_t GetParamVal (uint8_t param, uint32_t *cond_val)
 
void GRFUnsafe (ByteReader &)
 Set the current NewGRF as unsafe for static use.
 
void InitializePatchFlags ()
 Initialize the TTDPatch flags.
 

Variables

static constexpr uint MAX_SPRITEGROUP = UINT8_MAX
 Maximum GRF-local ID for a spritegroup.
 
GrfProcessingState _cur
 
std::map< GRFLocation, std::pair< SpriteID, uint16_t > > _grm_sprites
 
GRFLineToSpriteOverride _grf_line_to_action6_sprite_override
 
GrfMiscBits _misc_grf_features
 Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
 

Detailed Description

NewGRF internal processing state.

Definition in file newgrf_internal.h.

Typedef Documentation

◆ GRFLineToSpriteOverride

using GRFLineToSpriteOverride = std::map<GRFLocation, std::vector<uint8_t> >

Definition at line 177 of file newgrf_internal.h.

Enumeration Type Documentation

◆ ChangeInfoResult

enum ChangeInfoResult : uint8_t

Possible return values for the GrfChangeInfoHandler functions.

Enumerator
CIR_SUCCESS 

Variable was parsed and read.

CIR_DISABLED 

GRF was disabled due to error.

CIR_UNHANDLED 

Variable was parsed but unread.

CIR_UNKNOWN 

Variable is unknown.

CIR_INVALID_ID 

Attempt to modify an invalid ID.

Definition at line 20 of file newgrf_internal.h.

Function Documentation

◆ DisableGrf()

◆ DisableStaticNewGRFInfluencingNonStaticNewGRFs()

void DisableStaticNewGRFInfluencingNonStaticNewGRFs ( GRFConfig c)

Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desyncs.

We could just tell the NewGRF querying that the file doesn't exist, but that might give unwanted results. Disabling the NewGRF gives the best result as no NewGRF author can complain about that.

Parameters
cThe NewGRF to disable.

Definition at line 161 of file newgrf.cpp.

References GRFError::data, DisableGrf(), GRFConfig::GetName(), and GrfProcessingState::grfconfig.

Referenced by ParamSet().

◆ GetCargoTranslationTable()

std::span< const CargoLabel > GetCargoTranslationTable ( const GRFFile grffile)

Get the cargo translation table to use for the given GRF file.

Parameters
grffileGRF file.
Returns
Readonly cargo translation table to use.

Definition at line 508 of file newgrf.cpp.

References GRFFile::cargo_list, GetClimateDependentCargoTranslationTable(), and GetClimateIndependentCargoTranslationTable().

Referenced by BuildCargoTranslationMap().

◆ GetCurrentGRFOverride()

GRFFile * GetCurrentGRFOverride ( )

Get overridden GRF for current GRF if present.

Returns
Overridden GRFFile if present, or nullptr.

Definition at line 189 of file newgrf.cpp.

References GetFileByGRFID(), and GrfProcessingState::grffile.

Referenced by LoadTranslationTable().

◆ GetFileByGRFID()

GRFFile * GetFileByGRFID ( uint32_t  grfid)

Obtain a NewGRF file by its grfID.

Parameters
grfidThe grfID to obtain the file for
Returns
The file.

Definition at line 98 of file newgrf.cpp.

References _grf_files.

Referenced by DisableGrf(), FinalisePriceBaseMultipliers(), GetCurrentGRFOverride(), LanguageMap::GetLanguageMap(), GetNewEngine(), ImportGRFSound(), LoadNewGRF(), and ParamSet().

◆ GetParamVal()

uint32_t GetParamVal ( uint8_t  param,
uint32_t *  cond_val 
)

Definition at line 116 of file newgrf_act7_9.cpp.

◆ GRFUnsafe()

void GRFUnsafe ( ByteReader )

Set the current NewGRF as unsafe for static use.

Note
Used during safety scan on unsafe actions.

Definition at line 365 of file newgrf.cpp.

References GRFConfig::flags, GrfProcessingState::grfconfig, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), GrfProcessingState::skip_sprites, and Unsafe.

◆ HandleChangeInfoResult()

bool HandleChangeInfoResult ( const char *  caller,
ChangeInfoResult  cir,
uint8_t  feature,
uint8_t  property 
)

Definition at line 112 of file newgrf_act0.cpp.

◆ InitializePatchFlags()

◆ MapSpriteMappingRecolour()

void MapSpriteMappingRecolour ( PalSpriteID grf_sprite)

Map the colour modifiers of TTDPatch to those that Open is using.

Parameters
grf_spritePointer to the structure been modified.

Definition at line 29 of file newgrf_act2.cpp.

References ClrBit(), HasBit(), PalSpriteID::pal, PALETTE_MODIFIER_COLOUR, PALETTE_MODIFIER_TRANSPARENT, SetBit(), PalSpriteID::sprite, and SPRITE_MODIFIER_OPAQUE.

Referenced by ReadSpriteLayoutSprite().

◆ ReadBadgeList()

std::vector< BadgeID > ReadBadgeList ( ByteReader buf,
GrfSpecFeature  feature 
)

◆ ReadSpriteLayout()

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.

Parameters
bufInput
num_building_spritesNumber of building sprites to read
use_cur_spritesetsWhether to use currently referenceable action 1 sets.
featureGrfSpecFeature to use spritesets from.
allow_var10Whether the spritelayout may specify var10 values for resolving multiple action-1-2-3 chains
no_z_positionWhether bounding boxes have no Z offset
dtsLayout container to output into
Returns
True on error (GRF was disabled).

Definition at line 171 of file newgrf_act2.cpp.

References NewGRFSpriteLayout::Allocate(), NewGRFSpriteLayout::AllocateRegisters(), ClrBit(), NewGRFSpriteLayout::consistent_max_offset, DrawTileSeqStruct::delta_z, DisableGrf(), DrawTileSprites::ground, HasBit(), DrawTileSeqStruct::IsParentSprite(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, ByteReader::ReadByte(), ReadSpriteLayoutRegisters(), ReadSpriteLayoutSprite(), GrfProcessingState::skip_sprites, TLF_KNOWN_FLAGS, and TLF_NON_GROUND_FLAGS.

Referenced by StationChangeInfo().

◆ ReadSpriteLayoutSprite()

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,
uint16_t *  max_palette_offset 
)

Read a sprite and a palette from the GRF and convert them into a format suitable to OpenTTD.

Parameters
bufInput stream.
read_flagsWhether to read TileLayoutFlags.
invert_action1_flagSet to true, if palette bit 15 means 'not from action 1'.
use_cur_spritesetsWhether to use currently referenceable action 1 sets.
featureGrfSpecFeature to use spritesets from.
[out]grf_spriteRead sprite and palette.
[out]max_sprite_offsetOptionally returns the number of sprites in the spriteset of the sprite. (0 if no spritset)
[out]max_palette_offsetOptionally returns the number of sprites in the spriteset of the palette. (0 if no spritset)
Returns
Read TileLayoutFlags.

Definition at line 60 of file newgrf_act2.cpp.

References ClrBit(), DisableGrf(), GB(), GrfProcessingState::GetNumEnts(), GrfProcessingState::GetSprite(), HasBit(), GrfProcessingState::IsValidSpriteSet(), MapSpriteMappingRecolour(), PalSpriteID::pal, ByteReader::ReadWord(), SB(), SetBit(), PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, SPRITE_WIDTH, TLF_CUSTOM_PALETTE, TLF_PALETTE_REG_FLAGS, TLF_PALETTE_VAR10, TLF_SPRITE_REG_FLAGS, and TLF_SPRITE_VAR10.

Referenced by ReadSpriteLayout(), and StationChangeInfo().

◆ SetNewGRFOverride()

void SetNewGRFOverride ( uint32_t  source_grfid,
uint32_t  target_grfid 
)

Set the override for a NewGRF.

Parameters
source_grfidThe grfID which wants to override another NewGRF.
target_grfidThe grfID which is being overridden.

Definition at line 174 of file newgrf.cpp.

Referenced by LoadNewGRF().

◆ SkipBadgeList()

void SkipBadgeList ( ByteReader buf)

Skip a list of badges.

Parameters
bufBuffer reader containing list of badges to skip.

Definition at line 72 of file newgrf_act0.cpp.

References ByteReader::ReadWord().

Referenced by IgnoreIndustryProperty(), IgnoreObjectProperty(), and IgnoreRoadStopProperty().

◆ TranslateRefitMask()

CargoTypes TranslateRefitMask ( uint32_t  refit_mask)

Translate the refit mask.

refit_mask is uint32_t as it has not been mapped to CargoTypes.

Definition at line 307 of file newgrf.cpp.

References GetCargoTranslation(), GrfProcessingState::grffile, IsValidCargoType(), and SetBit().

Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), and StationChangeInfo().

Variable Documentation

◆ _cur

GrfProcessingState _cur
extern

Definition at line 74 of file newgrf.cpp.

◆ _grf_line_to_action6_sprite_override

GRFLineToSpriteOverride _grf_line_to_action6_sprite_override
extern

Definition at line 18 of file newgrf_act6.cpp.

◆ _grm_sprites

std::map<GRFLocation, std::pair<SpriteID, uint16_t> > _grm_sprites
extern

Definition at line 17 of file newgrf_act6.cpp.

◆ _misc_grf_features

GrfMiscBits _misc_grf_features
extern

Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.

Definition at line 69 of file newgrf.cpp.

Referenced by GetGlobalVariable(), HasGrfMiscBit(), ParamSet(), and ResetNewGRFData().

◆ MAX_SPRITEGROUP

constexpr uint MAX_SPRITEGROUP = UINT8_MAX
staticconstexpr

Maximum GRF-local ID for a spritegroup.

Definition at line 46 of file newgrf_internal.h.