OpenTTD Source 20260621-master-g720d10536d
newgrf.h File Reference

Base for the NewGRF implementation. More...

#include "cargotype.h"
#include "livery.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"
#include "vehicle_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
 State of features loaded by NewGRFs. More...
struct  PriceBaseSpec
 Describes properties of price bases. More...

Macros

#define GrfMsg(severity, format_string, ...)

Typedefs

using CanalFeatureFlags = EnumBitSet<CanalFeatureFlag, uint8_t>
 CanalFeatureFlag bitmask.
using GrfMiscBits = EnumBitSet<GrfMiscBit, uint8_t>
 Bitset of GrfMiscBit elements.
using GrfSpecFeatures = EnumBitSet<GrfSpecFeature, uint32_t, GrfSpecFeature::End>
 Bitset of GrfSpecFeature elements.

Enumerations

enum class  CanalFeature : uint8_t {
  LockWaterSlope , Locks , Dikes , Icon ,
  FlatDocks , RiverSlope , RiverEdge , RiverIcon ,
  Buoy , End
}
 List of different canal 'features'. More...
enum class  CanalFeatureFlag : uint8_t { HasFlatSprite = 0 }
 Flags controlling the display of canals. More...
enum class  GrfLoadingStage : uint8_t {
  FileScan , SafetyScan , LabelScan , Init ,
  Reserve , Activation , End
}
 Stages of loading all NewGRFs. More...
enum class  GrfMiscBit : uint8_t {
  DesertTreesFields = 0 , DesertPavedRoads = 1 , FieldBoundingBox = 2 , TrainWidth32Pixels = 3 ,
  AmbientSoundCallback = 4 , CatenaryOn3rdTrack = 5 , SecondRockyTileSet = 6
}
 Bits of NewGRF's GlobalVariable 1E/9E. More...
enum class  GrfSpecFeature : uint8_t {
  Trains , RoadVehicles , Ships , Aircraft ,
  Stations , Canals , Bridges , Houses ,
  GlobalVar , IndustryTiles , Industries , Cargoes ,
  SoundEffects , Airports , Signals , Objects ,
  RailTypes , AirportTiles , RoadTypes , TramTypes ,
  RoadStops , Badges , End , Default = End ,
  FakeTowns = End , FakeEnd , OriginalStrings = 0x48 , Invalid = 0xFF
}
enum class  ShoreReplacement : uint8_t { None , Action5 , ActionA , OnlyNew }
 Type of shore replacement loaded by NewGRFs. More...
enum class  TramDepotReplacement : uint8_t { None , WithTrack , WithoutTrack }
 Type of tram depot replacement loaded by NewGRFs. More...

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.
GrfSpecFeature GetGrfSpecFeature (VehicleType type)
 Get the GrfSpecFeature associated with a VehicleType.
