OpenTTD
Data Structures | Macros | Enumerations | Functions | Variables
newgrf_config.h File Reference

Functions to find and configure NewGRFs. More...

#include "strings_type.h"
#include "core/alloc_type.hpp"
#include "core/smallmap_type.hpp"
#include "misc/countedptr.hpp"
#include "fileio_type.h"
#include "textfile_type.h"

Go to the source code of this file.

Data Structures

struct  GRFIdentifier
 Basic data to distinguish a GRF. More...
 
struct  GRFError
 Information about why GRF had problems during initialisation. More...
 
struct  GRFParameterInfo
 Information about one grf parameter. More...
 
struct  GRFTextWrapper
 Reference counted wrapper around a GRFText pointer. More...
 
struct  GRFConfig
 Information about GRF, used in the game and (part of it) in savegames. More...
 
struct  NewGRFScanCallback
 Callback for NewGRF scanning. More...
 

Macros

#define UNKNOWN_GRF_NAME_PLACEHOLDER   "<Unknown>"
 For communication about GRFs over the network.
 

Enumerations

enum  GCF_Flags {
  GCF_SYSTEM, GCF_UNSAFE, GCF_STATIC, GCF_COMPATIBLE,
  GCF_COPY, GCF_INIT_ONLY, GCF_RESERVED, GCF_INVALID
}
 GRF config bit flags. More...
 
enum  GRFStatus {
  GCS_UNKNOWN, GCS_DISABLED, GCS_NOT_FOUND, GCS_INITIALISED,
  GCS_ACTIVATED
}
 Status of GRF. More...
 
enum  GRFBugs {
  GBUG_VEH_LENGTH, GBUG_VEH_REFIT, GBUG_VEH_POWERED_WAGON, GBUG_UNKNOWN_CB_RESULT,
  GBUG_VEH_CAPACITY
}
 Encountered GRF bugs. More...
 
enum  GRFListCompatibility { GLC_ALL_GOOD, GLC_COMPATIBLE, GLC_NOT_FOUND }
 Status of post-gameload GRF compatibility check. More...
 
enum  GRFPalette {
  GRFP_USE_BIT = 0, GRFP_GRF_OFFSET = 2, GRFP_GRF_SIZE = 2, GRFP_BLT_OFFSET = 4,
  GRFP_BLT_SIZE = 1, GRFP_USE_DOS = 0x0, GRFP_USE_WINDOWS = 0x1, GRFP_USE_MASK = 0x1,
  GRFP_GRF_UNSET = 0x0 << GRFP_GRF_OFFSET, GRFP_GRF_DOS = 0x1 << GRFP_GRF_OFFSET, GRFP_GRF_WINDOWS = 0x2 << GRFP_GRF_OFFSET, GRFP_GRF_ANY = GRFP_GRF_DOS | GRFP_GRF_WINDOWS,
  GRFP_GRF_MASK = GRFP_GRF_ANY, GRFP_BLT_UNSET = 0x0 << GRFP_BLT_OFFSET, GRFP_BLT_32BPP = 0x1 << GRFP_BLT_OFFSET, GRFP_BLT_MASK = GRFP_BLT_32BPP
}
 Information that can/has to be stored about a GRF's palette. More...
 
enum  GRFParameterType { PTYPE_UINT_ENUM, PTYPE_BOOL, PTYPE_END }
 The possible types of a newgrf parameter. More...
 
enum  FindGRFConfigMode {
  FGCM_EXACT, FGCM_COMPATIBLE, FGCM_NEWEST, FGCM_NEWEST_VALID,
  FGCM_ANY
}
 Method to find GRFs using FindGRFConfig. More...
 

Functions

size_t GRFGetSizeOfDataSection (FILE *f)
 Get the data section size of a GRF. More...
 
void ScanNewGRFFiles (NewGRFScanCallback *callback)
 Scan for all NewGRFs. More...
 
const GRFConfigFindGRFConfig (uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum=NULL, uint32 desired_version=0)
 Find a NewGRF in the scanned list. More...
 
