OpenTTD Source 20250331-master-g3c15e0c889
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 "../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, const char *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
paramvariable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first).
valuereturns the value of the variable.
grffileNewGRF querying the variable
Returns
true iff the variable is known and the value is returned in 'value'.

Definition at line 417 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(), GetRailTypeInfo(), GetSnowLine(), GrfProcessingState::grfconfig, GrfProcessingState::grffile, 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()

◆ GlobalVarReserveInfo()

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

Definition at line 333 of file newgrf_act0_globalvar.cpp.

◆ LoadBadgeTranslationTable()

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

Definition at line 69 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
firstID of the first translation table entry.
lastID of the last translation table entry.
bufThe property value.
gettableFunction to get storage for the translation table.
nameName of the table for debug output.
Returns
ChangeInfoResult.

Definition at line 44 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
readerThe source of the DWord.
Returns
The read DWord as string.

Definition at line 92 of file newgrf_act0_globalvar.cpp.

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

Referenced by GlobalVarChangeInfo().