OpenTTD Source: src/newgrf.h File Reference

OpenTTD Source 15.3

Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
newgrf.h File Reference

Base for the NewGRF implementation. More...

`#include "cargotype.h"`
`#include "rail_type.h"`
`#include "road_type.h"`
`#include "fileio_type.h"`
`#include "newgrf_badge_type.h"`
`#include "newgrf_callbacks.h"`
`#include "newgrf_text_type.h"`

Go to the source code of this file.

## Data Structures
struct | CanalProperties
| Canal properties local to the NewGRF. More...
struct | GRFLabel
struct | GRFFile
| Dynamic data of a loaded NewGRF. More...
struct | GRFLoadedFeatures
struct | PriceBaseSpec
| Describes properties of price bases. More...

## Macros
#define | GrfMsg(severity, format_string, ...) do { if ((severity) == 0 || _debug_grf_level >= (severity)) GrfMsgI(severity, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)

## Typedefs
using | GrfMiscBits = EnumBitSet< GrfMiscBit, uint8_t >
using | GrfSpecFeatures = EnumBitSet< GrfSpecFeature, uint32_t, GrfSpecFeature::GSF_END >

## Enumerations
enum | CanalFeature : uint8_t { CF_WATERSLOPE , CF_LOCKS , CF_DIKES , CF_ICON , CF_DOCKS , CF_RIVER_SLOPE , CF_RIVER_EDGE , CF_RIVER_GUI , CF_BUOY , CF_END }
| List of different canal 'features'. More...
enum | GrfLoadingStage : uint8_t { GLS_FILESCAN , GLS_SAFETYSCAN , GLS_LABELSCAN , GLS_INIT , GLS_RESERVE , GLS_ACTIVATION , GLS_END }
enum class | GrfMiscBit : uint8_t { DesertTreesFields = 0 , DesertPavedRoads = 1 , FieldBoundingBox = 2 , TrainWidth32Pixels = 3 , AmbientSoundCallback = 4 , CatenaryOn3rdTrack = 5 , SecondRockyTileSet = 6 }
enum | GrfSpecFeature : uint8_t { GSF_TRAINS , GSF_ROADVEHICLES , GSF_SHIPS , GSF_AIRCRAFT , GSF_STATIONS , GSF_CANALS , GSF_BRIDGES , GSF_HOUSES , GSF_GLOBALVAR , GSF_INDUSTRYTILES , GSF_INDUSTRIES , GSF_CARGOES , GSF_SOUNDFX , GSF_AIRPORTS , GSF_SIGNALS , GSF_OBJECTS , GSF_RAILTYPES , GSF_AIRPORTTILES , GSF_ROADTYPES , GSF_TRAMTYPES , GSF_ROADSTOPS , GSF_BADGES , GSF_END , GSF_DEFAULT = GSF_END , GSF_FAKE_TOWNS = GSF_END , GSF_FAKE_END , GSF_ORIGINAL_STRINGS = 0x48 , GSF_INVALID = 0xFF }
enum | ShoreReplacement : uint8_t { SHORE_REPLACE_NONE , SHORE_REPLACE_ACTION_5 , SHORE_REPLACE_ACTION_A , SHORE_REPLACE_ONLY_NEW }
enum | TramReplacement : uint8_t { TRAMWAY_REPLACE_DEPOT_NONE , TRAMWAY_REPLACE_DEPOT_WITH_TRACK , TRAMWAY_REPLACE_DEPOT_NO_TRACK }