GRFConfigGetGRFConfig (uint32 grfid, uint32 mask=0xFFFFFFFF)
 Retrieve a NewGRF from the current config by its grfid. More...
 
GRFConfig ** CopyGRFConfigList (GRFConfig **dst, const GRFConfig *src, bool init_only)
 Copy a GRF Config list. More...
 
void AppendStaticGRFConfigs (GRFConfig **dst)
 Appends the static GRFs to a list of GRFs. More...
 
void AppendToGRFConfigList (GRFConfig **dst, GRFConfig *el)
 Appends an element to a list of GRFs. More...
 
void ClearGRFConfigList (GRFConfig **config)
 Clear a GRF Config list, freeing all nodes. More...
 
void ResetGRFConfig (bool defaults)
 Reset the current GRF Config to either blank or newgame settings. More...
 
GRFListCompatibility IsGoodGRFConfigList (GRFConfig *grfconfig)
 Check if all GRFs in the GRF config from a savegame can be loaded. More...
 
bool FillGRFDetails (GRFConfig *config, bool is_static, Subdirectory subdir=NEWGRF_DIR)
 Find the GRFID of a given grf, and calculate its md5sum. More...
 
char * GRFBuildParamList (char *dst, const GRFConfig *c, const char *last)
 Build a string containing space separated parameter values, and terminate.
 
void ShowNewGRFSettings (bool editable, bool show_params, bool exec_changes, GRFConfig **config)
 Setup the NewGRF gui. More...
 
GRFTextWrapperFindUnknownGRFName (uint32 grfid, uint8 *md5sum, bool create)
 Finds the name of a NewGRF in the list of names for unknown GRFs. More...
 
void UpdateNewGRFScanStatus (uint num, const char *name)
 Update the NewGRF scan status. More...
 
bool UpdateNewGRFConfigPalette (int32 p1=0)
 Update the palettes of the graphics from the config file. More...
 

Variables

GRFConfig_all_grfs
 First item in list of all scanned NewGRFs.
 
GRFConfig_grfconfig
 First item in list of current GRF set up.
 
GRFConfig_grfconfig_newgame
 First item in list of default GRF set up.
 
GRFConfig_grfconfig_static
 First item in list of static GRF set up.
 
uint _missing_extra_graphics
 Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
 

Detailed Description

Functions to find and configure NewGRFs.

Definition in file newgrf_config.h.

Enumeration Type Documentation

◆ FindGRFConfigMode

Method to find GRFs using FindGRFConfig.

Enumerator
FGCM_EXACT 

Only find Grfs matching md5sum.

FGCM_COMPATIBLE 

Find best compatible Grf wrt. desired_version.

FGCM_NEWEST 

Find newest Grf.

FGCM_NEWEST_VALID 

Find newest Grf, ignoring Grfs with GCF_INVALID set.

FGCM_ANY 

Use first found.

Definition at line 193 of file newgrf_config.h.

◆ GCF_Flags

enum GCF_Flags

GRF config bit flags.

Enumerator
GCF_SYSTEM 

GRF file is an openttd-internal system grf.

GCF_UNSAFE 

GRF file is unsafe for static usage.

GCF_STATIC 

GRF file is used statically (can be used in any MP game)

GCF_COMPATIBLE 

GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)

GCF_COPY 

The data is copied from a grf in _all_grfs.

GCF_INIT_ONLY 

GRF file is processed up to GLS_INIT.

GCF_RESERVED 

GRF file passed GLS_RESERVE stage.

GCF_INVALID 

GRF is unusable with this version of OpenTTD.

Definition at line 23 of file newgrf_config.h.

◆ GRFBugs

enum GRFBugs

Encountered GRF bugs.

Enumerator
GBUG_VEH_LENGTH 

Length of rail vehicle changes when not inside a depot.

GBUG_VEH_REFIT 

Articulated vehicles carry different cargoes resp. are differently refittable than specified in purchase list.

GBUG_VEH_POWERED_WAGON 

Powered wagon changed poweredness state when not inside a depot.

GBUG_UNKNOWN_CB_RESULT 

