OpenTTD Source 20260218-master-g2123fca5ea
newgrf_act14.cpp File Reference

NewGRF Action 0x14 handler. More...

#include "../stdafx.h"
#include "../debug.h"
#include "../newgrf_text.h"
#include "newgrf_bytereader.h"
#include "newgrf_internal.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  AllowedSubtags
 Data structure to store the allowed id/type combinations for action 14. More...

Typedefs

using DataHandler = bool(*)(size_t len, ByteReader &buf)
 Callback to read binary data.
using TextHandler = bool(*)(uint8_t langid, std::string_view str)
 Callback to read text data.
using BranchHandler = bool(*)(ByteReader &buf)
 Callback for parsing branch nodes.

Functions

static bool ChangeGRFName (uint8_t langid, std::string_view str)
 Callback function for 'INFO'->'NAME' to add a translation to the newgrf name.
static bool ChangeGRFDescription (uint8_t langid, std::string_view str)
 Callback function for 'INFO'->'DESC' to add a translation to the newgrf description.
static bool ChangeGRFURL (uint8_t langid, std::string_view str)
 Callback function for 'INFO'->'URL_' to set the newgrf url.
static bool ChangeGRFNumUsedParams (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'NPAR' to set the number of valid parameters.
static bool ChangeGRFPalette (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'PALS' to set the number of valid parameters.
static bool ChangeGRFBlitter (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'BLTR' to set the blitter info.
static bool ChangeGRFVersion (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'VRSN' to the version of the NewGRF.
static bool ChangeGRFMinVersion (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'MINV' to the minimum compatible version of the NewGRF.
static bool ChangeGRFParamName (uint8_t langid, std::string_view str)
 Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter.
static bool ChangeGRFParamDescription (uint8_t langid, std::string_view str)
 Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter.
static bool ChangeGRFParamType (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.
static bool ChangeGRFParamLimits (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'PARAM'->param_num->'LIMI' to set the min/max value of a parameter.
static bool ChangeGRFParamMask (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use.
static bool ChangeGRFParamDefault (size_t len, ByteReader &buf)
 Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.
static bool SkipUnknownInfo (ByteReader &buf, uint8_t type)
 Try to skip the current node and all subnodes (if it's a branch node).
static bool HandleNodes (ByteReader &buf, std::span< const AllowedSubtags > subtags)
 Handle the contents of a 'C' choice of an Action14.
static bool ChangeGRFParamValueNames (ByteReader &buf)
 Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (type uint/enum) or the names of some bits (type bitmask).
static bool HandleParameterInfo (ByteReader &buf)
 Callback function for 'INFO'->'PARA' to set extra information about the parameters.
static bool HandleNode (uint8_t type, uint32_t id, ByteReader &buf, std::span< const AllowedSubtags > subtags)
 Handle the nodes of an Action14.
static void StaticGRFInfo (ByteReader &buf)
 Handle Action 0x14.

Variables

static GRFParameterInfo_cur_parameter
 The parameter which info is currently changed by the newgrf.
static constexpr AllowedSubtags _tags_parameters []
 Action14 parameter tags.
static constexpr AllowedSubtags _tags_info []
 Action14 tags for the INFO node.
static constexpr AllowedSubtags _tags_root []
 Action14 root tags.

Detailed Description

NewGRF Action 0x14 handler.

Definition in file newgrf_act14.cpp.

Typedef Documentation

◆ BranchHandler

using BranchHandler = bool(*)(ByteReader &buf)

Callback for parsing branch nodes.

Parameters
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 242 of file newgrf_act14.cpp.

◆ DataHandler

using DataHandler = bool(*)(size_t len, ByteReader &buf)

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 227 of file newgrf_act14.cpp.

◆ TextHandler

using TextHandler = bool(*)(uint8_t langid, std::string_view str)

Callback to read text data.

Parameters
langidThe language the text is for.
strThe actual text.
Returns
true iff the data could be processed.

Definition at line 235 of file newgrf_act14.cpp.

Function Documentation

◆ ChangeGRFBlitter()

bool ChangeGRFBlitter ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'BLTR' to set the blitter info.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 78 of file newgrf_act14.cpp.

References GRFP_BLT_32BPP, GRFP_BLT_MASK, GRFP_BLT_UNSET, and ByteReader::ReadByte().

◆ ChangeGRFDescription()

bool ChangeGRFDescription ( uint8_t langid,
std::string_view str )
static

Callback function for 'INFO'->'DESC' to add a translation to the newgrf description.

Callback to read text data.

Parameters
langidThe language the text is for.
strThe actual text.
Returns
true iff the data could be processed.

Definition at line 26 of file newgrf_act14.cpp.

References AddGRFTextToList().

◆ ChangeGRFMinVersion()

bool ChangeGRFMinVersion ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'MINV' to the minimum compatible version of the NewGRF.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 113 of file newgrf_act14.cpp.

References ByteReader::ReadDWord().

◆ ChangeGRFName()

bool ChangeGRFName ( uint8_t langid,
std::string_view str )
static

Callback function for 'INFO'->'NAME' to add a translation to the newgrf name.

Callback to read text data.

Parameters
langidThe language the text is for.
strThe actual text.
Returns
true iff the data could be processed.

Definition at line 19 of file newgrf_act14.cpp.

References AddGRFTextToList().

◆ ChangeGRFNumUsedParams()

bool ChangeGRFNumUsedParams ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'NPAR' to set the number of valid parameters.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 40 of file newgrf_act14.cpp.

References ByteReader::ReadByte().

◆ ChangeGRFPalette()

bool ChangeGRFPalette ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'PALS' to set the number of valid parameters.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 52 of file newgrf_act14.cpp.

References GRFP_GRF_ANY, GRFP_GRF_DOS, GRFP_GRF_MASK, GRFP_GRF_UNSET, GRFP_GRF_WINDOWS, and ByteReader::ReadByte().

◆ ChangeGRFParamDefault()

bool ChangeGRFParamDefault ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 209 of file newgrf_act14.cpp.

References _cur_parameter, and ByteReader::ReadDWord().

◆ ChangeGRFParamDescription()

bool ChangeGRFParamDescription ( uint8_t langid,
std::string_view str )
static

Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter.

Callback to read text data.

Parameters
langidThe language the text is for.
strThe actual text.
Returns
true iff the data could be processed.

Definition at line 142 of file newgrf_act14.cpp.

References _cur_parameter, and AddGRFTextToList().

◆ ChangeGRFParamLimits()

bool ChangeGRFParamLimits ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'PARAM'->param_num->'LIMI' to set the min/max value of a parameter.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 166 of file newgrf_act14.cpp.

References _cur_parameter, PTYPE_UINT_ENUM, and ByteReader::ReadDWord().

◆ ChangeGRFParamMask()

bool ChangeGRFParamMask ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 188 of file newgrf_act14.cpp.

References _cur_parameter, and ByteReader::ReadByte().

◆ ChangeGRFParamName()

bool ChangeGRFParamName ( uint8_t langid,
std::string_view str )
static

Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter.

Callback to read text data.

Parameters
langidThe language the text is for.
strThe actual text.
Returns
true iff the data could be processed.

Definition at line 135 of file newgrf_act14.cpp.

References _cur_parameter, and AddGRFTextToList().

◆ ChangeGRFParamType()

bool ChangeGRFParamType ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 149 of file newgrf_act14.cpp.

References _cur_parameter, PTYPE_END, and ByteReader::ReadByte().

◆ ChangeGRFParamValueNames()

bool ChangeGRFParamValueNames ( ByteReader & buf)
static

Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (type uint/enum) or the names of some bits (type bitmask).

In both cases the format is the same: Each subnode should be a text node with the value/bit number as id. Callback for parsing branch nodes.

Parameters
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 269 of file newgrf_act14.cpp.

References _cur_parameter, AddGRFTextToList(), ByteReader::ReadByte(), ByteReader::ReadDWord(), ByteReader::ReadString(), and SkipUnknownInfo().

◆ ChangeGRFURL()

bool ChangeGRFURL ( uint8_t langid,
std::string_view str )
static

Callback function for 'INFO'->'URL_' to set the newgrf url.

Callback to read text data.

Parameters
langidThe language the text is for.
strThe actual text.
Returns
true iff the data could be processed.

Definition at line 33 of file newgrf_act14.cpp.

References AddGRFTextToList().

◆ ChangeGRFVersion()

bool ChangeGRFVersion ( size_t len,
ByteReader & buf )
static

Callback function for 'INFO'->'VRSN' to the version of the NewGRF.

Callback to read binary data.

Parameters
lenThe number of bytes to read.
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 100 of file newgrf_act14.cpp.

References ByteReader::ReadDWord().

◆ HandleNode()

bool HandleNode ( uint8_t type,
uint32_t id,
ByteReader & buf,
std::span< const AllowedSubtags > subtags )
static

Handle the nodes of an Action14.

Parameters
typeType of node.
idID.
bufBuffer.
subtagsAllowed subtags.
Returns
Whether all tags could be handled.

Definition at line 404 of file newgrf_act14.cpp.

References HandleNodes(), ByteReader::ReadByte(), ByteReader::ReadString(), ByteReader::ReadWord(), and SkipUnknownInfo().

Referenced by HandleNodes().

◆ HandleNodes()

bool HandleNodes ( ByteReader & buf,
std::span< const AllowedSubtags > subtags )
static

Handle the contents of a 'C' choice of an Action14.

Parameters
bufBuffer.
subtagsList of subtags.
Returns
Whether the nodes could all be handled.

Definition at line 457 of file newgrf_act14.cpp.

References HandleNode(), ByteReader::ReadByte(), and ByteReader::ReadDWord().

Referenced by HandleNode(), HandleParameterInfo(), and StaticGRFInfo().

◆ HandleParameterInfo()

bool HandleParameterInfo ( ByteReader & buf)
static

Callback function for 'INFO'->'PARA' to set extra information about the parameters.

Each subnode of 'INFO'->'PARA' should be a branch node with the parameter number as id. The first parameter has id 0. The maximum parameter that can be changed is set by 'INFO'->'NPAR' which defaults to 80. Callback for parsing branch nodes.

Parameters
bufThe buffer to read from.
Returns
true iff the data could be processed.

Definition at line 313 of file newgrf_act14.cpp.

References _cur_parameter, _tags_parameters, HandleNodes(), ByteReader::ReadByte(), ByteReader::ReadDWord(), and SkipUnknownInfo().

◆ SkipUnknownInfo()

bool SkipUnknownInfo ( ByteReader & buf,
uint8_t type )
static

Try to skip the current node and all subnodes (if it's a branch node).

Parameters
bufBuffer.
typeThe node type to skip.
Returns
True if we could skip the node, false if an error occurred.

Definition at line 364 of file newgrf_act14.cpp.

References ByteReader::ReadByte(), ByteReader::ReadDWord(), ByteReader::ReadString(), ByteReader::ReadWord(), and SkipUnknownInfo().

Referenced by ChangeGRFParamValueNames(), HandleNode(), HandleParameterInfo(), and SkipUnknownInfo().

◆ StaticGRFInfo()

void StaticGRFInfo ( ByteReader & buf)
static

Handle Action 0x14.

Parameters
bufBuffer.

Definition at line 472 of file newgrf_act14.cpp.

References _tags_root, and HandleNodes().

Variable Documentation

◆ _cur_parameter

GRFParameterInfo* _cur_parameter
static

◆ _tags_info

AllowedSubtags _tags_info[]
staticconstexpr
Initial value:
= {
AllowedSubtags{'URL_', ChangeGRFURL},
AllowedSubtags{'NPAR', ChangeGRFNumUsedParams},
AllowedSubtags{'PALS', ChangeGRFPalette},
AllowedSubtags{'BLTR', ChangeGRFBlitter},
AllowedSubtags{'VRSN', ChangeGRFVersion},
AllowedSubtags{'MINV', ChangeGRFMinVersion},
AllowedSubtags{'PARA', HandleParameterInfo},
}
static bool ChangeGRFNumUsedParams(size_t len, ByteReader &buf)
Callback function for 'INFO'->'NPAR' to set the number of valid parameters.
static bool ChangeGRFURL(uint8_t langid, std::string_view str)
Callback function for 'INFO'->'URL_' to set the newgrf url.
static bool ChangeGRFMinVersion(size_t len, ByteReader &buf)
Callback function for 'INFO'->'MINV' to the minimum compatible version of the NewGRF.
static bool HandleParameterInfo(ByteReader &buf)
Callback function for 'INFO'->'PARA' to set extra information about the parameters.
static bool ChangeGRFName(uint8_t langid, std::string_view str)
Callback function for 'INFO'->'NAME' to add a translation to the newgrf name.
static bool ChangeGRFDescription(uint8_t langid, std::string_view str)
Callback function for 'INFO'->'DESC' to add a translation to the newgrf description.
static bool ChangeGRFPalette(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PALS' to set the number of valid parameters.
static bool ChangeGRFVersion(size_t len, ByteReader &buf)
Callback function for 'INFO'->'VRSN' to the version of the NewGRF.
static bool ChangeGRFBlitter(size_t len, ByteReader &buf)
Callback function for 'INFO'->'BLTR' to set the blitter info.
Data structure to store the allowed id/type combinations for action 14.

Action14 tags for the INFO node.

Definition at line 340 of file newgrf_act14.cpp.

◆ _tags_parameters

AllowedSubtags _tags_parameters[]
staticconstexpr
Initial value:
= {
AllowedSubtags{'TYPE', ChangeGRFParamType},
AllowedSubtags{'LIMI', ChangeGRFParamLimits},
AllowedSubtags{'MASK', ChangeGRFParamMask},
AllowedSubtags{'VALU', ChangeGRFParamValueNames},
AllowedSubtags{'DFLT', ChangeGRFParamDefault},
}
static bool ChangeGRFParamType(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.
static bool ChangeGRFParamLimits(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'LIMI' to set the min/max value of a parameter.
static bool ChangeGRFParamDescription(uint8_t langid, std::string_view str)
Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter.
static bool ChangeGRFParamDefault(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.
static bool ChangeGRFParamValueNames(ByteReader &buf)
Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (ty...
static bool ChangeGRFParamMask(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use.
static bool ChangeGRFParamName(uint8_t langid, std::string_view str)
Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter.

Action14 parameter tags.

Definition at line 296 of file newgrf_act14.cpp.

Referenced by HandleParameterInfo().

◆ _tags_root

AllowedSubtags _tags_root[]
staticconstexpr
Initial value:
= {
AllowedSubtags{'INFO', std::make_pair(std::begin(_tags_info), std::end(_tags_info))},
}
static constexpr AllowedSubtags _tags_info[]
Action14 tags for the INFO node.

Action14 root tags.

Definition at line 353 of file newgrf_act14.cpp.

Referenced by StaticGRFInfo().