# newgrf.cpp File Reference

Base of all NewGRF support. More...

`#include "stdafx.h"`
`#include <stdarg.h>`
`#include "debug.h"`
`#include "fileio_func.h"`
`#include "engine_func.h"`
`#include "engine_base.h"`
`#include "bridge.h"`
`#include "town.h"`
`#include "newgrf_engine.h"`
`#include "newgrf_text.h"`
`#include "fontcache.h"`
`#include "currency.h"`
`#include "landscape.h"`
`#include "newgrf.h"`
`#include "newgrf_cargo.h"`
`#include "newgrf_house.h"`
`#include "newgrf_sound.h"`
`#include "newgrf_station.h"`
`#include "industrytype.h"`
`#include "newgrf_canal.h"`
`#include "newgrf_townname.h"`
`#include "newgrf_industries.h"`
`#include "newgrf_airporttiles.h"`
`#include "newgrf_airport.h"`
`#include "newgrf_object.h"`
`#include "rev.h"`
`#include "fios.h"`
`#include "strings_func.h"`
`#include "date_func.h"`
`#include "string_func.h"`
`#include "network/network.h"`
`#include <map>`
`#include "smallmap_gui.h"`
`#include "genworld.h"`
`#include "gui.h"`
`#include "vehicle_func.h"`
`#include "language.h"`
`#include "vehicle_base.h"`
`#include "table/strings.h"`
`#include "table/build_industry.h"`

Go to the source code of this file.