A callback returned an unknown/invalid result.

GBUG_VEH_CAPACITY 

Capacity of vehicle changes when not refitting or arranging.

Definition at line 44 of file newgrf_config.h.

◆ GRFListCompatibility

Status of post-gameload GRF compatibility check.

Enumerator
GLC_ALL_GOOD 

All GRF needed by game are present.

GLC_COMPATIBLE 

Compatible (eg. the same ID, but different checksum) GRF found in at least one case.

GLC_NOT_FOUND 

At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)

Definition at line 53 of file newgrf_config.h.

◆ GRFPalette

enum GRFPalette

Information that can/has to be stored about a GRF's palette.

Enumerator
GRFP_USE_BIT 

The bit used for storing the palette to use.

GRFP_GRF_OFFSET 

The offset of the GRFP_GRF data.

GRFP_GRF_SIZE 

The size of the GRFP_GRF data.

GRFP_BLT_OFFSET 

The offset of the GRFP_BLT data.

GRFP_BLT_SIZE 

The size of the GRFP_BLT data.

GRFP_USE_DOS 

The palette state is set to use the DOS palette.

GRFP_USE_WINDOWS 

The palette state is set to use the Windows palette.

GRFP_USE_MASK 

Bitmask to get only the use palette use states.

GRFP_GRF_UNSET 

The NewGRF provided no information.

GRFP_GRF_DOS 

The NewGRF says the DOS palette can be used.

GRFP_GRF_WINDOWS 

The NewGRF says the Windows palette can be used.

GRFP_GRF_ANY 

The NewGRF says any palette can be used.

GRFP_GRF_MASK 

Bitmask to get only the NewGRF supplied information.

GRFP_BLT_UNSET 

The NewGRF provided no information or doesn't care about a 32 bpp blitter.

GRFP_BLT_32BPP 

The NewGRF prefers a 32 bpp blitter.

GRFP_BLT_MASK 

Bitmask to only get the blitter information.

Definition at line 60 of file newgrf_config.h.

◆ GRFParameterType

The possible types of a newgrf parameter.

Enumerator
PTYPE_UINT_ENUM 

The parameter allows a range of numbers, each of which can have a special name.

PTYPE_BOOL 

The parameter is either 0 or 1.

PTYPE_END 

Invalid parameter type.

Definition at line 116 of file newgrf_config.h.

◆ GRFStatus

enum GRFStatus

Status of GRF.

Enumerator
GCS_UNKNOWN 

The status of this grf file is unknown.

GCS_DISABLED 

GRF file is disabled.

GCS_NOT_FOUND 

GRF file was not found in the local cache.

GCS_INITIALISED 

GRF file has been initialised.

GCS_ACTIVATED 

GRF file has been activated.

Definition at line 35 of file newgrf_config.h.

Function Documentation

◆ AppendStaticGRFConfigs()

void AppendStaticGRFConfigs ( GRFConfig **  dst)

Appends the static GRFs to a list of GRFs.

Parameters
dstthe head of the list to add to

Definition at line 514 of file newgrf_config.cpp.

References CopyGRFConfigList(), GRFConfig::next, and RemoveDuplicatesFromGRFConfigList().