## Functions
bool | HasGrfMiscBit (GrfMiscBit bit)
| Check for grf miscellaneous bits.
void | LoadNewGRFFile (GRFConfig &config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
| Load a particular NewGRF.
void | LoadNewGRF (SpriteID load_index, uint num_baseset)
| Load all the NewGRFs.
void | ReloadNewGRFData ()
| Reload all NewGRF files during a running game.
void | ResetNewGRFData ()
| Reset all NewGRF loaded data.
void | ResetPersistentNewGRFData ()
| Reset NewGRF data which is stored persistently in savegames.
void | GrfMsgI (int severity, const std::string &msg)
| Debug() function dedicated to newGRF debugging messages Function is essentially the same as Debug(grf, severity, ...) with the addition of file:line information when parsing grf files.
bool | GetGlobalVariable (uint8_t param, uint32_t *value, const GRFFile *grffile)
| Reads a variable common to VarAction2 and Action7/9/D.
StringID | MapGRFStringID (uint32_t grfid, GRFStringID str)
| Used when setting an object's property to map to the GRF's strings while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one.
void | ShowNewGRFError ()
| Show the first NewGRF error we can find.

## Variables
static const uint32_t | INVALID_GRFID = 0xFFFFFFFF
GRFLoadedFeatures | _loaded_newgrf_features
| Indicates which are the newgrf features currently loaded ingame.

## Detailed Description

Base for the NewGRF implementation.

Definition in file newgrf.h.

## Macro Definition Documentation

## ◆ GrfMsg

#define GrfMsg | ( |  | severity,
|  |  | format_string,
|  |  | ...
| ) |  | do { if ((severity) == 0 || _debug_grf_level >= (severity)) GrfMsgI(severity, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)

Definition at line 226 of file newgrf.h.

## Typedef Documentation

## ◆ GrfMiscBits

using GrfMiscBits = EnumBitSet<GrfMiscBit, uint8_t>

Definition at line 66 of file newgrf.h.

## ◆ GrfSpecFeatures

using GrfSpecFeatures = EnumBitSet<GrfSpecFeature, uint32_t, GrfSpecFeature::GSF_END>

Definition at line 101 of file newgrf.h.

## Enumeration Type Documentation

## ◆ CanalFeature

enum CanalFeature : uint8_t

List of different canal 'features'.

Each feature gets an entry in the canal spritegroup table

Definition at line 25 of file newgrf.h.

## ◆ GrfLoadingStage

enum GrfLoadingStage : uint8_t

Definition at line 44 of file newgrf.h.

## ◆ GrfMiscBit

enum class GrfMiscBit : uint8_t
| strong

Enumerator
TrainWidth32Pixels | Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable;. See also GRFFile::traininfo_vehicle_width

Definition at line 56 of file newgrf.h.

## ◆ GrfSpecFeature

enum GrfSpecFeature : uint8_t

Enumerator
GSF_DEFAULT | Unspecified feature, default badge.
GSF_FAKE_TOWNS | Fake town GrfSpecFeature for NewGRF debugging (parent scope)
GSF_FAKE_END | End of the fake features.
GSF_INVALID | An invalid spec feature.

Definition at line 68 of file newgrf.h.

## ◆ ShoreReplacement

enum ShoreReplacement : uint8_t

Enumerator
SHORE_REPLACE_NONE | No shore sprites were replaced.
SHORE_REPLACE_ACTION_5 | Shore sprites were replaced by Action5.
SHORE_REPLACE_ACTION_A | Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).
SHORE_REPLACE_ONLY_NEW | Only corner-shores were loaded by Action5 (openttd(w/d).grf only).

Definition at line 175 of file newgrf.h.

## ◆ TramReplacement

enum TramReplacement : uint8_t

Enumerator
TRAMWAY_REPLACE_DEPOT_NONE | No tram depot graphics were loaded.
TRAMWAY_REPLACE_DEPOT_WITH_TRACK | Electrified depot graphics with tram track were loaded.
TRAMWAY_REPLACE_DEPOT_NO_TRACK | Electrified depot graphics without tram track were loaded.

Definition at line 182 of file newgrf.h.

## Function Documentation

## ◆ GetGlobalVariable()

bool GetGlobalVariable | ( | uint8_t | param,
|  | uint32_t * | value,
|  | const GRFFile * | grffile
| ) |  |

Reads a variable common to VarAction2 and Action7/9/D.

Returns VarAction2 variable 'param' resp. Action7/9/D variable '0x80 + param'. If a variable is not accessible from all four actions, it is handled in the action specific functions.

Parameters

  param | variable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first).
  value | returns the value of the variable.
  grffile | NewGRF querying the variable

Returns
  true iff the variable is known and the value is returned in 'value'.

Definition at line 422 of file newgrf_act0_globalvar.cpp.

