OpenTTD Source: src/newgrf.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
newgrf.cpp File Reference

Base of all NewGRF support. More...

`#include "stdafx.h"`
`#include "core/backup_type.hpp"`
`#include "core/container_func.hpp"`
`#include "company_manager_face.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 "spritecache.h"`
`#include "currency.h"`
`#include "landscape.h"`
`#include "newgrf_badge.h"`
`#include "newgrf_badge_config.h"`
`#include "newgrf_cargo.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 "network/core/config.h"`
`#include "smallmap_gui.h"`
`#include "genworld.h"`
`#include "error_func.h"`
`#include "vehicle_base.h"`
`#include "road.h"`
`#include "newgrf_roadstop.h"`
`#include "newgrf/newgrf_bytereader.h"`
`#include "newgrf/newgrf_internal_vehicle.h"`
`#include "newgrf/newgrf_internal.h"`
`#include "newgrf/newgrf_stringmapping.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | InvokeGrfActionHandler
| Helper class to invoke a GrfActionHandler. More...

## Functions
std::span< const GRFFile > | GetAllGRFFiles ()
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.
GRFFile * | GetFileByGRFID (uint32_t grfid)
| Obtain a NewGRF file by its grfID.
static GRFFile * | GetFileByFilename (const std::string &filename)
| Obtain a NewGRF file by its filename.
static void | ClearTemporaryNewGRFData (GRFFile *gf)
| Reset all NewGRFData that was used only while processing data.
GRFError * | DisableGrf (StringID message, GRFConfig *config)
| Disable a GRF.
void | DisableStaticNewGRFInfluencingNonStaticNewGRFs (GRFConfig &c)
| Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desyncs.
void | SetNewGRFOverride (uint32_t source_grfid, uint32_t target_grfid)
| Set the override for a NewGRF.
GRFFile * | GetCurrentGRFOverride ()
| Get overridden GRF for current GRF if present.
Engine * | GetNewEngine (const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access)
| Returns the engine associated to a certain internal_id, resp.
EngineID | GetNewEngineID (const GRFFile *file, VehicleType type, uint16_t internal_id)
| Return the ID of a new engine.
CargoTypes | TranslateRefitMask (uint32_t refit_mask)
| Translate the refit mask.
void | ConvertTTDBasePrice (uint32_t base_pointer, std::string_view 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.
void | GRFUnsafe (ByteReader &)
| Set the current NewGRF as unsafe for static use.
static void | ResetNewGRF ()
| Reset and clear all NewGRFs.
static void | ResetNewGRFErrors ()
| Clear all NewGRF errors.
void | ResetCallbacks (bool final)
void | ResetGRM ()
void | ResetNewGRFData ()
| Reset all NewGRF loaded data.
void | ResetPersistentNewGRFData ()
| Reset NewGRF data which is stored persistently in savegames.
std::span< const CargoLabel > | GetCargoTranslationTable (const GRFFile &grffile)
| Get the cargo translation table to use for the given GRF file.
static void | BuildCargoTranslationMap ()
| Construct the Cargo Mapping.
static void | InitNewGRFFile (const GRFConfig &config)
| Prepare loading a NewGRF file with its config.
static CargoLabel | GetActiveCargoLabel (const std::initializer_list< CargoLabel > &labels)
| Find first cargo label that exists and is active from a list of cargo labels.
static CargoLabel | GetActiveCargoLabel (const std::variant< CargoLabel, MixedCargoType > &label)
| Get active cargo label from either a cargo label or climate-dependent mixed cargo type.
static void | CalculateRefitMasks ()
| Precalculate refit masks from cargo classes for all vehicles.
static void | FinaliseCanals ()
| Set to use the correct action0 properties for each canal feature.
static void | FinaliseEngineArray ()
| Check for invalid engines.
void | FinaliseCargoArray ()
| Check for invalid cargoes.
static bool | IsHouseSpecValid (HouseSpec &hs, const HouseSpec *next1, const HouseSpec *next2, const HouseSpec *next3, const std::string &filename)
| Check if a given housespec is valid and disable it if it's not.
static void | EnsureEarlyHouse (HouseZones bitmask)
| Make sure there is at least one house available in the year 0 for the given climate / housezone combination.
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 (ReusableBuffer< uint8_t > &allocator, uint num, GrfLoadingStage stage)
static void | LoadNewGRFFileFromFile (GRFConfig &config, GrfLoadingStage stage, SpriteFile &file)
| Load a particular NewGRF from a SpriteFile.
void | LoadNewGRFFile (GRFConfig &config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
| Load a particular NewGRF.
static void | ActivateOldShore ()
| Relocates the old shore sprites at new positions.
static void | ActivateOldTramDepot ()
| Relocate the old tram depot sprites to the new position, if no new ones were loaded.
static void | FinalisePriceBaseMultipliers ()
| Decide whether price base multipliers of grfs shall apply globally or only to the grf specifying them.
template<typename T >
void | AddBadgeToSpecs (T &specs, GrfSpecFeature feature, Badge &badge)
static void | FinaliseBadges ()
| Finish up applying badges to things.
void | InitGRFTownGeneratorNames ()
| Allocate memory for the NewGRF town names.
static void | AfterLoadGRFs ()
| Finish loading NewGRFs and execute needed post-processing.
void | LoadNewGRF (SpriteID load_index, uint num_baseset)
| Load all the NewGRFs.

## Variables
static std::vector< GRFFile > | _grf_files
| List of all loaded GRF files.
GrfMiscBits | _misc_grf_features {}
| Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
GRFLoadedFeatures | _loaded_newgrf_features
| Indicates which are the newgrf features currently loaded ingame.
GrfProcessingState | _cur_gps
TypedIndexContainer< std::vector< GRFTempEngineData >, EngineID > | _gted
| Temporary engine data used during NewGRF loading.
static std::map< uint32_t, uint32_t > | _grf_id_overrides

## Detailed Description

Base of all NewGRF support.

Definition in file newgrf.cpp.

## Function Documentation

## ◆ ActivateOldShore()

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

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

Referenced by AfterLoadGRFs().

## ◆ ActivateOldTramDepot()

static void ActivateOldTramDepot | ( |  | ) |
| static

Relocate the old tram depot sprites to the new position, if no new ones were loaded.

Definition at line 1464 of file newgrf.cpp.

References _loaded_newgrf_features, GRFLoadedFeatures::tram, and TRAMWAY_REPLACE_DEPOT_WITH_TRACK.

Referenced by AfterLoadGRFs().

## ◆ AddBadgeToSpecs()

template<typename T >

void AddBadgeToSpecs | ( | T & | specs,
|  | GrfSpecFeature | feature,
|  | Badge & | badge
| ) |  |

Definition at line 1593 of file newgrf.cpp.

## ◆ AfterLoadGRFs()

static void AfterLoadGRFs | ( |  | ) |
| static

Finish loading NewGRFs and execute needed post-processing.

Definition at line 1632 of file newgrf.cpp.

References _gted, ActivateOldShore(), ActivateOldTramDepot(), BindAirportSpecs(), BuildIndustriesLegend(), BuildLinkStatsLegend(), CalculateRefitMasks(), CommitVehicleListOrderChanges(), FinaliseAirportsArray(), FinaliseBadges(), FinaliseCanals(), FinaliseCargoArray(), FinaliseEngineArray(), FinaliseHouseArray(), FinaliseIndustriesArray(), FinaliseObjectsArray(), FinalisePriceBaseMultipliers(), FinaliseStringMapping(), GetRailTypeByLabel(), GetRoadTypeByLabel(), InitGRFTownGeneratorNames(), InitializeSortedCargoSpecs(), InitRailTypes(), InitRoadTypes(), INVALID_RAILTYPE, INVALID_ROADTYPE, Engine::IterateType(), RoadIsTram, GRFFile::roadtype_list, ROADTYPE_ROAD, ROADTYPE_TRAM, RTT_ROAD, RTT_TRAM, SetYearEngineAgingStops(), SortIndustryTypes(), GRFFile::tramtype_list, VEH_ROAD, and VEH_TRAIN.

Referenced by LoadNewGRF().

## ◆ BuildCargoTranslationMap()

static void BuildCargoTranslationMap | ( |  | ) |
| static

Construct the Cargo Mapping.

Note
  This is the reverse of a cargo translation table

Definition at line 537 of file newgrf.cpp.

References GRFFile::cargo_map, find_index(), GetCargoTranslationTable(), GrfProcessingState::grffile, and CargoSpec::Iterate().

Referenced by LoadNewGRF().

## ◆ CalculateRefitMasks()

static void CalculateRefitMasks | ( |  | ) |
| static

Precalculate refit masks from cargo classes for all vehicles.

< Set if the vehicle shall carry only the default cargo

Definition at line 647 of file newgrf.cpp.

References _cargo_mask, _gted, _settings_game, _standard_cargo_mask, Armoured, Bulk, CALLBACK_FAILED, RailVehicleInfo::capacity, GRFFile::cargo_list, GRFFile::cargo_map, CBID_VEHICLE_CUSTOM_REFIT, EngineInfo::climates, ClrBit(), CT_INVALID, CT_PASSENGERS, CustomRefit, ErrorUnknownCallbackResult(), Express, FindFirstBit(), GameSettings::game_creation, GetActiveCargoLabel(), GetVehicleCallback(), HasBit(), IsDefaultCargo(), IsValidCargoType(), CargoSpec::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), GameCreationSettings::landscape, Liquid, Mail, GRFTempEngineData::NONEMPTY, NUM_CARGO, ShipVehicleInfo::old_refittable, Passengers, PieceGoods, RAILVEH_WAGON, Refrigerated, SetBit(), VEH_AIRCRAFT, VEH_SHIP, and VEH_TRAIN.

Referenced by AfterLoadGRFs().

## ◆ ClearTemporaryNewGRFData()

static void ClearTemporaryNewGRFData | ( | GRFFile * | gf | ) |
| static

Reset all NewGRFData that was used only while processing data.

Definition at line 124 of file newgrf.cpp.

References GRFFile::labels.

Referenced by DisableGrf(), and LoadNewGRF().

## ◆ ConvertTTDBasePrice()

void ConvertTTDBasePrice | ( | uint32_t | base_pointer,
|  | std::string_view | 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.

Parameters

  | base_pointer | TTD(P) Base Price Pointer
  | error_location | Function name for grf error messages
  [out] | 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 332 of file newgrf.cpp.

Referenced by RailVehicleChangeInfo(), and RoadVehicleChangeInfo().

## ◆ DecodeSpecialSprite()

static void DecodeSpecialSprite | ( | ReusableBuffer< uint8_t > & | allocator,
|  | uint | num,
|  | GrfLoadingStage | stage
| ) |  |
| static

Definition at line 1252 of file newgrf.cpp.

## ◆ DisableGrf()

GRFError * DisableGrf | ( | StringID | message,
|  | GRFConfig * | config
| ) |  |

Disable a GRF.

Parameters

  message | Error message or STR_NULL.
  config | GRFConfig to disable, nullptr for current.

Returns
  Error message of the GRF for further customisation.

Definition at line 135 of file newgrf.cpp.

References ClearTemporaryNewGRFData(), GRFConfig::errors, GCS_DISABLED, GetFileByGRFID(), GrfProcessingState::grfconfig, GrfProcessingState::grffile, GRFIdentifier::grfid, GRFConfig::ident, GrfProcessingState::nfo_line, GRFError::nfo_line, GrfProcessingState::skip_sprites, and GRFConfig::status.

Referenced by DisableStaticNewGRFInfluencingNonStaticNewGRFs(), FeatureTownName(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), LoadNewGRFFileFromFile(), ParamSet(), ReadSpriteLayout(), ReadSpriteLayoutRegisters(), ReadSpriteLayoutSprite(), TownHouseChangeInfo(), and TranslateGRFStrings().

## ◆ DisableStaticNewGRFInfluencingNonStaticNewGRFs()

void DisableStaticNewGRFInfluencingNonStaticNewGRFs | ( | GRFConfig & | c | ) |

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

References GRFError::data, DisableGrf(), GRFConfig::GetName(), and GrfProcessingState::grfconfig.

Referenced by ParamSet().

## ◆ EnsureEarlyHouse()

static void EnsureEarlyHouse | ( | HouseZones | bitmask | ) |
| static

Make sure there is at least one house available in the year 0 for the given climate / housezone combination.

Parameters

  bitmask | The climate and housezone to check for. Exactly one climate bit and one housezone bit should be set.

Definition at line 1013 of file newgrf.cpp.

References TimerGameConst< struct Calendar >::MAX_YEAR, TimerGameConst< struct Calendar >::MIN_YEAR, and HouseSpec::Specs().

Referenced by FinaliseHouseArray().

## ◆ FinaliseAirportsArray()

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

References _grf_files.

Referenced by AfterLoadGRFs().

## ◆ FinaliseBadges()

static void FinaliseBadges | ( |  | ) |
| static

Finish up applying badges to things.

Definition at line 1603 of file newgrf.cpp.

References _grf_files, AddBadgeClassesToConfiguration(), ApplyBadgeFeaturesToClassBadges(), Badge::features, GetBadgeByLabel(), Badge::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set().

Referenced by AfterLoadGRFs().

## ◆ FinaliseCanals()

static void FinaliseCanals | ( |  | ) |
| static

Set to use the correct action0 properties for each canal feature.

Definition at line 843 of file newgrf.cpp.

References _water_feature.

Referenced by AfterLoadGRFs().

## ◆ FinaliseCargoArray()

void FinaliseCargoArray | ( |  | ) |

Check for invalid cargoes.

Definition at line 937 of file newgrf.cpp.

Referenced by AfterLoadGRFs().

## ◆ FinaliseEngineArray()

static void FinaliseEngineArray | ( |  | ) |
| static

Check for invalid engines.

Definition at line 854 of file newgrf.cpp.

References _loaded_newgrf_features, _settings_game, AppendCopyableBadgeList(), GameSettings::game_creation, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), GetEngineLiveryScheme(), GetNewEngineID(), GetRailTypeInfo(), GetRoadTypeInfo(), HasVariants, IsFolded, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), GameCreationSettings::landscape, RAILVEH_WAGON, RoadVehicleInfo::roadtype, SetBit(), GRFLoadedFeatures::used_liveries, VEH_ROAD, and VEH_TRAIN.

Referenced by AfterLoadGRFs().

## ◆ FinaliseHouseArray()

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

References _grf_files, HouseSpec::accepts_cargo, HouseSpec::accepts_cargo_label, HouseSpec::building_flags, HouseSpec::cargo_acceptance, EnsureEarlyHouse(), HouseSpec::Get(), GetClimateMaskForLandscape(), IsHouseSpecValid(), IsValidCargoType(), lengthof, NUM_HOUSES, HouseOverrideManager::SetEntitySpec(), and HouseSpec::Specs().

Referenced by AfterLoadGRFs().

## ◆ FinaliseIndustriesArray()

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

References _grf_files, GetActiveCargoLabel(), IsValidCargoType(), MapNewGRFIndustryType(), and IndustryOverrideManager::SetEntitySpec().

Referenced by AfterLoadGRFs().

## ◆ FinaliseObjectsArray()

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

References _grf_files, ObjectSpec::BindToClasses(), and ObjectOverrideManager::SetEntitySpec().

Referenced by AfterLoadGRFs().

## ◆ FinalisePriceBaseMultipliers()

static void FinalisePriceBaseMultipliers | ( |  | ) |
| static

Decide whether price base multipliers of grfs shall apply globally or only to the grf specifying them.

Features, to which '_grf_id_overrides' applies. Currently vehicle features only.

Definition at line 1479 of file newgrf.cpp.

References _grf_files, Debug, PriceBaseSpec::fallback_price, PriceBaseSpec::grf_feature, GRFFile::grf_features, GRFFile::price_base_multipliers, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetPriceBaseMultiplier(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by AfterLoadGRFs().

## ◆ GetActiveCargoLabel() [1/2]

static CargoLabel GetActiveCargoLabel | ( | const std::initializer_list< CargoLabel > & | labels | ) |
| static

Find first cargo label that exists and is active from a list of cargo labels.

Parameters

  labels | List of cargo labels.

Returns
  First cargo label in list that exists, or CT_INVALID if none exist.

Definition at line 612 of file newgrf.cpp.

References CT_INVALID.

Referenced by CalculateRefitMasks(), FinaliseIndustriesArray(), and GetActiveCargoLabel().

## ◆ GetActiveCargoLabel() [2/2]

static CargoLabel GetActiveCargoLabel | ( | const std::variant< CargoLabel, MixedCargoType > & | label | ) |
| static

Get active cargo label from either a cargo label or climate-dependent mixed cargo type.

Parameters

  label | Cargo label or climate-dependent mixed cargo type.

Returns
  Active cargo label, or CT_INVALID if cargo label is not active.

Definition at line 626 of file newgrf.cpp.

References GetActiveCargoLabel(), MCT_GRAIN_WHEAT_MAIZE, MCT_LIVESTOCK_FRUIT, and MCT_VALUABLES_GOLD_DIAMONDS.

## ◆ GetAllGRFFiles()

std::span< const GRFFile > GetAllGRFFiles | ( |  | ) |

Definition at line 65 of file newgrf.cpp.

## ◆ GetCargoTranslationTable()

std::span< const CargoLabel > GetCargoTranslationTable | ( | const GRFFile & | grffile | ) |

Get the cargo translation table to use for the given GRF file.

Parameters

  grffile | GRF file.

Returns
  Readonly cargo translation table to use.

Definition at line 521 of file newgrf.cpp.

References GRFFile::cargo_list, GetClimateDependentCargoTranslationTable(), and GetClimateIndependentCargoTranslationTable().

Referenced by BuildCargoTranslationMap().

## ◆ GetCurrentGRFOverride()

GRFFile * GetCurrentGRFOverride | ( |  | ) |

Get overridden GRF for current GRF if present.

Returns
  Overridden GRFFile if present, or nullptr.

Definition at line 196 of file newgrf.cpp.

References GetFileByGRFID(), and GrfProcessingState::grffile.

Referenced by LoadTranslationTable().

## ◆ GetFileByFilename()

static GRFFile * GetFileByFilename | ( | const std::string & | filename | ) |
| static

Obtain a NewGRF file by its filename.

Parameters

  filename | The filename to obtain the file for.

Returns
  The file.

Definition at line 116 of file newgrf.cpp.

References _grf_files.

Referenced by InitNewGRFFile(), and LoadNewGRFFile().

## ◆ GetFileByGRFID()

GRFFile * GetFileByGRFID | ( | uint32_t | grfid | ) |

Obtain a NewGRF file by its grfID.

Parameters

  grfid | The grfID to obtain the file for

Returns
  The file.

Definition at line 104 of file newgrf.cpp.

References _grf_files.

Referenced by DisableGrf(), GetCurrentGRFOverride(), LanguageMap::GetLanguageMap(), GetNewEngine(), ImportGRFSound(), LoadNewGRF(), and ParamSet().

## ◆ GetNewEngine()

Engine * GetNewEngine | ( | const GRFFile * | file,
|  | VehicleType | type,
|  | uint16_t | internal_id,
|  | bool | static_access
| ) |  |

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 nullptr instead of allocating a new engine. (Used for static Action 0x04).

Returns
  The requested engine.

Definition at line 214 of file newgrf.cpp.

References _engine_counts, _gted, _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::CanAllocateItem(), VehicleSettings::dynamic_engines, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), GetFileByGRFID(), EngineOverrideManager::GetID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetPoolSize(), GetRailTypeInfo(), Engine::grf_prop, GRFFilePropsBase::HasGrfFile(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, RailTypeInfo::label, GRFFilePropsBase::SetGRFFile(), EngineOverrideManager::UseUnreservedID(), VEH_TRAIN, and GameSettings::vehicle.

Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), and ShipVehicleChangeInfo().

## ◆ GetNewEngineID()

EngineID GetNewEngineID | ( | const GRFFile * | file,
|  | VehicleType | type,
|  | uint16_t | internal_id
| ) |  |

Return the ID of a new engine.

Parameters

  file | The NewGRF file providing the engine.
  type | The Vehicle type.
  internal_id | NewGRF-internal ID of the engine.

Returns
  The new EngineID.

Note
  depending on the dynamic_engine setting and a possible override property the grfID may be unique or overwriting or partially re-defining properties of an existing engine.

Definition at line 296 of file newgrf.cpp.

References _settings_game, VehicleSettings::dynamic_engines, EngineOverrideManager::GetID(), and GameSettings::vehicle.

Referenced by FinaliseEngineArray(), and GetNextArticulatedPart().

## ◆ 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

  severity | debugging severity level, see debug.h
  msg | the message

Definition at line 90 of file newgrf.cpp.

References Debug, GRFConfig::filename, GrfProcessingState::grfconfig, and GrfProcessingState::nfo_line.

## ◆ GRFUnsafe()

void GRFUnsafe | ( | ByteReader & |  | ) |

Set the current NewGRF as unsafe for static use.

Note
  Used during safety scan on unsafe actions.

Definition at line 373 of file newgrf.cpp.

References GRFConfig::flags, GrfProcessingState::grfconfig, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), GrfProcessingState::skip_sprites, and Unsafe.

## ◆ InitGRFTownGeneratorNames()

void InitGRFTownGeneratorNames | ( |  | ) |
| extern

Allocate memory for the NewGRF town names.

Definition at line 80 of file newgrf_townname.cpp.

References GRFTownName::styles.

Referenced by AfterLoadGRFs().

## ◆ InitNewGRFFile()

static void InitNewGRFFile | ( | const GRFConfig & | config | ) |
| static

Prepare loading a NewGRF file with its config.

Parameters

  config | The NewGRF configuration struct with name, id, parameters and alike.

Definition at line 554 of file newgrf.cpp.

References _grf_files, GRFConfig::filename, GetFileByFilename(), and GrfProcessingState::grffile.

Referenced by LoadNewGRF().

## ◆ IsHouseSpecValid()

static bool IsHouseSpecValid | ( | HouseSpec & | hs,
|  | const HouseSpec * | next1,
|  | const HouseSpec * | next2,
|  | const HouseSpec * | next3,
|  | const std::string & | 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 967 of file newgrf.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), HouseSpec::building_availability, HouseSpec::building_flags, Debug, HouseSpec::enabled, HouseSpec::Get(), HouseSpec::grf_prop, GRFFilePropsBase::local_id, and HouseSpec::population.

Referenced by FinaliseHouseArray().

## ◆ LoadNewGRF()

void LoadNewGRF | ( | SpriteID | load_index,
|  | uint | num_baseset
| ) |  |

Load all the NewGRFs.

Parameters

  load_index | The offset for the first sprite to add.
  num_baseset | Number of NewGRFs at the front of the list to look up in the baseset dir instead of the newgrf dir.

Definition at line 1758 of file newgrf.cpp.

References _display_opt, _grfconfig, _networking, _settings_game, AfterLoadGRFs(), BASESET_DIR, BuildCargoTranslationMap(), GrfProcessingState::ClearDataForNextFile(), ClearTemporaryNewGRFData(), TimerGameCalendar::ConvertYMDToDate(), TimerGameEconomy::ConvertYMDToDate(), TimerGameTick::counter, TimerGameCalendar::date, TimerGameEconomy::date, TimerGameCalendar::date_fract, TimerGameEconomy::date_fract, Debug, FioCheckFileExists(), GameSettings::game_creation, GCS_ACTIVATED, GCS_DISABLED, GCS_INITIALISED, GCS_NOT_FOUND, GCS_UNKNOWN, GetFileByGRFID(), GrfProcessingState::grfconfig, GrfProcessingState::grffile, InitializePatchFlags(), InitNewGRFFile(), InitOnly, LoadNewGRFFile(), NETWORK_MAX_GRF_COUNT, NEWGRF_DIR, Reserved, ResetNewGRFData(), SetNewGRFOverride(), GrfProcessingState::spriteid, GrfProcessingState::stage, GameCreationSettings::starting_year, Static, System, TimerGameCalendar::year, and TimerGameEconomy::year.

Referenced by LoadSpriteTables().

## ◆ LoadNewGRFFile()

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

Load a particular NewGRF.

Parameters

  config | The configuration of the to be loaded NewGRF.
  stage | The loading stage of the NewGRF.
  subdir | The sub directory to find the NewGRF in.
  temporary | The 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 1391 of file newgrf.cpp.

References GRFConfig::filename, GRFConfig::flags, GCS_INITIALISED, GetFileByFilename(), GrfProcessingState::grffile, GRFP_USE_MASK, LoadNewGRFFileFromFile(), OpenCachedSpriteFile(), GRFConfig::palette, Reserved, GRFConfig::status, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by FillGRFDetails(), and LoadNewGRF().

## ◆ LoadNewGRFFileFromFile()

static void LoadNewGRFFileFromFile | ( | GRFConfig & | config,
|  | GrfLoadingStage | stage,
|  | SpriteFile & | file
| ) |  |
| static

Load a particular NewGRF from a SpriteFile.

Parameters

  config | The configuration of the to be loaded NewGRF.
  stage | The loading stage of the NewGRF.
  file | The file to load the GRF data from.

Definition at line 1295 of file newgrf.cpp.

References GrfProcessingState::ClearDataForNextFile(), Debug, DisableGrf(), GrfProcessingState::file, GRFConfig::filename, SpriteFile::GetContainerVersion(), GrfProcessingState::grfconfig, GrfProcessingState::nfo_line, RandomAccessFile::ReadByte(), RandomAccessFile::ReadDword(), ReadGRFSpriteOffsets(), RandomAccessFile::ReadWord(), GrfProcessingState::skip_sprites, RandomAccessFile::SkipBytes(), and SkipSpriteData().

Referenced by LoadNewGRFFile().

## ◆ ResetCallbacks()

void ResetCallbacks | ( | bool | final | ) |
| extern

Definition at line 267 of file newgrf_act2.cpp.

## ◆ ResetGRM()

void ResetGRM | ( |  | ) |
| extern

Definition at line 37 of file newgrf_actd.cpp.

## ◆ ResetNewGRF()

static void ResetNewGRF | ( |  | ) |
| static

Reset and clear all NewGRFs.

Definition at line 382 of file newgrf.cpp.

References _grf_files, _grfconfig, GrfProcessingState::grfconfig, and GrfProcessingState::grffile.

Referenced by ResetNewGRFData().

## ◆ ResetNewGRFData()

void ResetNewGRFData | ( |  | ) |

Reset all NewGRF loaded data.

Definition at line 408 of file newgrf.cpp.

References _gted, _loaded_newgrf_features, _misc_grf_features, _settings_game, _water_feature, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::CleanPool(), CleanUpStrings(), ClearSnowLine(), GameSettings::game_creation, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetPoolSize(), GetRailTypeInfo(), GRFLoadedFeatures::has_2CC, Engine::IterateType(), RailTypeInfo::label, GameCreationSettings::landscape, NewGRFClass< Tspec, Tindex, Tmax >::Reset(), AirportSpec::ResetAirports(), AirportTileSpec::ResetAirportTiles(), ResetBadges(), ResetBridges(), ResetCurrencies(), ResetFaces(), ResetGenericCallbacks(), ResetIndustries(), ResetNewGRF(), ResetNewGRFErrors(), ResetObjects(), ResetPriceBaseMultipliers(), ResetRailTypes(), ResetRoadTypes(), SetupCargoForClimate(), SetupEngines(), GRFLoadedFeatures::shore, SHORE_REPLACE_NONE, GRFLoadedFeatures::tram, TRAMWAY_REPLACE_DEPOT_NONE, GRFLoadedFeatures::used_liveries, and VEH_TRAIN.

Referenced by LoadNewGRF(), and ShutdownGame().

## ◆ ResetNewGRFErrors()

static void ResetNewGRFErrors | ( |  | ) |
| static

Clear all NewGRF errors.

Definition at line 395 of file newgrf.cpp.

References _grfconfig.

Referenced by ResetNewGRFData().

## ◆ ResetPersistentNewGRFData()

void ResetPersistentNewGRFData | ( |  | ) |

Reset NewGRF data which is stored persistently in savegames.

Definition at line 505 of file newgrf.cpp.

References OverrideManagerBase::ResetMapping(), and EngineOverrideManager::ResetToDefaultMapping().

## ◆ SetNewGRFOverride()

void SetNewGRFOverride | ( | uint32_t | source_grfid,
|  | uint32_t | target_grfid
| ) |  |

Set the override for a NewGRF.

Parameters

  source_grfid | The grfID which wants to override another NewGRF.
  target_grfid | The grfID which is being overridden.

Definition at line 181 of file newgrf.cpp.

Referenced by LoadNewGRF().

## ◆ TranslateRefitMask()

CargoTypes TranslateRefitMask | ( | uint32_t | refit_mask | ) |

Translate the refit mask.

refit_mask is uint32_t as it has not been mapped to CargoTypes.

Definition at line 315 of file newgrf.cpp.

References GetCargoTranslation(), GrfProcessingState::grffile, IsValidCargoType(), and SetBit().

Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), and StationChangeInfo().

## Variable Documentation

## ◆ _cur_gps

GrfProcessingState _cur_gps

Definition at line 76 of file newgrf.cpp.

## ◆ _grf_files

std::vector<GRFFile> _grf_files
| static

List of all loaded GRF files.

Definition at line 63 of file newgrf.cpp.

Referenced by FinaliseAirportsArray(), FinaliseBadges(), FinaliseHouseArray(), FinaliseIndustriesArray(), FinaliseObjectsArray(), FinalisePriceBaseMultipliers(), GetFileByFilename(), GetFileByGRFID(), InitNewGRFFile(), and ResetNewGRF().

## ◆ _grf_id_overrides

std::map<uint32_t, uint32_t> _grf_id_overrides
| static

Definition at line 174 of file newgrf.cpp.

## ◆ _gted

TypedIndexContainer<std::vector<GRFTempEngineData>, EngineID> _gted

Temporary engine data used during NewGRF loading.

Definition at line 78 of file newgrf.cpp.

Referenced by AfterLoadGRFs(), AircraftVehicleChangeInfo(), CalculateRefitMasks(), GetNewEngine(), RailVehicleChangeInfo(), ResetNewGRFData(), RoadVehicleChangeInfo(), and ShipVehicleChangeInfo().

## ◆ _loaded_newgrf_features

GRFLoadedFeatures _loaded_newgrf_features

Indicates which are the newgrf features currently loaded ingame.

Definition at line 74 of file newgrf.cpp.

Referenced by ActivateOldShore(), ActivateOldTramDepot(), AircraftVehicleChangeInfo(), DrawRoadDepotSprite(), DrawTile_Road(), SelectCompanyLiveryWindow::DrawWidget(), FinaliseEngineArray(), ObjectChangeInfo(), SelectCompanyLiveryWindow::OnClick(), SelectCompanyLiveryWindow::OnDropdownSelect(), SelectCompanyLiveryWindow::OnInvalidateData(), RailVehicleChangeInfo(), ResetNewGRFData(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), and SelectCompanyLiveryWindow::UpdateWidgetSize().

## ◆ _misc_grf_features

GrfMiscBits _misc_grf_features {}

Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.

Definition at line 71 of file newgrf.cpp.

Referenced by GetGlobalVariable(), HasGrfMiscBit(), ParamSet(), and ResetNewGRFData().