## Data Structures
class | OTTDByteReaderSignal
class | ByteReader
struct | GRFTempEngineData
struct | GRFLocation
struct | Action5Type
| Information about a single action 5 type. More...
struct | AllowedSubtags
| Data structure to store the allowed id/type combinations for action 14. More...
## Typedefs
typedef void(* | SpecialSpriteHandler )(ByteReader *buf)
typedef std::map< GRFLocation, byte * > | GRFLineToSpriteOverride
typedef std::map< StringID *, uint32 > | StringIDToGRFIDMapping
typedef ChangeInfoResult(* | VCI_Handler )(uint engine, int numinfo, int prop, ByteReader *buf)
typedef bool(* | DataHandler )(size_t, ByteReader *)
| Type of callback function for binary nodes.
typedef bool(* | TextHandler )(byte, const char *str)
| Type of callback function for text nodes.
typedef bool(* | BranchHandler )(ByteReader *)
| Type of callback function for branch nodes.
## Enumerations
enum | GrfDataType { GDT_SOUND }
enum | ChangeInfoResult { CIR_SUCCESS, CIR_UNHANDLED, CIR_UNKNOWN, CIR_INVALID_ID }
enum | Action5BlockType { A5BLOCK_FIXED, A5BLOCK_ALLOW_OFFSET, A5BLOCK_INVALID }
| The type of action 5 type. More...
## Functions
void CDECL | grfmsg (int severity, const char *str,...)
| DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf, severity, .
static GRFFile * | GetFileByGRFID (uint32 grfid)
static GRFFile * | GetFileByFilename (const char *filename)
static void | ClearTemporaryNewGRFData (GRFFile *gf)
| Reset all NewGRFData that was used only while processing data.
StringID | MapGRFStringID (uint32 grfid, StringID 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.
static uint8 | MapDOSColour (uint8 colour)
static void | SetNewGRFOverride (uint32 source_grfid, uint32 target_grfid)
static Engine * | GetNewEngine (const GRFFile *file, VehicleType type, uint16 internal_id, bool static_access=false)
| Returns the engine associated to a certain internal_id, resp.
EngineID | GetNewEngineID (const GRFFile *file, VehicleType type, uint16 internal_id)
static void | MapSpriteMappingRecolour (PalSpriteID *grf_sprite)
| Map the colour modifiers of TTDPatch to those that Open is using.
static void | ConvertTTDBasePrice (uint32 base_pointer, const char *error_location, Price *index)
| Converts TTD(P) Base Price pointers into the enum used by OTTD See http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts.
static ChangeInfoResult | CommonVehicleChangeInfo (EngineInfo *ei, int prop, ByteReader *buf)
static ChangeInfoResult | RailVehicleChangeInfo (uint engine, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | RoadVehicleChangeInfo (uint engine, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | ShipVehicleChangeInfo (uint engine, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | AircraftVehicleChangeInfo (uint engine, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | StationChangeInfo (uint stid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | CanalChangeInfo (uint id, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | BridgeChangeInfo (uint brid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | IgnoreTownHouseProperty (int prop, ByteReader *buf)
static ChangeInfoResult | TownHouseChangeInfo (uint hid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | GlobalVarChangeInfo (uint gvid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | GlobalVarReserveInfo (uint gvid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | CargoChangeInfo (uint cid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | SoundEffectChangeInfo (uint sid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | IgnoreIndustryTileProperty (int prop, ByteReader *buf)
static ChangeInfoResult | IndustrytilesChangeInfo (uint indtid, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | IgnoreIndustryProperty (int prop, ByteReader *buf)
static bool | ValidateIndustryLayout (const IndustryTileTable *layout, int size)
| Validate the industry layout; e.g.
static void | CleanIndustryTileTable (IndustrySpec *ind)
| Clean the tile table of the IndustrySpec if it's needed.
static ChangeInfoResult | IndustriesChangeInfo (uint indid, int numinfo, int prop, ByteReader *buf)
static void | DuplicateTileTable (AirportSpec *as)
| Create a copy of the tile table so it can be freed later without problems.
static ChangeInfoResult | AirportChangeInfo (uint airport, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | IgnoreObjectProperty (uint prop, ByteReader *buf)
static ChangeInfoResult | ObjectChangeInfo (uint id, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | RailTypeChangeInfo (uint id, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | RailTypeReserveInfo (uint id, int numinfo, int prop, ByteReader *buf)
static ChangeInfoResult | AirportTilesChangeInfo (uint airtid, int numinfo, int prop, ByteReader *buf)
static bool | HandleChangeInfoResult (const char *caller, ChangeInfoResult cir, uint8 feature, uint8 property)
static void | FeatureChangeInfo (ByteReader *buf)
static void | SafeChangeInfo (ByteReader *buf)
static void | ReserveChangeInfo (ByteReader *buf)
static void | NewSpriteSet (ByteReader *buf)
static void | SkipAct1 (ByteReader *buf)
static const SpriteGroup * | GetGroupFromGroupID (byte setid, byte type, uint16 groupid)
static const SpriteGroup * | CreateGroupFromGroupID (byte feature, byte setid, byte type, uint16 spriteid, uint16 num_sprites)
static void | NewSpriteGroup (ByteReader *buf)
static CargoID | TranslateCargo (uint8 feature, uint8 ctype)
static bool | IsValidGroupID (uint16 groupid, const char *function)
static void | VehicleMapSpriteGroup (ByteReader *buf, byte feature, uint8 idcount)
static void | CanalMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | StationMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | TownHouseMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | IndustryMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | IndustrytileMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | CargoMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | ObjectMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | RailTypeMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | AirportMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | AirportTileMapSpriteGroup (ByteReader *buf, uint8 idcount)
static void | FeatureMapSpriteGroup (ByteReader *buf)
static void | FeatureNewName (ByteReader *buf)
static uint16 | SanitizeSpriteOffset (uint16 &num, uint16 offset, int max_sprites, const char *name)
| Sanitize incoming sprite offsets for Action 5 graphics replacements.
static void | GraphicsNew (ByteReader *buf)
static void | SkipAct5 (ByteReader *buf)
void | CheckForMissingSprites ()
| Check whether we are (obviously) missing some of the extra (Action 0x05) sprites that we like to use.
bool | GetGlobalVariable (byte param, uint32 *value)
| Reads a variable common to VarAction2 and Action7/9/D.
static uint32 | GetParamVal (byte param, uint32 *cond_val)
static void | CfgApply (ByteReader *buf)
static void | DisableStaticNewGRFInfluencingNonStaticNewGRFs (GRFConfig *c)
| Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desyncs.
static void | SkipIf (ByteReader *buf)
static void | ScanInfo (ByteReader *buf)
static void | GRFInfo (ByteReader *buf)
static void | SpriteReplace (ByteReader *buf)
static void | SkipActA (ByteReader *buf)
static void | GRFLoadError (ByteReader *buf)
static void | GRFComment (ByteReader *buf)
static void | SafeParamSet (ByteReader *buf)
static uint32 | GetPatchVariable (uint8 param)
static uint32 | PerformGRM (uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, const char *type)
static void | ParamSet (ByteReader *buf)
static void | SafeGRFInhibit (ByteReader *buf)
static void | GRFInhibit (ByteReader *buf)
static void | FeatureTownName (ByteReader *buf)
static void | DefineGotoLabel (ByteReader *buf)
static void | GRFSound (ByteReader *buf)
static void | SkipAct11 (ByteReader *buf)
static void | ImportGRFSound (ByteReader *buf)
static void | GRFImportBlock (ByteReader *buf)
static void | LoadGRFSound (ByteReader *buf)
static void | LoadFontGlyph (ByteReader *buf)
static void | SkipAct12 (ByteReader *buf)
static void | TranslateGRFStrings (ByteReader *buf)
static bool | ChangeGRFName (byte langid, const char *str)
| Callback function for 'INFO'->'NAME' to add a translation to the newgrf name.
static bool | ChangeGRFDescription (byte langid, const char *str)
| Callback function for 'INFO'->'DESC' to add a translation to the newgrf description.
static bool | ChangeGRFNumUsedParams (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'NPAR' to set the number of valid parameters.
static bool | ChangeGRFPalette (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'PALS' to set the number of valid parameters.
static bool | ChangeGRFVersion (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'VRSN' to the version of the NewGRF.
static bool | ChangeGRFMinVersion (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'MINV' to the minimum compatible version of the NewGRF.
static bool | ChangeGRFParamName (byte langid, const char *str)
| Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter.
static bool | ChangeGRFParamDescription (byte langid, const char *str)
| Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter.
static bool | ChangeGRFParamType (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.
static bool | ChangeGRFParamLimits (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'PARAM'->param_num->'LIMI' to set the min/max value of a parameter.
static bool | ChangeGRFParamMask (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use.
static bool | ChangeGRFParamDefault (size_t len, ByteReader *buf)
| Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.
static bool | SkipUnknownInfo (ByteReader *buf, byte type)
| Try to skip the current node and all subnodes (if it's a branch node).
static bool | HandleNodes (ByteReader *buf, AllowedSubtags *tags)
static bool | ChangeGRFParamValueNames (ByteReader *buf)
| Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (type uint/enum) or the names of some bits (type bitmask).
static bool | HandleParameterInfo (ByteReader *buf)
| Callback function for 'INFO'->'PARA' to set extra information about the parameters.
static bool | HandleNode (byte type, uint32 id, ByteReader *buf, AllowedSubtags subtags[])
static bool | HandleNodes (ByteReader *buf, AllowedSubtags subtags[])
static void | StaticGRFInfo (ByteReader *buf)
static void | GRFDataBlock (ByteReader *buf)
static void | GRFUnsafe (ByteReader *buf)
static void | InitializeGRFSpecial ()
static void | ResetCustomStations ()
static void | ResetCustomHouses ()
static void | ResetCustomAirports ()
static void | ResetCustomIndustries ()
static void | ResetCustomObjects ()
static void | ResetNewGRF ()
static void | ResetNewGRFErrors ()
void | ResetNewGRFData ()
| Reset all NewGRF loaded data TODO.
static void | BuildCargoTranslationMap ()
static void | InitNewGRFFile (const GRFConfig *config, int sprite_offset)
static void | CalculateRefitMasks ()
| Precalculate refit masks from cargo classes for all vehicles.
static void | FinaliseEngineArray ()
| Check for invalid engines.
static void | FinaliseCargoArray ()
| Check for invalid cargos.
static bool | IsHouseSpecValid (HouseSpec *hs, const HouseSpec *next1, const HouseSpec *next2, const HouseSpec *next3, const char *filename)
| Check if a given housespec is valid and disable it if it's not.
static void | FinaliseHouseArray ()
| Add all new houses to the house array.
static void | FinaliseIndustriesArray ()
| Add all new industries to the industry array.
static void | FinaliseObjectsArray ()
| Add all new objects to the object array.
static void | FinaliseAirportsArray ()
| Add all new airports to the airport array.
static void | DecodeSpecialSprite (byte *buf, uint num, GrfLoadingStage stage)
void | LoadNewGRFFile (GRFConfig *config, uint file_index, GrfLoadingStage stage)
static void | ActivateOldShore ()
| Relocates the old shore sprites at new positions.
static void | FinalisePriceBaseMultipliers ()
| Decide whether price base multipliers of grfs shall apply globally or only to the grf specifying them.
void | InitDepotWindowBlockSizes ()
| Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game.
void | InitGRFTownGeneratorNames ()
| Allocate memory for the NewGRF town names.
static void | AfterLoadGRFs ()
void | LoadNewGRF (uint load_index, uint file_index)
bool | HasGrfMiscBit (GrfMiscBit bit)
## Variables
static int | _skip_sprites
static uint | _file_index
static SmallVector< GRFFile *, 16 > | _grf_files
static GRFFile * | _cur_grffile
static SpriteID | _cur_spriteid
static GrfLoadingStage | _cur_stage
static uint32 | _nfo_line
static GRFConfig * | _cur_grfconfig
static byte | _misc_grf_features = 0
static uint32 | _ttdpatch_flags [8]
GRFLoadedFeatures | _loaded_newgrf_features
static byte | _grf_data_blocks
static GrfDataType | _grf_data_type
static const uint | MAX_STATIONS = 256
static GRFTempEngineData * | _gted
static uint32 | _grm_engines [256]
static uint32 | _grm_cargos [NUM_CARGO *2]
static std::map< GRFLocation, SpriteID > | _grm_sprites
static GRFLineToSpriteOverride | _grf_line_to_action6_sprite_override
static StringIDToGRFIDMapping | _string_to_grf_mapping
static std::map< uint32, uint32 > | _grf_id_overrides
static const Action5Type | _action5_types []
| The information about action 5 types.
static GRFParameterInfo * | _cur_parameter
| The parameter which info is currently changed by the newgrf.
AllowedSubtags | _tags_parameters []
AllowedSubtags | _tags_info []
AllowedSubtags | _tags_root []
static const CargoLabel | _default_refitmasks_rail []
| List of what cargo labels are refittable for the given the vehicle-type.
static const CargoLabel | _default_refitmasks_road []
static const CargoLabel | _default_refitmasks_ships []
static const CargoLabel | _default_refitmasks_aircraft []
static const CargoLabel *const | _default_refitmasks []

## Detailed Description

Base of all NewGRF support.

Definition in file newgrf.cpp.

## Enumeration Type Documentation

enum Action5BlockType

The type of action 5 type.

Enumerator:

  A5BLOCK_FIXED | Only allow replacing a whole block of sprites. (TTDP compatible).
  A5BLOCK_ALLOW_OFFSET | Allow replacing any subset by specifiing an offset.
  A5BLOCK_INVALID | unknown/not-implemented type

Definition at line 4780 of file newgrf.cpp.

enum ChangeInfoResult

Enumerator:

  CIR_SUCCESS | Variable was parsed and read.
  CIR_UNHANDLED | Variable was parsed but unread.
  CIR_UNKNOWN | Variable is unknown.
  CIR_INVALID_ID | Attempt to modify an invalid ID.

Definition at line 484 of file newgrf.cpp.

## Function Documentation

static void ActivateOldShore | ( |  | ) | `[static]`

Relocates the old shore sprites at new positions.

1. If shore sprites are neither loaded by Action5 nor ActionA, the extra sprites from openttd(w/d).grf are used. (SHORE_REPLACE_ONLY_NEW) 2. If a newgrf replaces some shore sprites by ActionA. The (maybe also replaced) grass tiles are used for corner shores. (SHORE_REPLACE_ACTION_A) 3. If a newgrf replaces shore sprites by Action5 any shore replacement by ActionA has no effect. (SHORE_REPLACE_ACTION_5)

Definition at line 7974 of file newgrf.cpp.

References GRFLoadedFeatures::shore, SHORE_REPLACE_ACTION_5, SHORE_REPLACE_ACTION_A, and SHORE_REPLACE_NONE.

static bool ChangeGRFDescription | ( | byte | langid,
|  | const char * | str |
| ) |  |  | `[static]`

Callback function for 'INFO'->'DESC' to add a translation to the newgrf description.

Definition at line 6502 of file newgrf.cpp.

References AddGRFTextToList(), GRFIdentifier::grfid, GRFConfig::ident, GRFConfig::info, and GRFTextWrapper::text.

static bool ChangeGRFMinVersion | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'MINV' to the minimum compatible version of the NewGRF.

Definition at line 6555 of file newgrf.cpp.

References grfmsg(), GRFConfig::min_loadable_version, and GRFConfig::version.

static bool ChangeGRFName | ( | byte | langid,
|  | const char * | str |
| ) |  |  | `[static]`

Callback function for 'INFO'->'NAME' to add a translation to the newgrf name.

Definition at line 6495 of file newgrf.cpp.

References AddGRFTextToList(), GRFIdentifier::grfid, GRFConfig::ident, GRFConfig::name, and GRFTextWrapper::text.

static bool ChangeGRFNumUsedParams | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'NPAR' to set the number of valid parameters.

Definition at line 6509 of file newgrf.cpp.

References grfmsg(), lengthof, min(), GRFConfig::num_valid_params, and GRFConfig::param.

static bool ChangeGRFPalette | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PALS' to set the number of valid parameters.

Definition at line 6521 of file newgrf.cpp.

References grfmsg(), GRFP_GRF_ANY, GRFP_GRF_DOS, GRFP_GRF_WINDOWS, and GRFConfig::palette.

static bool ChangeGRFParamDefault | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.

Definition at line 6645 of file newgrf.cpp.

References GRFParameterInfo::def_value, grfmsg(), and GRFConfig::has_param_defaults.

static bool ChangeGRFParamDescription | ( | byte | langid,
|  | const char * | str |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter.

Definition at line 6584 of file newgrf.cpp.

References AddGRFTextToList(), GRFParameterInfo::desc, GRFIdentifier::grfid, and GRFConfig::ident.

static bool ChangeGRFParamLimits | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PARAM'->param_num->'LIMI' to set the min/max value of a parameter.

Definition at line 6608 of file newgrf.cpp.

References grfmsg(), GRFParameterInfo::max_value, GRFParameterInfo::min_value, PTYPE_UINT_ENUM, and GRFParameterInfo::type.

static bool ChangeGRFParamMask | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use.

Definition at line 6624 of file newgrf.cpp.

References GRFParameterInfo::first_bit, grfmsg(), lengthof, min(), GRFParameterInfo::num_bit, GRFConfig::param, and GRFParameterInfo::param_nr.

static bool ChangeGRFParamName | ( | byte | langid,
|  | const char * | str |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter.

Definition at line 6577 of file newgrf.cpp.

References AddGRFTextToList(), GRFIdentifier::grfid, GRFConfig::ident, and GRFParameterInfo::name.

static bool ChangeGRFParamType | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.

Definition at line 6591 of file newgrf.cpp.

References grfmsg(), PTYPE_END, and GRFParameterInfo::type.

static bool ChangeGRFParamValueNames | ( | ByteReader * | buf | ) | `[static]`

Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (type uint/enum) or the names of some bits (type bitmask).

In both cases the format is the same: Each subnode should be a text node with the value/bit number as id.

Definition at line 6749 of file newgrf.cpp.

References AddGRFTextToList(), SmallVector< T, S >::End(), SmallMap< T, U, S >::Find(), GRFIdentifier::grfid, grfmsg(), GRFConfig::ident, SmallMap< T, U, S >::Insert(), GRFParameterInfo::max_value, SkipUnknownInfo(), and GRFParameterInfo::value_names.

static bool ChangeGRFVersion | ( | size_t | len,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Callback function for 'INFO'->'VRSN' to the version of the NewGRF.

Definition at line 6542 of file newgrf.cpp.

References grfmsg(), GRFConfig::min_loadable_version, and GRFConfig::version.

void CheckForMissingSprites | ( |  | ) |

Check whether we are (obviously) missing some of the extra (Action 0x05) sprites that we like to use.

When missing sprites are found a warning will be shown.

Definition at line 4912 of file newgrf.cpp.

References A5BLOCK_INVALID, Action5Type::block_type, DEBUG, INVALID_STRING_ID, lengthof, Action5Type::max_sprites, Action5Type::name, ShowErrorMessage(), Action5Type::sprite_base, and WL_CRITICAL.

static void CleanIndustryTileTable | ( | IndustrySpec * | ind | ) | `[static]`

Clean the tile table of the IndustrySpec if it's needed.

Definition at line 2535 of file newgrf.cpp.

References CLEAN_TILELAYOUT, IndustrySpec::cleanup_flag, HasBit(), IndustrySpec::num_table, and IndustrySpec::table.

static void ConvertTTDBasePrice | ( | uint32 | base_pointer,
|  | const char * | error_location,
|  | Price * | index |
| ) |  |  | `[static]`

Converts TTD(P) Base Price pointers into the enum used by OTTD See http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts.

Parameters:

  | base_pointer | TTD(P) Base Price Pointer
  | error_location | Function name for grf error messages
  | index | If base_pointer is valid, index is assigned to the matching price; else it is left unchanged

< Position of first base price

< Size of each base price record

Definition at line 465 of file newgrf.cpp.

References grfmsg().

static void DisableStaticNewGRFInfluencingNonStaticNewGRFs | ( | GRFConfig * | c | ) | `[static]`

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 5219 of file newgrf.cpp.

References ClearTemporaryNewGRFData(), GRFError::data, GRFConfig::error, GCS_DISABLED, GRFConfig::GetName(), GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::status.

static void DuplicateTileTable | ( | AirportSpec * | as | ) | `[static]`

Create a copy of the tile table so it can be freed later without problems.

Parameters:

  | as | The AirportSpec to copy the arrays of.

Definition at line 2863 of file newgrf.cpp.

References AirportSpec::depot_table, MemCpyT(), AirportSpec::nof_depots, AirportSpec::num_table, and AirportSpec::table.

static void FinaliseAirportsArray | ( |  | ) | `[static]`

Add all new airports to the airport array.

Airport properties can be set at any time in the GRF file, so we can only add a airport spec to the airport array after the file has finished loading.

Definition at line 7768 of file newgrf.cpp.

References SmallVector< T, S >::Begin(), SmallVector< T, S >::End(), and NUM_AIRPORTTILES.

static void FinaliseHouseArray | ( |  | ) | `[static]`

Add all new houses to the house array.

House properties can be set at any time in the GRF file, so we can only add a house spec to the house array after the file has finished loading. We also need to check the dates, due to the TTDPatch behaviour described below that we need to emulate.

Definition at line 7609 of file newgrf.cpp.

References SmallVector< T, S >::Begin(), HouseSpec::building_flags, HouseSpec::enabled, SmallVector< T, S >::End(), IsHouseSpecValid(), MAX_YEAR, HouseSpec::min_year, and HouseOverrideManager::SetEntitySpec().

static void FinaliseIndustriesArray | ( |  | ) | `[static]`

Add all new industries to the industry array.

Industry properties can be set at any time in the GRF file, so we can only add a industry spec to the industry array after the file has finished loading.

Definition at line 7677 of file newgrf.cpp.

References SmallVector< T, S >::Begin(), IndustrySpec::closure_text, IndustrySpec::conflicting, IndustrySpec::enabled, SmallVector< T, S >::End(), GetGRFStringID(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, GRFLoadedFeatures::has_newindustries, IndustrySpec::name, IndustrySpec::new_industry_text, NUM_INDUSTRYTILES, IndustrySpec::production_down_text, IndustrySpec::production_up_text, IndustryOverrideManager::SetEntitySpec(), and IndustrySpec::station_name.

static void FinaliseObjectsArray | ( |  | ) | `[static]`

Add all new objects to the object array.

Object properties can be set at any time in the GRF file, so we can only add an object spec to the object array after the file has finished loading.

Definition at line 7748 of file newgrf.cpp.

References _object_mngr, SmallVector< T, S >::Begin(), ObjectSpec::enabled, SmallVector< T, S >::End(), NUM_OBJECTS, and ObjectOverrideManager::SetEntitySpec().

bool GetGlobalVariable | ( | byte | param,
|  | uint32 * | value |
| ) |  |  |

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.

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

Definition at line 4946 of file newgrf.cpp.

References _cur_year, _date, _display_opt, _settings_game, _tick_counter, Clamp(), ConvertDateToYMD(), ConvertYMDToDate(), YearMonthDay::day, DAYS_TILL_ORIGINAL_BASE_YEAR, DifficultySettings::diff_level, GameSettings::difficulty, VehicleSettings::disable_elrails, GameSettings::game_creation, GB(), GetRailTypeInfo(), GetSnowLine(), GMB_TRAIN_WIDTH_32_PIXELS, GRFP_USE_MASK, HasBit(), GameCreationSettings::landscape, max(), YearMonthDay::month, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR, GRFConfig::palette, RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, RAILTYPE_MONO, RAILTYPE_RAIL, VehicleSettings::road_side, SB(), SetBit(), GRFFile::traininfo_vehicle_pitch, GRFFile::traininfo_vehicle_width, GameSettings::vehicle, and YearMonthDay::year.

static Engine* GetNewEngine | ( | const GRFFile * | file,
|  | VehicleType | type,
|  | uint16 | internal_id,
|  | bool | static_access = `false` |
| ) |  |  | `[static]`

Returns the engine associated to a certain internal_id, resp.

allocates it.

Parameters:

  | file | NewGRF that wants to change the engine
  | type | Vehicle type
  | internal_id | Engine ID inside the NewGRF
  | static_access | If the engine is not present, return NULL instead of allocating a new engine. (Used for static Action 0x04)

Returns:
  The requested engine

Definition at line 339 of file newgrf.cpp.

References _engine_counts, _settings_game, SmallVector< T, S >::Append(), BSWAP32(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::CanAllocateItem(), VehicleSettings::dynamic_engines, SmallVector< T, S >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), EngineOverrideManager::GetID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::GetPoolSize(), GetRailTypeInfo(), Engine::grf_prop, GRFFilePropsBase< Tcnt >::grffile, EngineIDMapping::grfid, grfmsg(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, RailtypeInfo::label, SmallVector< T, S >::Length(), min(), ReallocT(), EngineIDMapping::type, VEH_TRAIN, and GameSettings::vehicle.

Referenced by ShipVehicleChangeInfo().

void CDECL grfmsg | ( | int | severity,
|  | const char * | str,
|  |  | ... |
| ) |  |  |

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
  | str | message in printf() format

Definition at line 237 of file newgrf.cpp.

References DEBUG, and GRFConfig::filename.

Referenced by AddGenericCallback(), AddGRFString(), ChangeGRFMinVersion(), ChangeGRFNumUsedParams(), ChangeGRFPalette(), ChangeGRFParamDefault(), ChangeGRFParamLimits(), ChangeGRFParamMask(), ChangeGRFParamType(), ChangeGRFParamValueNames(), ChangeGRFVersion(), ConvertTTDBasePrice(), DEFINE_NEWGRF_CLASS_METHOD(), UnmappedChoiceList::Flush(), GetNewEngine(), HandleParameterInfo(), SanitizeSpriteOffset(), ObjectOverrideManager::SetEntitySpec(), IndustryOverrideManager::SetEntitySpec(), HouseOverrideManager::SetEntitySpec(), ShipVehicleChangeInfo(), TownHouseChangeInfo(), and TranslateTTDPatchCodes().

static bool HandleParameterInfo | ( | ByteReader * | buf | ) | `[static]`

Callback function for 'INFO'->'PARA' to set extra information about the parameters.

Each subnode of 'INFO'->'PARA' should be a branch node with the parameter number as id. The first parameter has id 0. The maximum parameter that can be changed is set by 'INFO'->'NPAR' which defaults to 80.

Definition at line 6795 of file newgrf.cpp.

References SmallVector< T, S >::Append(), grfmsg(), SmallVector< T, S >::Length(), GRFConfig::num_valid_params, GRFConfig::param_info, and SkipUnknownInfo().

void InitDepotWindowBlockSizes | ( |  | ) |

Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game.

Note:
  Calling this function once for each game is enough.

Definition at line 206 of file depot_gui.cpp.

References GetVehicleHeight(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

void InitGRFTownGeneratorNames | ( |  | ) |

Allocate memory for the NewGRF town names.

Definition at line 82 of file settings_gui.cpp.

References _grf_names, _nb_grf_names, and INVALID_STRING_ID.

static bool IsHouseSpecValid | ( | HouseSpec * | hs,
|  | const HouseSpec * | next1,
|  | const HouseSpec * | next2,
|  | const HouseSpec * | next3,
|  | const char * | filename |
| ) |  |  | `[static]`

Check if a given housespec is valid and disable it if it's not.

The housespecs that follow it are used to check the validity of multitile houses.

Parameters:

  | hs | The housespec to check.
  | next1 | The housespec that follows `hs`.
  | next2 | The housespec that follows `next1`.
  | next3 | The housespec that follows `next2`.
  | filename | The filename of the newgrf this house was defined in.

Returns:
  Whether the given housespec is valid.

Definition at line 7563 of file newgrf.cpp.

References HouseSpec::building_availability, HouseSpec::building_flags, DEBUG, HouseSpec::enabled, HouseSpec::grf_prop, HZ_CLIMALL, HZ_ZONALL, GRFFilePropsBase< Tcnt >::local_id, and HouseSpec::population.

Referenced by FinaliseHouseArray().

StringID MapGRFStringID | ( | uint32 | grfid,
|  | StringID | 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 | StringID that we want to have the equivalent in OoenTTD

Returns:
  the properly adjusted StringID

Definition at line 295 of file newgrf.cpp.

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

Referenced by ChangeIndustryProduction(), and TranslateTTDPatchCodes().

static void MapSpriteMappingRecolour | ( | PalSpriteID * | grf_sprite | ) | `[static]`

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

Parameters:

  | grf_sprite | pointer to the structure been modified

Definition at line 440 of file newgrf.cpp.

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

static uint16 SanitizeSpriteOffset | ( | uint16 & | num,
|  | uint16 | offset,
|  | int | max_sprites,
|  | const char * | name |
| ) |  |  | `[static]`

Sanitize incoming sprite offsets for Action 5 graphics replacements.

Parameters:

  | num | the number of sprites to load.
  | offset | offset from the base.
  | max_sprites | the maximum number of sprites that can be loaded in this action 5.
  | name | used for error warnings.

Returns:
  the number of sprites that is going to be skipped

Definition at line 4758 of file newgrf.cpp.

References grfmsg(), and max().

static ChangeInfoResult ShipVehicleChangeInfo | ( | uint | engine,
|  | int | numinfo,
|  | int | prop,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

Todo:
  Speed fractions for ships on oceans and canals

Definition at line 924 of file newgrf.cpp.

References _cargo_mask, EngineInfo::callback_mask, CIR_INVALID_ID, CIR_SUCCESS, CIR_UNHANDLED, CT_INVALID, EF_USES_2CC, GetNewEngine(), grfmsg(), GRFLoadedFeatures::has_2CC, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, ShipVehicleInfo::max_speed, NUM_CARGO, ShipVehicleInfo::old_refittable, PROP_SHIP_CARGO_CAPACITY, PROP_SHIP_COST_FACTOR, PROP_SHIP_RUNNING_COST_FACTOR, PROP_SHIP_SPEED, GRFTempEngineData::refitmask_valid, EngineInfo::retire_early, SB(), VE_DEFAULT, VE_DISABLE_EFFECT, VE_TYPE_COUNT, VE_TYPE_START, VEH_SHIP, and ShipVehicleInfo::visual_effect.

static bool SkipUnknownInfo | ( | ByteReader * | buf,
|  | byte | type |
| ) |  |  | `[static]`

Try to skip the current node and all subnodes (if it's a branch node).

Returns:
  True if we could skip the node, false if an error occured.

Definition at line 6844 of file newgrf.cpp.

Referenced by ChangeGRFParamValueNames(), and HandleParameterInfo().

static ChangeInfoResult TownHouseChangeInfo | ( | uint | hid,
|  | int | numinfo,
|  | int | prop,
|  | ByteReader * | buf |
| ) |  |  | `[static]`

New houses do not (currently) expect to have a default start date before 1930, as this breaks the build date stuff.

See also:
  FinaliseHouseArray() for more details.

Definition at line 1585 of file newgrf.cpp.

References _settings_game, abs(), HouseSpec::accepts_cargo, OverrideManagerBase::Add(), HouseSpec::animation, HouseSpec::building_availability, HouseSpec::building_flags, HouseSpec::building_name, HouseSpec::callback_mask, HouseSpec::cargo_acceptance, CIR_INVALID_ID, CIR_SUCCESS, CIR_UNHANDLED, CIR_UNKNOWN, Clamp(), HouseSpec::class_id, CT_INVALID, HouseSpec::enabled, HouseSpec::extra_flags, AnimationInfo::frames, GameSettings::game_creation, GB(), CargoSpec::Get(), grfmsg(), GRFLoadedFeatures::has_newhouses, CargoSpec::IsValid(), GameCreationSettings::landscape, HouseSpec::mail_generation, HouseSpec::max_year, MAX_YEAR, MemCpyT(), min(), HouseSpec::min_year, HouseSpec::minimum_life, ORIGINAL_BASE_YEAR, HouseSpec::population, HouseSpec::probability, HouseSpec::processing_time, HouseSpec::random_colour, HouseSpec::removal_cost, HouseSpec::remove_rating_decrease, SB(), AnimationInfo::speed, and AnimationInfo::status.

static bool ValidateIndustryLayout | ( | const IndustryTileTable * | layout,
|  | int | size |
| ) |  |  | `[static]`

Validate the industry layout; e.g.

to prevent duplicate tiles.

Parameters:

  | layout | the layout to check
  | size | the size of the layout

Returns:
  true if the layout is deemed valid

Definition at line 2521 of file newgrf.cpp.

References TileIndexDiffC::x, and TileIndexDiffC::y.

## Variable Documentation

const Action5Type _action5_types[]`[static]`

Initial value:

     {

       { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x00"             },
       { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x01"             },
       { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x02"             },
       { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x03"             },
       { A5BLOCK_FIXED,        SPR_SIGNALS_BASE,            48, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,    "Signal graphics"       },
       { A5BLOCK_FIXED,        SPR_ELRAIL_BASE,             48, ELRAIL_SPRITE_COUNT,                         "Catenary graphics"     },
       { A5BLOCK_FIXED,        SPR_SLOPES_BASE,             74, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, "Foundation graphics"   },
       { A5BLOCK_INVALID,      0,                           75, 0,                                           "TTDP GUI graphics"     },
       { A5BLOCK_FIXED,        SPR_CANALS_BASE,             65, CANALS_SPRITE_COUNT,                         "Canal graphics"        },
       { A5BLOCK_FIXED,        SPR_ONEWAY_BASE,              6, ONEWAY_SPRITE_COUNT,                         "One way road graphics" },
       { A5BLOCK_FIXED,        SPR_2CCMAP_BASE,            256, TWOCCMAP_SPRITE_COUNT,                       "2CC colour maps"       },
       { A5BLOCK_FIXED,        SPR_TRAMWAY_BASE,           113, TRAMWAY_SPRITE_COUNT,                        "Tramway graphics"      },
       { A5BLOCK_INVALID,      0,                          133, 0,                                           "Snowy temperate tree"  },
       { A5BLOCK_FIXED,        SPR_SHORE_BASE,              16, SPR_SHORE_SPRITE_COUNT,                      "Shore graphics"        },
       { A5BLOCK_INVALID,      0,                            0, 0,                                           "New Signals graphics"  },
       { A5BLOCK_FIXED,        SPR_TRACKS_FOR_SLOPES_BASE,  12, TRACKS_FOR_SLOPES_SPRITE_COUNT,              "Sloped rail track"     },
       { A5BLOCK_FIXED,        SPR_AIRPORTX_BASE,           15, AIRPORTX_SPRITE_COUNT,                       "Airport graphics"      },
       { A5BLOCK_FIXED,        SPR_ROADSTOP_BASE,            8, ROADSTOP_SPRITE_COUNT,                       "Road stop graphics"    },
       { A5BLOCK_FIXED,        SPR_AQUEDUCT_BASE,            8, AQUEDUCT_SPRITE_COUNT,                       "Aqueduct graphics"     },
       { A5BLOCK_FIXED,        SPR_AUTORAIL_BASE,           55, AUTORAIL_SPRITE_COUNT,                       "Autorail graphics"     },
       { A5BLOCK_ALLOW_OFFSET, SPR_FLAGS_BASE,               1, FLAGS_SPRITE_COUNT,                          "Flag graphics"         },
       { A5BLOCK_ALLOW_OFFSET, SPR_OPENTTD_BASE,             1, OPENTTD_SPRITE_COUNT,                        "OpenTTD GUI graphics"  },
       { A5BLOCK_ALLOW_OFFSET, SPR_AIRPORT_PREVIEW_BASE,     1, SPR_AIRPORT_PREVIEW_COUNT,                   "Airport preview graphics" },
    }

The information about action 5 types.

Definition at line 4795 of file newgrf.cpp.

const CargoLabel* const _default_refitmasks[]`[static]`

Initial value:

     {
      _default_refitmasks_rail,
      _default_refitmasks_road,
      _default_refitmasks_ships,
      _default_refitmasks_aircraft,
    }

Definition at line 7409 of file newgrf.cpp.

const CargoLabel _default_refitmasks_aircraft[]`[static]`

Initial value:

     {
      'PASS', 'MAIL', 'GOOD', 'VALU', 'GOLD', 'DIAM', 'FOOD', 'FRUT', 'SUGR',
      'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL', 'PLST', 'FZDR',
      0 }

Definition at line 7404 of file newgrf.cpp.

const CargoLabel _default_refitmasks_rail[]`[static]`

Initial value:

     {
      'PASS', 'COAL', 'MAIL', 'LVST', 'GOOD', 'GRAI', 'WHEA', 'MAIZ', 'WOOD',
      'IORE', 'STEL', 'VALU', 'GOLD', 'DIAM', 'PAPR', 'FOOD', 'FRUT', 'CORE',
      'WATR', 'SUGR', 'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL',
      'PLST', 'FZDR',
      0 }

List of what cargo labels are refittable for the given the vehicle-type.

Only currently active labels are applied.

Definition at line 7387 of file newgrf.cpp.

const CargoLabel _default_refitmasks_road[]`[static]`

Initial value:

     {
      0 }

Definition at line 7394 of file newgrf.cpp.

const CargoLabel _default_refitmasks_ships[]`[static]`

Initial value:

     {
      'COAL', 'MAIL', 'LVST', 'GOOD', 'GRAI', 'WHEA', 'MAIZ', 'WOOD', 'IORE',
      'STEL', 'VALU', 'GOLD', 'DIAM', 'PAPR', 'FOOD', 'FRUT', 'CORE', 'WATR',
      'RUBR', 'SUGR', 'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL',
      'PLST', 'FZDR',
      0 }

Definition at line 7397 of file newgrf.cpp.

AllowedSubtags _tags_info[]

Initial value:

     {
      AllowedSubtags('NAME', ChangeGRFName),
      AllowedSubtags('DESC', ChangeGRFDescription),
      AllowedSubtags('NPAR', ChangeGRFNumUsedParams),
      AllowedSubtags('PALS', ChangeGRFPalette),
      AllowedSubtags('VRSN', ChangeGRFVersion),
      AllowedSubtags('MINV', ChangeGRFMinVersion),
      AllowedSubtags('PARA', HandleParameterInfo),
      AllowedSubtags()
    }

Definition at line 6823 of file newgrf.cpp.

AllowedSubtags _tags_parameters[]

Initial value:

     {
      AllowedSubtags('NAME', ChangeGRFParamName),
      AllowedSubtags('DESC', ChangeGRFParamDescription),
      AllowedSubtags('TYPE', ChangeGRFParamType),
      AllowedSubtags('LIMI', ChangeGRFParamLimits),
      AllowedSubtags('MASK', ChangeGRFParamMask),
      AllowedSubtags('VALU', ChangeGRFParamValueNames),
      AllowedSubtags('DFLT', ChangeGRFParamDefault),
      AllowedSubtags()
    }

Definition at line 6778 of file newgrf.cpp.

AllowedSubtags _tags_root[]

Initial value:

     {
      AllowedSubtags('INFO', _tags_info),
      AllowedSubtags()
    }

Definition at line 6834 of file newgrf.cpp.