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

OpenTTD Source 15.3

Data Structures | Typedefs | Functions | Variables
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
typedef bool(* | DataHandler) (size_t, ByteReader &)
| Type of callback function for binary nodes.
typedef bool(* | TextHandler) (uint8_t, std::string_view str)
| Type of callback function for text nodes.
typedef bool(* | BranchHandler) (ByteReader &)
| Type of callback function for 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

typedef bool(* BranchHandler) (ByteReader &)

Type of callback function for branch nodes.

Definition at line 223 of file newgrf_act14.cpp.

## ◆ DataHandler

typedef bool(* DataHandler) (size_t, ByteReader &)

Type of callback function for binary nodes.

Definition at line 221 of file newgrf_act14.cpp.

## ◆ TextHandler

typedef bool(* TextHandler) (uint8_t, std::string_view str)

Type of callback function for text nodes.

Definition at line 222 of file newgrf_act14.cpp.

## Function Documentation

## ◆ ChangeGRFBlitter()

static bool ChangeGRFBlitter | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 78 of file newgrf_act14.cpp.

References GrfProcessingState::grfconfig, GRFP_BLT_32BPP, GRFP_BLT_UNSET, GRFConfig::palette, and ByteReader::ReadByte().

## ◆ ChangeGRFDescription()

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

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

Definition at line 26 of file newgrf_act14.cpp.

References AddGRFTextToList(), GrfProcessingState::grfconfig, GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::info.

## ◆ ChangeGRFMinVersion()

static bool ChangeGRFMinVersion | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 113 of file newgrf_act14.cpp.

References GrfProcessingState::grfconfig, GRFConfig::min_loadable_version, ByteReader::ReadDWord(), and GRFConfig::version.

## ◆ ChangeGRFName()

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

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

Definition at line 19 of file newgrf_act14.cpp.

References AddGRFTextToList(), GrfProcessingState::grfconfig, GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::name.

## ◆ ChangeGRFNumUsedParams()

static bool ChangeGRFNumUsedParams | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 40 of file newgrf_act14.cpp.

References GrfProcessingState::grfconfig, GRFConfig::num_valid_params, and ByteReader::ReadByte().

## ◆ ChangeGRFPalette()

static bool ChangeGRFPalette | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 52 of file newgrf_act14.cpp.

References GrfProcessingState::grfconfig, GRFP_GRF_ANY, GRFP_GRF_DOS, GRFP_GRF_UNSET, GRFP_GRF_WINDOWS, GRFConfig::palette, and ByteReader::ReadByte().

## ◆ ChangeGRFParamDefault()

static bool ChangeGRFParamDefault | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 209 of file newgrf_act14.cpp.

References _cur_parameter, GRFParameterInfo::def_value, GrfProcessingState::grfconfig, GRFConfig::has_param_defaults, and ByteReader::ReadDWord().

## ◆ ChangeGRFParamDescription()

static 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.

Definition at line 142 of file newgrf_act14.cpp.

References _cur_parameter, AddGRFTextToList(), GRFParameterInfo::desc, GrfProcessingState::grfconfig, GRFIdentifier::grfid, and GRFConfig::ident.

## ◆ ChangeGRFParamLimits()

static 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.

Definition at line 166 of file newgrf_act14.cpp.

References _cur_parameter, GRFParameterInfo::max_value, GRFParameterInfo::min_value, PTYPE_UINT_ENUM, ByteReader::ReadDWord(), and GRFParameterInfo::type.

## ◆ ChangeGRFParamMask()

static bool ChangeGRFParamMask | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 188 of file newgrf_act14.cpp.

References _cur_parameter, GRFParameterInfo::first_bit, GRFParameterInfo::num_bit, GRFParameterInfo::param_nr, and ByteReader::ReadByte().

## ◆ ChangeGRFParamName()

static 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.

Definition at line 135 of file newgrf_act14.cpp.

References _cur_parameter, AddGRFTextToList(), GrfProcessingState::grfconfig, GRFIdentifier::grfid, GRFConfig::ident, and GRFParameterInfo::name.

## ◆ ChangeGRFParamType()

static bool ChangeGRFParamType | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 149 of file newgrf_act14.cpp.

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

## ◆ ChangeGRFParamValueNames()

static 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.

Definition at line 249 of file newgrf_act14.cpp.

References _cur_parameter, AddGRFTextToList(), GrfProcessingState::grfconfig, GRFIdentifier::grfid, GRFConfig::ident, GRFParameterInfo::max_value, ByteReader::ReadByte(), ByteReader::ReadDWord(), ByteReader::ReadString(), SkipUnknownInfo(), and GRFParameterInfo::value_names.

