OpenTTD Source: src/newgrf/newgrf_act0_globalvar.cpp File Reference

OpenTTD Source 15.0-RC2

Functions
newgrf_act0_globalvar.cpp File Reference

NewGRF Action 0x00 handler for global variables. More...

`#include "../stdafx.h"`
`#include "../debug.h"`
`#include "../currency.h"`
`#include "../landscape.h"`
`#include "../language.h"`
`#include "../rev.h"`
`#include "../string_func.h"`
`#include "../core/utf8.hpp"`
`#include "../newgrf.h"`
`#include "../newgrf_badge.h"`
`#include "../newgrf_badge_type.h"`
`#include "../newgrf_cargo.h"`
`#include "../newgrf_engine.h"`
`#include "../newgrf_sound.h"`
`#include "../vehicle_base.h"`
`#include "../rail.h"`
`#include "newgrf_bytereader.h"`
`#include "newgrf_internal_vehicle.h"`
`#include "newgrf_internal.h"`
`#include "newgrf_stringmapping.h"`
`#include "table/strings.h"`
`#include "../safeguards.h"`

Go to the source code of this file.

## Functions
template<typename T , typename TGetTableFunc >
static ChangeInfoResult | LoadTranslationTable (uint first, uint last, ByteReader &buf, TGetTableFunc gettable, std::string_view name)
| Load a cargo- or railtype-translation table.
static ChangeInfoResult | LoadBadgeTranslationTable (uint first, uint last, ByteReader &buf, std::vector< BadgeID > &translation_table, std::string_view name)
static std::string | ReadDWordAsString (ByteReader &reader)
| Helper to read a DWord worth of bytes from the reader and to return it as a valid string.
static ChangeInfoResult | GlobalVarChangeInfo (uint first, uint last, int prop, ByteReader &buf)
| Define properties for global variables.
static ChangeInfoResult | GlobalVarReserveInfo (uint first, uint last, int prop, ByteReader &buf)
bool | GetGlobalVariable (uint8_t param, uint32_t *value, const GRFFile *grffile)
| Reads a variable common to VarAction2 and Action7/9/D.

## Detailed Description

NewGRF Action 0x00 handler for global variables.

Definition in file newgrf_act0_globalvar.cpp.

## Function Documentation

## ◆ GetGlobalVariable()

bool GetGlobalVariable | ( | uint8_t | param,
|  | uint32_t * | 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 418 of file newgrf_act0_globalvar.cpp.

References _misc_grf_features, _settings_game, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::base(), Clamp(), GameSettings::construction, TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate(), TimerGameTick::counter, TimerGameCalendar::date, TimerGameCalendar::date_fract, TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, VehicleSettings::disable_elrails, GameSettings::game_creation, GB(), GetGRFConfig(), GetRailTypeInfo(), GetSnowLine(), GRFP_USE_MASK, TimerGame< struct Calendar >::IsLeapYear(), GameCreationSettings::landscape, ConstructionSettings::map_height_limit, TimerGameConst< struct Calendar >::ORIGINAL_BASE_YEAR, TimerGameConst< struct Calendar >::ORIGINAL_MAX_YEAR, GRFConfig::palette, RAILTYPE_ELECTRIC, RAILTYPE_MAGLEV, RAILTYPE_MONO, RAILTYPE_RAIL, VehicleSettings::road_side, SB(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SP_CUSTOM, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TILE_HEIGHT, to_underlying(), GRFFile::traininfo_vehicle_pitch, GRFFile::traininfo_vehicle_width, TrainWidth32Pixels, GameSettings::vehicle, and TimerGameCalendar::year.

## ◆ GlobalVarChangeInfo()

static ChangeInfoResult GlobalVarChangeInfo | ( | uint | first,
|  | uint | last,
|  | int | prop,
|  | ByteReader & | buf
| ) |  |
| static

Define properties for global variables.

Parameters

  first | ID of the first global var.
  last | ID of the last global var.
  prop | The property to change.
  buf | The property value.

Returns
  ChangeInfoResult.

Definition at line 108 of file newgrf_act0_globalvar.cpp.

References _currency_specs, _settings_game, AddStringForMapping(), GRFFile::badge_list, GRFFile::cargo_list, CIR_SUCCESS, CIR_UNKNOWN, GameSettings::construction, CURRENCY_END, DecodeUtf8(), GB(), LanguagePackHeader::GetCaseIndex(), LanguagePackHeader::GetGenderIndex(), GetLanguage(), GetNewgrfCurrencyIdConverted(), GrfProcessingState::grffile, IsSnowLineSet(), GRFFile::language_map, ConstructionSettings::map_height_limit, MAX_LANG, MAX_NUM_CASES, MAX_NUM_GENDERS, LanguageMap::Mapping::newgrf_id, NFO_UTF8_IDENTIFIER, LanguageMap::Mapping::openttd_id, GRFFile::price_base_multipliers, GRFFile::railtype_list, ByteReader::ReadByte(), ByteReader::ReadDWord(), ReadDWordAsString(), ByteReader::ReadString(), ByteReader::ReadWord(), GRFFile::roadtype_list, SetSnowLine(), SNOW_LINE_DAYS, SNOW_LINE_MONTHS, StrMakeValid(), StrMakeValidInPlace(), and GRFFile::tramtype_list.

## ◆ GlobalVarReserveInfo()

static ChangeInfoResult GlobalVarReserveInfo | ( | uint | first,
|  | uint | last,
|  | int | prop,
|  | ByteReader & | buf
| ) |  |
| static

Definition at line 334 of file newgrf_act0_globalvar.cpp.

## ◆ LoadBadgeTranslationTable()

static ChangeInfoResult LoadBadgeTranslationTable | ( | uint | first,
|  | uint | last,
|  | ByteReader & | buf,
|  | std::vector< BadgeID > & | translation_table,
|  | std::string_view | name
| ) |  |
| static

Definition at line 70 of file newgrf_act0_globalvar.cpp.

## ◆ LoadTranslationTable()

template<typename T , typename TGetTableFunc >

static ChangeInfoResult LoadTranslationTable | ( | uint | first,
|  | uint | last,
|  | ByteReader & | buf,
|  | TGetTableFunc | gettable,
|  | std::string_view | name
| ) |  |
| static

Load a cargo- or railtype-translation table.

Parameters

  first | ID of the first translation table entry.
  last | ID of the last translation table entry.
  buf | The property value.
  gettable | Function to get storage for the translation table.
  name | Name of the table for debug output.

Returns
  ChangeInfoResult.

Definition at line 45 of file newgrf_act0_globalvar.cpp.

References CIR_INVALID_ID, CIR_SUCCESS, GetCurrentGRFOverride(), GrfProcessingState::grffile, and ByteReader::ReadDWord().

## ◆ ReadDWordAsString()

static std::string ReadDWordAsString | ( | ByteReader & | reader | ) |
| static

Helper to read a DWord worth of bytes from the reader and to return it as a valid string.

Parameters

  reader | The source of the DWord.

Returns
  The read DWord as string.

Definition at line 93 of file newgrf_act0_globalvar.cpp.

References ByteReader::ReadByte(), and StrMakeValid().

Referenced by GlobalVarChangeInfo().