Data Structures | Enumerations | Functions | Variables

# newgrf.h File Reference

Base for the NewGRF implementation. More...

`#include "cargotype.h"`
`#include "rail_type.h"`
`#include "fileio_type.h"`
`#include "core/bitmath_func.hpp"`
`#include "core/alloc_type.hpp"`
`#include "core/smallvec_type.hpp"`

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
## Enumerations
enum | CanalFeature { 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 { 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_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_END, GSF_FAKE_TOWNS = GSF_END, GSF_FAKE_END, GSF_INVALID = 0xFF }
enum | ShoreReplacement { SHORE_REPLACE_NONE, SHORE_REPLACE_ACTION_5, SHORE_REPLACE_ACTION_A, SHORE_REPLACE_ONLY_NEW }
## Functions
static bool | HasGrfMiscBit (GrfMiscBit bit)
| Check for grf miscellaneous bits.
byte | GetGRFContainerVersion ()
| Get the container version of the currently opened GRF file.
void | LoadNewGRFFile (struct GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
| Load a particular NewGRF.
void | LoadNewGRF (uint load_index, uint file_index)
| Load all the NewGRFs.
void | ReloadNewGRFData ()
| Reload all NewGRF files during a running game.
void | ResetNewGRFData ()
| Reset all NewGRF loaded data TODO.
void | ResetPersistentNewGRFData ()
| Reset NewGRF data which is stored persistently in savegames.
void CDECL | grfmsg (int severity, const char *str,...) WARN_FORMAT(2
void CDECL bool | GetGlobalVariable (byte param, uint32 *value, const GRFFile *grffile)
| 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.
void | ShowNewGRFError ()
| Show the first NewGRF error we can find.
## Variables
static const uint32 | 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.

## Enumeration Type Documentation

enum CanalFeature

List of different canal 'features'.

Each feature gets an entry in the canal spritegroup table

Definition at line 26 of file newgrf.h.

enum GrfMiscBit

Enumerator:

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

enum GrfSpecFeature

Enumerator:

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

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

## Function Documentation

void CDECL bool GetGlobalVariable | ( | byte | param,
|  | uint32 * | 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 5618 of file newgrf.cpp.

References _cur_year, _date, _date_fract, _misc_grf_features, _settings_game, _tick_counter, Clamp(), ConvertDateToYMD(), ConvertYMDToDate(), YearMonthDay::day, DAYS_TILL_ORIGINAL_BASE_YEAR, VehicleSettings::disable_elrails, GameSettings::game_creation, GetRailTypeInfo(), GetSnowLine(), GMB_TRAIN_WIDTH_32_PIXELS, GrfProcessingState::grfconfig, GrfProcessingState::grffile, HasBit(), IsLeapYear(), GameCreationSettings::landscape, max(), MAX_TILE_HEIGHT, YearMonthDay::month, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR, GRFConfig::palette, RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, RAILTYPE_MONO, RAILTYPE_RAIL, VehicleSettings::road_side, SB(), SetBit(), TILE_HEIGHT, GRFFile::traininfo_vehicle_pitch, GRFFile::traininfo_vehicle_width, GameSettings::vehicle, and YearMonthDay::year.

byte GetGRFContainerVersion | ( |  | ) |

Get the container version of the currently opened GRF file.

Returns:
  Container version of the GRF file or 0 if the file is corrupt/no GRF file.

Definition at line 8683 of file newgrf.cpp.

References FioGetPos(), FioReadByte(), FioReadWord(), FioSeekTo(), and lengthof.

Referenced by LoadGrfFile(), LoadGrfFileIndexed(), and LoadNewGRFFile().

static bool HasGrfMiscBit | ( | GrfMiscBit | bit | ) | `[inline, static]`

Check for grf miscellaneous bits.

Parameters:

  | bit | The bit to check.

Returns:
  Whether the bit is set.

Definition at line 174 of file newgrf.h.

References _misc_grf_features, and HasBit().

Referenced by AlwaysDrawUnpavedRoads(), and AmbientSoundEffect().

void LoadNewGRF | ( | uint | load_index,
|  | uint | file_index |
| ) |  |  |

Load all the NewGRFs.

Parameters:

  | load_index | The offset for the first sprite to add.
  | file_index | The Fio index of the first NewGRF to load.

Definition at line 9076 of file newgrf.cpp.

References _cur_year, _date, _date_fract, _display_opt, _grfconfig, _networking, _settings_game, _tick_counter, AfterLoadGRFs(), BASESET_DIR, BSWAP32(), BuildCargoTranslationMap(), GrfProcessingState::ClearDataForNextFile(), ClearTemporaryNewGRFData(), ClrBit(), ConvertYMDToDate(), DEBUG, GRFConfig::filename, FioCheckFileExists(), GRFConfig::flags, GameSettings::game_creation, GCF_INIT_ONLY, GCF_RESERVED, GCS_ACTIVATED, GCS_DISABLED, GCS_NOT_FOUND, GetFileByGRFID(), GrfProcessingState::grffile, GRFIdentifier::grfid, HasBit(), GRFConfig::ident, InitializeGRFSpecial(), InitNewGRFFile(), lengthof, LoadNewGRFFile(), GRFConfig::next, ResetNewGRFData(), SetBit(), SetNewGRFOverride(), GrfProcessingState::spriteid, GrfProcessingState::stage, GameCreationSettings::starting_year, and GRFConfig::status.

Referenced by LoadSpriteTables().

void LoadNewGRFFile | ( | GRFConfig * | config,
|  | uint | file_index,
|  | GrfLoadingStage | stage,
|  | Subdirectory | subdir |
| ) |  |  |

Load a particular NewGRF.

Parameters:

  | config | The configuration of the to be loaded NewGRF.
  | file_index | The Fio index of the first NewGRF to load.
  | stage | The loading stage of the NewGRF.
  | subdir | The sub directory to find the NewGRF in.

Definition at line 8709 of file newgrf.cpp.

References _palette_remap_grf, ReusableBuffer< T >::Allocate(), GrfProcessingState::ClearDataForNextFile(), DEBUG, DisableGrf(), GRFConfig::error, GrfProcessingState::file_index, GRFConfig::filename, FioOpenFile(), FioReadByte(), FioReadDword(), FioReadWord(), FioSkipBytes(), GRFConfig::flags, GCF_RESERVED, GCS_INITIALISED, GetFileByFilename(), GetGRFContainerVersion(), GrfProcessingState::grf_container_ver, GrfProcessingState::grfconfig, GrfProcessingState::grffile, grfmsg(), HasBit(), GRFConfig::IsOpenTTDBaseGRF(), LAST_GRF_SLOT, GrfProcessingState::nfo_line, GRFConfig::palette, ReadGRFSpriteOffsets(), GrfProcessingState::skip_sprites, SkipSpriteData(), GRFConfig::status, and usererror().

Referenced by FillGRFDetails(), and LoadNewGRF().

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

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

Referenced by AfterLoadGRFs(), ChangeIndustryProduction(), and TranslateTTDPatchCodes().

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 2785 of file afterload.cpp.

References AfterLoadCompanyStats(), AfterLoadVehicles(), CheckTrainsLengths(), COMPANY_FIRST, DeleteInvalidEngineNews(), GfxLoadSprites(), InvalidateWindowClassesData(), InvalidateWindowData(), LoadStringWidthTable(), MarkWholeScreenDirty(), RecomputePrices(), StartupEngines(), GroupStatistics::UpdateAfterLoad(), UpdateHousesAndTowns(), WC_COMPANY_COLOUR, and WC_COMPANY_INFRASTRUCTURE.

Referenced by NewGRFConfirmationCallback(), and EngineOverrideManager::ResetToCurrentNewGRFConfig().