## ◆ ChangeGRFURL()

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

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

Definition at line 33 of file newgrf_act14.cpp.

References AddGRFTextToList(), GrfProcessingState::grfconfig, GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::url.

## ◆ ChangeGRFVersion()

static bool ChangeGRFVersion | ( | size_t | len,
|  | ByteReader & | buf
| ) |  |
| static

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

Definition at line 100 of file newgrf_act14.cpp.

References GrfProcessingState::grfconfig, GRFConfig::min_loadable_version, ByteReader::ReadDWord(), and GRFConfig::version.

## ◆ HandleNode()

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

Handle the nodes of an Action14.

Parameters

  type | Type of node.
  id | ID.
  buf | Buffer.
  subtags | Allowed subtags.

Returns
  Whether all tags could be handled.

Definition at line 383 of file newgrf_act14.cpp.

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

Referenced by HandleNodes().

## ◆ HandleNodes()

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

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

Parameters

  buf | Buffer.
  subtags | List of subtags.

Returns
  Whether the nodes could all be handled.

Definition at line 436 of file newgrf_act14.cpp.

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

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

## ◆ HandleParameterInfo()

static 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.

Definition at line 292 of file newgrf_act14.cpp.

References _cur_parameter, _tags_parameters, GrfProcessingState::grfconfig, HandleNodes(), GRFConfig::num_valid_params, GRFConfig::param_info, ByteReader::ReadByte(), ByteReader::ReadDWord(), and SkipUnknownInfo().

## ◆ SkipUnknownInfo()

static bool SkipUnknownInfo | ( | ByteReader & | buf,
|  | uint8_t | type
| ) |  |
| static

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

Parameters

  buf | Buffer.
  type | The node type to skip.

Returns
  True if we could skip the node, false if an error occurred.

Definition at line 343 of file newgrf_act14.cpp.

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

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

## ◆ StaticGRFInfo()

static void StaticGRFInfo | ( | ByteReader & | buf | ) |
| static

Handle Action 0x14.

Parameters

  buf | Buffer.

Definition at line 451 of file newgrf_act14.cpp.

References _tags_root, and HandleNodes().

## Variable Documentation

## ◆ _cur_parameter

GRFParameterInfo* _cur_parameter
| static

The parameter which info is currently changed by the newgrf.

Definition at line 132 of file newgrf_act14.cpp.

Referenced by ChangeGRFParamDefault(), ChangeGRFParamDescription(), ChangeGRFParamLimits(), ChangeGRFParamMask(), ChangeGRFParamName(), ChangeGRFParamType(), ChangeGRFParamValueNames(), and HandleParameterInfo().

## ◆ _tags_info

constexpr AllowedSubtags _tags_info[]
| staticconstexpr

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

Action14 tags for the INFO node.

Definition at line 319 of file newgrf_act14.cpp.

## ◆ _tags_parameters

constexpr AllowedSubtags _tags_parameters[]
| staticconstexpr

Initial value:
= {
AllowedSubtags{'NAME', ChangeGRFParamName},
AllowedSubtags{'DESC', ChangeGRFParamDescription},
AllowedSubtags{'TYPE', ChangeGRFParamType},
AllowedSubtags{'LIMI', ChangeGRFParamLimits},
AllowedSubtags{'MASK', ChangeGRFParamMask},
AllowedSubtags{'VALU', ChangeGRFParamValueNames},
AllowedSubtags{'DFLT', ChangeGRFParamDefault},
}
ChangeGRFParamType
static bool ChangeGRFParamType(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.
Definition newgrf_act14.cpp:149
ChangeGRFParamLimits
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.
Definition newgrf_act14.cpp:166
ChangeGRFParamDescription
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.
Definition newgrf_act14.cpp:142
ChangeGRFParamDefault
static bool ChangeGRFParamDefault(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.
Definition newgrf_act14.cpp:209
ChangeGRFParamValueNames
static bool ChangeGRFParamValueNames(ByteReader &buf)
Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (ty...
Definition newgrf_act14.cpp:249
ChangeGRFParamMask
static bool ChangeGRFParamMask(size_t len, ByteReader &buf)
Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use.
Definition newgrf_act14.cpp:188
ChangeGRFParamName
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.
Definition newgrf_act14.cpp:135

Action14 parameter tags.

Definition at line 276 of file newgrf_act14.cpp.

Referenced by HandleParameterInfo().

## ◆ _tags_root

constexpr AllowedSubtags _tags_root[]
| staticconstexpr

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

Action14 root tags.

Definition at line 332 of file newgrf_act14.cpp.

Referenced by StaticGRFInfo().