VehicleType GetVehicleType (GrfSpecFeature feature)
 Get the VehicleType associated with a GrfSpecFeature.

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,
... )
Value:
do { if ((severity) == 0 || _debug_grf_level >= (severity)) GrfMsgI(severity, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)
void GrfMsgI(int severity, const std::string &msg)
Debug() function dedicated to newGRF debugging messages Function is essentially the same as Debug(grf...
Definition newgrf.cpp:91

Definition at line 247 of file newgrf.h.

Typedef Documentation

◆ CanalFeatureFlags

CanalFeatureFlag bitmask.

Definition at line 47 of file newgrf.h.

◆ GrfMiscBits

using GrfMiscBits = EnumBitSet<GrfMiscBit, uint8_t>

Bitset of GrfMiscBit elements.

Definition at line 78 of file newgrf.h.

◆ GrfSpecFeatures

Bitset of GrfSpecFeature elements.

Definition at line 115 of file newgrf.h.

Enumeration Type Documentation

◆ CanalFeature

enum class CanalFeature : uint8_t
strong

List of different canal 'features'.

Each feature gets an entry in the canal spritegroup table

Enumerator
LockWaterSlope 

The sloped water tiles in locks.

Locks 

The sides of the lock.

Dikes 

The canal dikes/embankment.

Icon 

Unused: the TTDP UI icon for canals.

FlatDocks 

Unused: the graphics for TTDP flat docks.

RiverSlope 

The sloped water tiles for rivers.

RiverEdge 

The river banks.

RiverIcon 

Unused: the TTDP UI icons for rivers.

Buoy 

Buoy without underlying water.

End 

End marker.

Definition at line 29 of file newgrf.h.

◆ CanalFeatureFlag

enum class CanalFeatureFlag : uint8_t
strong

Flags controlling the display of canals.

Enumerator
HasFlatSprite 

Additional flat ground sprite in the beginning.

Definition at line 43 of file newgrf.h.

◆ GrfLoadingStage

enum class GrfLoadingStage : uint8_t
strong

Stages of loading all NewGRFs.

Enumerator
FileScan 

Load the Action 8 metadata (GRF ID, name).

SafetyScan 

Checks whether the NewGRF can be used in a static context.

LabelScan 

First step of NewGRF loading; find the 'goto' labels in the NewGRF.

Init 

Second step of NewGRF loading; load all actions into memory.

Reserve 

Third step of NewGRF loading; reserve features and GRMs.

Activation 

Forth step of NewGRF loading; activate the features.

End 

End marker.

Definition at line 56 of file newgrf.h.

◆ GrfMiscBit

enum class GrfMiscBit : uint8_t
strong

Bits of NewGRF's GlobalVariable 1E/9E.

Enumerator
DesertTreesFields 

Unsupported: allow trees and fields in desert climate.

DesertPavedRoads 

Show pavement and lights in desert towns.

FieldBoundingBox 

Unsupported: fields have a height.

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
AmbientSoundCallback 

Enable ambient sound effect callback 144.

CatenaryOn3rdTrack 

Unsupported: enable catenaries over third track type.

SecondRockyTileSet 

Enable using the second rocky tile set.

Definition at line 67 of file newgrf.h.

◆ GrfSpecFeature

enum class GrfSpecFeature : uint8_t
strong
Enumerator
Trains 

Trains feature.

RoadVehicles 

Road vehicles feature.

Ships 

Ships feature.

Aircraft 

Aircraft feature.

Stations 

Stations feature.

Canals 

Canals feature.

Bridges 

Bridges feature.

Houses 

Houses feature.

GlobalVar 

Global variables feature.

IndustryTiles 

Industry tiles feature.

Industries 

Industries feature.

Cargoes 

Cargoes feature.

SoundEffects 

Sound effects feature.

Airports 

Airports feature.

Signals 

Signals feature.

Objects 

Objects feature.

RailTypes 

Rail types feature.

AirportTiles 

Airport tiles feature.

RoadTypes 

Road types feature.

TramTypes 

Tram types feature.

RoadStops 

Road stops feature.

Badges 

Badges feature.

End 

End marker.

Default 

Unspecified feature, default badge.

FakeTowns 

Fake town GrfSpecFeature for NewGRF debugging (parent scope).

FakeEnd 

End of the fake features.

OriginalStrings 

Pseudo unsupported 'feature' for replacing original strings.

Invalid 

An invalid spec feature.

Definition at line 80 of file newgrf.h.

◆ ShoreReplacement

enum class ShoreReplacement : uint8_t
strong

Type of shore replacement loaded by NewGRFs.

Enumerator
None 

No shore sprites were replaced.

Action5 

Shore sprites were replaced by Action5.

ActionA 

Shore sprites were replaced by ActionA (using grass tiles for the corner-shores).

OnlyNew 

Only corner-shores were loaded by Action5 (openttd(w/d).grf only).

Definition at line 194 of file newgrf.h.

◆ TramDepotReplacement

enum class TramDepotReplacement : uint8_t
strong

Type of tram depot replacement loaded by NewGRFs.

Enumerator
None 

No tram depot graphics were loaded.

WithTrack 

Electrified depot graphics with tram track were loaded.

WithoutTrack 

Electrified depot graphics without tram track were loaded.

Definition at line 202 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
paramvariable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first).
valuereturns the value of the variable.
grffileNewGRF 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, Arctic, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::base(), Clamp(), TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate(), TimerGameTick::counter, TimerGameCalendar::date, TimerGameCalendar::date_fract, TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, GB(), GetGRFConfig(), GetRailTypeInfo(), GetSnowLine(), GRFP_USE_MASK, TimerGame< struct Calendar >::IsLeapYear(), TimerGameConst< struct Calendar >::ORIGINAL_BASE_YEAR, TimerGameConst< struct Calendar >::ORIGINAL_MAX_YEAR, GRFConfig::palette, RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, RAILTYPE_MONO, RAILTYPE_RAIL, 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, and TimerGameCalendar::year.

◆ GetGrfSpecFeature()

◆ GetVehicleType()

VehicleType GetVehicleType ( GrfSpecFeature feature)

Get the VehicleType associated with a GrfSpecFeature.

Parameters
featureThe feature.
Returns
the VehicleType

Definition at line 1909 of file newgrf.cpp.

References Aircraft, Invalid, Road, RoadVehicles, Ship, Ships, Train, and Trains.

Referenced by ParamSet().

◆ 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
severitydebugging severity level, see debug.h
msgthe message

Definition at line 91 of file newgrf.cpp.

References Debug.

◆ HasGrfMiscBit()

bool HasGrfMiscBit ( GrfMiscBit bit)
inline

Check for grf miscellaneous bits.

Parameters
bitThe bit to check.
Returns
Whether the bit is set.

Definition at line 231 of file newgrf.h.

References _misc_grf_features.

Referenced by AmbientSoundEffect(), DrawRoadAsSnowOrDesert(), and DrawTile_Clear().

◆ LoadNewGRF()

◆ LoadNewGRFFile()

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

Load a particular NewGRF.

Parameters
configThe configuration of the to be loaded NewGRF.
stageThe loading stage of the NewGRF.
subdirThe sub directory to find the NewGRF in.
temporaryThe 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 1398 of file newgrf.cpp.

References Activation, GRFConfig::filename, FileScan, GRFConfig::flags, GetFileByFilename(), GRFP_USE_MASK, Initialised, LabelScan, LoadNewGRFFileFromFile(), OpenCachedSpriteFile(), GRFConfig::palette, Reserve, Reserved, SafetyScan, 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
grfidId of the grf file.
strGRF-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 3480 of file afterload.cpp.

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

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

◆ ResetNewGRFData()

◆ ResetPersistentNewGRFData()

void ResetPersistentNewGRFData ( )

Reset NewGRF data which is stored persistently in savegames.

Definition at line 511 of file newgrf.cpp.

◆ ShowNewGRFError()

void ShowNewGRFError ( )

Variable Documentation

◆ _loaded_newgrf_features

◆ INVALID_GRFID

const uint32_t INVALID_GRFID = 0xFFFFFFFF
static

Definition at line 117 of file newgrf.h.