Referenced by ResetGRFConfig(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ AppendToGRFConfigList()

void AppendToGRFConfigList ( GRFConfig **  dst,
GRFConfig el 
)

Appends an element to a list of GRFs.

Parameters
dstthe head of the list to add to
elthe new tail to be

Definition at line 528 of file newgrf_config.cpp.

References GRFConfig::next, and RemoveDuplicatesFromGRFConfigList().

Referenced by NewGRFScanCallback::~NewGRFScanCallback().

◆ ClearGRFConfigList()

void ClearGRFConfigList ( GRFConfig **  config)

Clear a GRF Config list, freeing all nodes.

Parameters
configStart of the list.
Postcondition
config is set to NULL.

Definition at line 444 of file newgrf_config.cpp.

References GRFConfig::next.

Referenced by LoadCheckData::Clear(), CopyGRFConfigList(), DoScanNewGRFFiles(), NetworkGameListHandleDelayedInsert(), NetworkGameListRemoveItem(), NewGRFWindow::OnDropdownSelect(), ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ CopyGRFConfigList()

GRFConfig** CopyGRFConfigList ( GRFConfig **  dst,
const GRFConfig src,
bool  init_only 
)

Copy a GRF Config list.

Parameters
dstpointer to destination list
srcpointer to source list values
init_onlythe copied GRF will be processed up to GLS_INIT
Returns
pointer to the last value added to the destination list

Definition at line 462 of file newgrf_config.cpp.

References ClearGRFConfigList(), ClrBit(), GRFConfig::flags, GCF_INIT_ONLY, GRFConfig::next, and SetBit().

Referenced by AppendStaticGRFConfigs(), NewGRFConfirmationCallback(), ResetGRFConfig(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ FillGRFDetails()

bool FillGRFDetails ( GRFConfig config,
bool  is_static,
Subdirectory  subdir 
)

Find the GRFID of a given grf, and calculate its md5sum.

Parameters
configgrf to fill.
is_staticgrf is static.
subdirthe subdirectory to search in.
Returns
Operation was successfully completed.

Definition at line 412 of file newgrf_config.cpp.

References CONFIG_SLOT, GRFConfig::filename, FioCheckFileExists(), GCS_NOT_FOUND, LoadNewGRFFile(), and GRFConfig::status.

Referenced by GRFFileScanner::AddFile(), GRFLoadConfig(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ FindGRFConfig()

const GRFConfig* FindGRFConfig ( uint32  grfid,
FindGRFConfigMode  mode,
const uint8 *  md5sum,
uint32  desired_version 
)

Find a NewGRF in the scanned list.

Parameters
grfidGRFID to look for,
modeRestrictions for matching grfs
md5sumExpected MD5 sum
desired_versionRequested version
Returns
The matching grf, if it exists in _all_grfs, else NULL.

Definition at line 809 of file newgrf_config.cpp.

Referenced by GRFLoadConfig(), ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(), HasGRFConfig(), IsGoodGRFConfigList(), NewGRFWindow::OnInvalidateData(), PrintGrfInfo(), ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), NewGRFWindow::TagNameFilter(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ FindUnknownGRFName()

GRFTextWrapper* FindUnknownGRFName ( uint32  grfid,
uint8 *  md5sum,
bool  create 
)

Finds the name of a NewGRF in the list of names for unknown GRFs.

An unknown GRF is a GRF where the .grf is not found during scanning.

The names are resolved via UDP calls to servers that should know the name, though the replies may not come. This leaves "<Unknown>" as name, though that shouldn't matter very much as they need GRF crawler or so to look up the GRF anyway and that works better with the GRF ID.

Parameters
grfidthe GRF ID part of the 'unique' GRF identifier
md5sumthe MD5 checksum part of the 'unique' GRF identifier
createwhether to create a new GRFConfig if the GRFConfig did not exist in the fake list of GRFConfigs.
Returns
The GRFTextWrapper of the name of the GRFConfig with the given GRF ID and MD5 checksum or NULL when it does not exist and create is false. This value must NEVER be freed by the caller.

Definition at line 854 of file newgrf_config.cpp.

References AddGRFTextToList(), GRFIdentifier::grfid, GRFIdentifier::md5sum, UnknownGRF::name, UnknownGRF::next, GRFTextWrapper::text, and UNKNOWN_GRF_NAME_PLACEHOLDER.

Referenced by ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(), and ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS().

◆ GetGRFConfig()

GRFConfig* GetGRFConfig ( uint32  grfid,
uint32  mask 
)

Retrieve a NewGRF from the current config by its grfid.

Parameters
grfidgrf to look for.
maskGRFID mask to allow for partial matching.
Returns
The grf config, if it exists, else NULL.

Definition at line 889 of file newgrf_config.cpp.

References GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::next.

Referenced by ErrorUnknownCallbackResult(), ShowNewGrfVehicleError(), TranslateGRFStrings(), VehicleLengthChanged(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ GRFGetSizeOfDataSection()

size_t GRFGetSizeOfDataSection ( FILE *  f)

Get the data section size of a GRF.

Parameters
fGRF.
Returns
Size of the data section or SIZE_MAX if the file has no separate data section.

Definition at line 343 of file newgrf_config.cpp.

References _grf_cont_v2_sig, DEBUG, and MemCmpT().

Referenced by CalcGRFMD5Sum(), GraphicsSet::CheckMD5(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ IsGoodGRFConfigList()

GRFListCompatibility IsGoodGRFConfigList ( GRFConfig grfconfig)

Check if all GRFs in the GRF config from a savegame can be loaded.

Parameters
grfconfigGrfConfig to check
Returns
will return any of the following 3 values:
  • GLC_ALL_GOOD: No problems occurred, all GRF files were found and loaded
  • GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a compatible GRF with the same grfid was found and used instead
  • GLC_NOT_FOUND: For one or more GRF's no match was found at all

Definition at line 557 of file newgrf_config.cpp.

References BSWAP32(), DEBUG, FGCM_COMPATIBLE, FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), GRFConfig::flags, free(), GCF_COMPATIBLE, GCF_COPY, GCF_INVALID, GCS_NOT_FOUND, GLC_ALL_GOOD, GLC_COMPATIBLE, GLC_NOT_FOUND, GRFIdentifier::grfid, GRFParameterInfo::GRFParameterInfo(), GRFConfig::has_param_defaults, HasBit(), GRFConfig::ident, lastof, SmallVector< T, S >::Length(), GRFIdentifier::md5sum, md5sumToString(), GRFConfig::min_loadable_version, GRFConfig::name, GRFConfig::next, GRFConfig::num_valid_params, GRFConfig::param_info, SetBit(), stredup(), and GRFConfig::version.

Referenced by NewGRFScanCallback::~NewGRFScanCallback().

◆ ResetGRFConfig()

void ResetGRFConfig ( bool  defaults)

Reset the current GRF Config to either blank or newgame settings.

Definition at line 539 of file newgrf_config.cpp.

References AppendStaticGRFConfigs(), and CopyGRFConfigList().

Referenced by AfterNewGRFScan::OnNewGRFsScanned(), and NewGRFScanCallback::~NewGRFScanCallback().

◆ ScanNewGRFFiles()

void ScanNewGRFFiles ( NewGRFScanCallback callback)

◆ ShowNewGRFSettings()

void ShowNewGRFSettings ( bool  editable,
bool  show_params,
bool  exec_changes,
GRFConfig **  config 
)

Setup the NewGRF gui.

Parameters
editableallow the user to make changes to the grfconfig in the window
show_paramsshow information about what parameters are set for the grf files
exec_changesif changes are made to the list (editable is true), apply these changes immediately or only update the list
configpointer to a linked-list of grfconfig's that will be shown

Definition at line 2005 of file newgrf_gui.cpp.

References DeleteWindowByClass(), and WC_GAME_OPTIONS.

Referenced by NewGRFScanCallback::~NewGRFScanCallback().

◆ UpdateNewGRFConfigPalette()

bool UpdateNewGRFConfigPalette ( int32  p1)

Update the palettes of the graphics from the config file.

Called when changing the default palette in advanced settings.

Parameters
p1Unused.
Returns
Always true.

Definition at line 330 of file newgrf_config.cpp.

References GRFConfig::next.

Referenced by AfterNewGRFScan::OnNewGRFsScanned().

◆ UpdateNewGRFScanStatus()

void UpdateNewGRFScanStatus ( uint  num,
const char *  name 
)

Update the NewGRF scan status.

Parameters
numThe number of NewGRFs scanned so far.
nameThe name of the last scanned NewGRF.

Definition at line 2279 of file newgrf_gui.cpp.

References FindWindowByClass(), ScanProgressWindow::UpdateNewGRFScanStatus(), and WC_MODAL_PROGRESS.

Referenced by GRFFileScanner::AddFile(), and ScanNewGRFFiles().