OpenTTD Source: src/newgrf/newgrf_internal.h File Reference

OpenTTD Source 15.0-RC2

Data Structures | Typedefs | Enumerations | Functions | Variables
newgrf_internal.h File Reference

NewGRF internal processing state. More...

`#include "../newgrf.h"`
`#include "../newgrf_commons.h"`
`#include "../newgrf_config.h"`
`#include "../spriteloader/sprite_file_type.hpp"`
`#include "newgrf_bytereader.h"`

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.
GRFFile * | GetCurrentGRFOverride ()
| Get overridden GRF for current GRF if present.
std::span< const CargoLabel > | GetCargoTranslationTable (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< BadgeID > | ReadBadgeList (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, GrfSpecFeature 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, GrfSpecFeature feature, bool allow_var10, bool no_z_position, NewGRFSpriteLayout *dts)
| Read a spritelayout from the GRF.
GRFFile * | GetFileByGRFID (uint32_t grfid)
| Obtain a NewGRF file by its grfID.
GRFError * | DisableGrf (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 (std::string_view caller, ChangeInfoResult cir, GrfSpecFeature 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_gps
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()

GRFError * DisableGrf | ( | StringID | message,
|  | GRFConfig * | config
| ) |  |

Disable a GRF.

Parameters

  message | Error message or STR_NULL.
  config | GRFConfig to disable, nullptr for current.

Returns
  Error message of the GRF for further customisation.

Definition at line 135 of file newgrf.cpp.

References ClearTemporaryNewGRFData(), GRFConfig::errors, GCS_DISABLED, GetFileByGRFID(), GrfProcessingState::grfconfig, GrfProcessingState::grffile, GRFIdentifier::grfid, GRFConfig::ident, GrfProcessingState::nfo_line, GRFError::nfo_line, GrfProcessingState::skip_sprites, and GRFConfig::status.

Referenced by DisableStaticNewGRFInfluencingNonStaticNewGRFs(), FeatureTownName(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), LoadNewGRFFileFromFile(), ParamSet(), ReadSpriteLayout(), ReadSpriteLayoutRegisters(), ReadSpriteLayoutSprite(), TownHouseChangeInfo(), and TranslateGRFStrings().

## ◆ 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

  c | The NewGRF to disable.

Definition at line 168 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

  grffile | GRF file.

Returns
  Readonly cargo translation table to use.

Definition at line 521 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 196 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

  grfid | The grfID to obtain the file for

Returns
  The file.

Definition at line 104 of file newgrf.cpp.

References _grf_files.

Referenced by DisableGrf(), 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 373 of file newgrf.cpp.

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

## ◆ HandleChangeInfoResult()

bool HandleChangeInfoResult | ( | std::string_view | caller,
|  | ChangeInfoResult | cir,
|  | GrfSpecFeature | feature,
|  | uint8_t | property
| ) |  |

Definition at line 112 of file newgrf_act0.cpp.

## ◆ InitializePatchFlags()

void InitializePatchFlags | ( |  | ) |

Initialize the TTDPatch flags.

Definition at line 28 of file newgrf_act7_9.cpp.

References _generating_world, _settings_game, _ttdpatch_flags, EconomySettings::allow_town_roads, ConstructionSettings::build_on_slopes, GameSettings::construction, VehicleSettings::disable_elrails, VehicleSettings::dynamic_engines, GameSettings::economy, VehicleSettings::freight_trains, OrderSettings::gradual_loading, OrderSettings::improved_load, EconomySettings::inflation, ConstructionSettings::max_bridge_length, StationSettings::never_expire_airports, VehicleSettings::never_expire_vehicles, GameSettings::order, GameSettings::station, EconomySettings::station_noise_level, ConstructionSettings::train_signal_side, GameSettings::vehicle, and VehicleSettings::wagon_speed_limits.

Referenced by LoadNewGRF().

## ◆ MapSpriteMappingRecolour()

void MapSpriteMappingRecolour | ( | PalSpriteID * | grf_sprite | ) |

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

Parameters

  grf_sprite | Pointer to the structure been modified.

Definition at line 32 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
| ) |  |

Read a list of badges.

Parameters

  buf | Buffer reader containing list of badges to read.
  feature | The feature of the badge list.

Returns
  list of badges.

Definition at line 86 of file newgrf_act0.cpp.

References GRFFile::badge_list, GrfProcessingState::grffile, MarkBadgeSeen(), and ByteReader::ReadWord().

Referenced by AircraftVehicleChangeInfo(), AirportChangeInfo(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), ObjectChangeInfo(), RailTypeChangeInfo(), RailVehicleChangeInfo(), RoadTypeChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), StationChangeInfo(), and TownHouseChangeInfo().

## ◆ ReadSpriteLayout()

bool ReadSpriteLayout | ( | ByteReader & | buf,
|  | uint | num_building_sprites,
|  | bool | use_cur_spritesets,
|  | GrfSpecFeature | feature,
|  | bool | allow_var10,
|  | bool | no_z_position,
|  | NewGRFSpriteLayout * | dts
| ) |  |

Read a spritelayout from the GRF.

Parameters

  buf | Input
  num_building_sprites | Number of building sprites to read
  use_cur_spritesets | Whether to use currently referenceable action 1 sets.
  feature | GrfSpecFeature to use spritesets from.
  allow_var10 | Whether the spritelayout may specify var10 values for resolving multiple action-1-2-3 chains
  no_z_position | Whether bounding boxes have no Z offset
  dts | Layout container to output into

Returns
  True on error (GRF was disabled).

Definition at line 174 of file newgrf_act2.cpp.

References NewGRFSpriteLayout::Allocate(), NewGRFSpriteLayout::AllocateRegisters(), ClrBit(), NewGRFSpriteLayout::consistent_max_offset, DisableGrf(), SpriteBounds::extent, DrawTileSprites::ground, HasBit(), DrawTileSeqStruct::IsParentSprite(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, SpriteBounds::origin, ByteReader::ReadByte(), ReadSpriteLayoutRegisters(), ReadSpriteLayoutSprite(), GrfProcessingState::skip_sprites, TLF_KNOWN_FLAGS, TLF_NON_GROUND_FLAGS, Coord3D< T >::x, Coord3D< T >::y, and Coord3D< T >::z.

Referenced by StationChangeInfo().

## ◆ ReadSpriteLayoutSprite()

TileLayoutFlags ReadSpriteLayoutSprite | ( | ByteReader & | buf,
|  | bool | read_flags,
|  | bool | invert_action1_flag,
|  | bool | use_cur_spritesets,
|  | GrfSpecFeature | 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

  | buf | Input stream.
  | read_flags | Whether to read TileLayoutFlags.
  | invert_action1_flag | Set to true, if palette bit 15 means 'not from action 1'.
  | use_cur_spritesets | Whether to use currently referenceable action 1 sets.
  | feature | GrfSpecFeature to use spritesets from.
  [out] | grf_sprite | Read sprite and palette.
  [out] | max_sprite_offset | Optionally returns the number of sprites in the spriteset of the sprite. (0 if no spritset)
  [out] | max_palette_offset | Optionally returns the number of sprites in the spriteset of the palette. (0 if no spritset)

Returns
  Read TileLayoutFlags.

Definition at line 63 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_grfid | The grfID which wants to override another NewGRF.
  target_grfid | The grfID which is being overridden.

Definition at line 181 of file newgrf.cpp.

Referenced by LoadNewGRF().

## ◆ SkipBadgeList()

void SkipBadgeList | ( | ByteReader & | buf | ) |

Skip a list of badges.

Parameters

  buf | Buffer 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 315 of file newgrf.cpp.

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

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

## Variable Documentation

## ◆ _cur_gps

GrfProcessingState _cur_gps
| extern

Definition at line 76 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 71 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.