# newgrf.h File Reference

`#include "station.h"`
`#include "town_type.h"`
`#include "newgrf_config.h"`
`#include "cargotype.h"`
`#include "industry_type.h"`

Go to the source code of this file.

## Data Structures
struct | GRFLabel
struct | GRFFile
struct | GRFLoadedFeatures
## Enumerations
enum | GrfLoadingStage { GLS_FILESCAN, GLS_SAFETYSCAN, GLS_LABELSCAN, GLS_INIT, GLS_RESERVE, GLS_ACTIVATION, GLS_END }
enum | GrfMiscBit { GMB_DESERT_TREES_FIELDS = 0, GMB_DESERT_PAVED_ROADS = 1, GMB_FIELD_BOUNDING_BOX = 2, GMB_TRAIN_WIDTH_32_PIXELS = 3, GMB_AMBIENT_SOUND_CALLBACK = 4, GMB_CATENARY_ON_3RD_TRACK = 5 }
enum | GrfSpecFeature { GSF_TRAIN, GSF_ROAD, GSF_SHIP, GSF_AIRCRAFT, GSF_STATION, GSF_CANAL, GSF_BRIDGE, GSF_TOWNHOUSE, GSF_GLOBALVAR, GSF_INDUSTRYTILES, GSF_INDUSTRIES, GSF_CARGOS, GSF_SOUNDFX, GSF_END }
enum | ShoreReplacement { SHORE_REPLACE_NONE, SHORE_REPLACE_ACTION_5, SHORE_REPLACE_ACTION_A, SHORE_REPLACE_ONLY_NEW }
## Functions
| DECLARE_POSTFIX_INCREMENT (GrfLoadingStage)
void | LoadNewGRFFile (GRFConfig *config, uint file_index, GrfLoadingStage stage)
void | LoadNewGRF (uint load_index, uint file_index)
void | ReloadNewGRFData ()
| Reload all NewGRF files during a running game.
void CDECL | grfmsg (int severity, const char *str,...)
| DEBUG() function dedicated to newGRF debugging messages Function is essentialy the same as DEBUG(grf, severity, .
bool | HasGrfMiscBit (GrfMiscBit bit)
bool | GetGlobalVariable (byte param, uint32 *value)
| Reads a variable common to VarAction2 and Action7/9/D.
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.
## Variables
GRFFile * | _first_grffile
GRFLoadedFeatures | _loaded_newgrf_features

## Detailed Description

Definition in file newgrf.h.

## Enumeration Type Documentation

enum ShoreReplacement

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 105 of file newgrf.h.

## Function Documentation

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

References Clamp(), DAYS_TILL_ORIGINAL_BASE_YEAR, GB(), max(), ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR, and SB().

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

DEBUG() function dedicated to newGRF debugging messages Function is essentialy 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 151 of file newgrf.cpp.

References buf.

Referenced by AddGRFString(), AllocateStationClass(), GraphicsNew(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), SanitizeSpriteOffset(), ShipVehicleChangeInfo(), and TownHouseChangeInfo().

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

References GB(), and GetGRFStringID().

Referenced by ChangeIndustryProduction(), and GRFMappedStringID::MapString().

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 2500 of file openttd.cpp.

References AfterLoadVehicles(), AfterLoadWaypoints(), CheckTrainsLengths(), MarkWholeScreenDirty(), and UpdateHousesAndTowns().

Referenced by ClickChangeClimateCheat(), and NewGRFConfirmationCallback().