References _misc_grf_features, _settings_game, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::base(), Clamp(), GameSettings::construction, TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate(), TimerGameTick::counter, TimerGameCalendar::date, TimerGameCalendar::date_fract, TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, VehicleSettings::disable_elrails, GameSettings::game_creation, GB(), GetGRFConfig(), GetRailTypeInfo(), GetSnowLine(), GRFP_USE_MASK, TimerGame< struct Calendar >::IsLeapYear(), GameCreationSettings::landscape, ConstructionSettings::map_height_limit, TimerGameConst< struct Calendar >::ORIGINAL_BASE_YEAR, TimerGameConst< struct Calendar >::ORIGINAL_MAX_YEAR, GRFConfig::palette, RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, RAILTYPE_MONO, RAILTYPE_RAIL, VehicleSettings::road_side, SB(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SP_CUSTOM, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TILE_HEIGHT, to_underlying(), GRFFile::traininfo_vehicle_pitch, GRFFile::traininfo_vehicle_width, TrainWidth32Pixels, GameSettings::vehicle, and TimerGameCalendar::year.

## ◆ GrfMsgI()

void GrfMsgI | ( | int | severity,
|  | const std::string & | msg
| ) |  |

Debug() function dedicated to newGRF debugging messages Function is essentially the same as Debug(grf, severity, ...) with the addition of file:line information when parsing grf files.

NOTE: for the above reason(s) GrfMsg() should ONLY be used for loading/parsing grf files, not for runtime debug messages as there is no file information available during that time.

Parameters

  severity | debugging severity level, see debug.h
  msg | the message

Definition at line 90 of file newgrf.cpp.

References Debug, GRFConfig::filename, GrfProcessingState::grfconfig, and GrfProcessingState::nfo_line.

## ◆ HasGrfMiscBit()

bool HasGrfMiscBit | ( | GrfMiscBit | bit | ) |
| inline

Check for grf miscellaneous bits.

Parameters

  bit | The bit to check.

Returns
  Whether the bit is set.

Definition at line 210 of file newgrf.h.

References _misc_grf_features, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by AmbientSoundEffect(), and DrawRoadAsSnowOrDesert().

## ◆ LoadNewGRF()

void LoadNewGRF | ( | SpriteID | load_index,
|  | uint | num_baseset
| ) |  |

Load all the NewGRFs.

Parameters

  load_index | The offset for the first sprite to add.
  num_baseset | Number of NewGRFs at the front of the list to look up in the baseset dir instead of the newgrf dir.

Definition at line 1758 of file newgrf.cpp.

References _display_opt, _grfconfig, _networking, _settings_game, AfterLoadGRFs(), BASESET_DIR, BuildCargoTranslationMap(), GrfProcessingState::ClearDataForNextFile(), ClearTemporaryNewGRFData(), TimerGameCalendar::ConvertYMDToDate(), TimerGameEconomy::ConvertYMDToDate(), TimerGameTick::counter, TimerGameCalendar::date, TimerGameEconomy::date, TimerGameCalendar::date_fract, TimerGameEconomy::date_fract, Debug, FioCheckFileExists(), GameSettings::game_creation, GCS_ACTIVATED, GCS_DISABLED, GCS_INITIALISED, GCS_NOT_FOUND, GCS_UNKNOWN, GetFileByGRFID(), GrfProcessingState::grfconfig, GrfProcessingState::grffile, InitializePatchFlags(), InitNewGRFFile(), InitOnly, LoadNewGRFFile(), NETWORK_MAX_GRF_COUNT, NEWGRF_DIR, Reserved, ResetNewGRFData(), SetNewGRFOverride(), GrfProcessingState::spriteid, GrfProcessingState::stage, GameCreationSettings::starting_year, Static, System, TimerGameCalendar::year, and TimerGameEconomy::year.

Referenced by LoadSpriteTables().

## ◆ LoadNewGRFFile()

void LoadNewGRFFile | ( | GRFConfig & | config,
|  | GrfLoadingStage | stage,
|  | Subdirectory | subdir,
|  | bool | temporary
| ) |  |

Load a particular NewGRF.

Parameters

  config | The configuration of the to be loaded NewGRF.
  stage | The loading stage of the NewGRF.
  subdir | The sub directory to find the NewGRF in.
  temporary | The NewGRF/sprite file is to be loaded temporarily and should be closed immediately, contrary to loading the SpriteFile and having it cached by the SpriteCache.

Definition at line 1391 of file newgrf.cpp.

References GRFConfig::filename, GRFConfig::flags, GCS_INITIALISED, GetFileByFilename(), GrfProcessingState::grffile, GRFP_USE_MASK, LoadNewGRFFileFromFile(), OpenCachedSpriteFile(), GRFConfig::palette, Reserved, GRFConfig::status, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by FillGRFDetails(), and LoadNewGRF().

## ◆ MapGRFStringID()

StringID MapGRFStringID | ( | uint32_t | grfid,
|  | GRFStringID | str
| ) |  |

Used when setting an object's property to map to the GRF's strings while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one.

Parameters

  grfid | Id of the grf file.
  str | GRF-local GRFStringID that we want to have the equivalent in OpenTTD.

Returns
  The properly adjusted StringID.

Definition at line 129 of file newgrf_stringmapping.cpp.

References GetGRFStringID(), IsInsideMM(), and TTDPStringIDToOTTDStringIDMapping().

Referenced by ChangeIndustryProduction(), FinaliseStringMapping(), ProcessNewGRFStringControlCode(), and TranslateTTDPatchCodes().

## ◆ ReloadNewGRFData()

void ReloadNewGRFData | ( |  | ) |

Reload all NewGRF files during a running game.

This is a cut-down version of AfterLoadGame(). XXX - We need to reset the vehicle position hash because with a non-empty hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles() to recalculate vehicle data as some NewGRF vehicle sets could have been removed or added and changed statistics

Definition at line 3445 of file afterload.cpp.

References AfterLoadCompanyStats(), AfterLoadLabelMaps(), AfterLoadVehiclesPhase1(), AfterLoadVehiclesPhase2(), CheckTrainsLengths(), DeleteInvalidEngineNews(), GfxLoadSprites(), InvalidateWindowClassesData(), InvalidateWindowData(), LoadStringWidthTable(), MarkWholeScreenDirty(), RecomputePrices(), StartupEngines(), GroupStatistics::UpdateAfterLoad(), UpdateHousesAndTowns(), WC_BUILD_TOOLBAR, WC_COMPANY_COLOUR, and WC_COMPANY_INFRASTRUCTURE.

Referenced by ClickChangeMaxHlCheat(), NewGRFWindow::Close(), NewGRFConfirmationCallback(), and EngineOverrideManager::ResetToCurrentNewGRFConfig().

## ◆ ResetNewGRFData()

void ResetNewGRFData | ( |  | ) |

Reset all NewGRF loaded data.

Definition at line 408 of file newgrf.cpp.

References _gted, _loaded_newgrf_features, _misc_grf_features, _settings_game, _water_feature, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::CleanPool(), CleanUpStrings(), ClearSnowLine(), GameSettings::game_creation, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetPoolSize(), GetRailTypeInfo(), GRFLoadedFeatures::has_2CC, Engine::IterateType(), RailTypeInfo::label, GameCreationSettings::landscape, NewGRFClass< Tspec, Tindex, Tmax >::Reset(), AirportSpec::ResetAirports(), AirportTileSpec::ResetAirportTiles(), ResetBadges(), ResetBridges(), ResetCurrencies(), ResetFaces(), ResetGenericCallbacks(), ResetIndustries(), ResetNewGRF(), ResetNewGRFErrors(), ResetObjects(), ResetPriceBaseMultipliers(), ResetRailTypes(), ResetRoadTypes(), SetupCargoForClimate(), SetupEngines(), GRFLoadedFeatures::shore, SHORE_REPLACE_NONE, GRFLoadedFeatures::tram, TRAMWAY_REPLACE_DEPOT_NONE, GRFLoadedFeatures::used_liveries, and VEH_TRAIN.

Referenced by LoadNewGRF(), and ShutdownGame().

## ◆ ResetPersistentNewGRFData()

void ResetPersistentNewGRFData | ( |  | ) |

Reset NewGRF data which is stored persistently in savegames.

Definition at line 505 of file newgrf.cpp.

References OverrideManagerBase::ResetMapping(), and EngineOverrideManager::ResetToDefaultMapping().

## ◆ ShowNewGRFError()

void ShowNewGRFError | ( |  | ) |

Show the first NewGRF error we can find.

Definition at line 47 of file newgrf_gui.cpp.

References _grfconfig, GRFError::custom_message, GRFError::data, GetEncodedStringWithArgs(), GRFError::message, GRFError::param_value, GRFError::severity, ShowErrorMessage(), WL_CRITICAL, and WL_ERROR.

Referenced by _GenerateWorld(), and InitializeWindowsAndCaches().

## Variable Documentation

## ◆ _loaded_newgrf_features

GRFLoadedFeatures _loaded_newgrf_features
| extern

Indicates which are the newgrf features currently loaded ingame.

Definition at line 74 of file newgrf.cpp.

Referenced by ActivateOldShore(), ActivateOldTramDepot(), AircraftVehicleChangeInfo(), DrawRoadDepotSprite(), DrawTile_Road(), SelectCompanyLiveryWindow::DrawWidget(), FinaliseEngineArray(), ObjectChangeInfo(), SelectCompanyLiveryWindow::OnClick(), SelectCompanyLiveryWindow::OnDropdownSelect(), SelectCompanyLiveryWindow::OnInvalidateData(), RailVehicleChangeInfo(), ResetNewGRFData(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), and SelectCompanyLiveryWindow::UpdateWidgetSize().

## ◆ INVALID_GRFID

const uint32_t INVALID_GRFID = 0xFFFFFFFF
| static

Definition at line 103 of file newgrf.h.