From 68f5a8a0fd946987691b59cc2a3bb2877c483d68 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 30 Jun 2026 21:42:03 +0200 Subject: [PATCH] Codechange: use Label for Action14 NodeID --- src/newgrf/newgrf_act14.cpp | 46 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/newgrf/newgrf_act14.cpp b/src/newgrf/newgrf_act14.cpp index 2785c7a3a0..e583d96b9f 100644 --- a/src/newgrf/newgrf_act14.cpp +++ b/src/newgrf/newgrf_act14.cpp @@ -246,6 +246,8 @@ using TextHandler = bool(*)(GRFLanguage langid, std::string_view str); */ using BranchHandler = bool(*)(ByteReader &buf); +using NodeID = Label; ///< Label type of the nodes in the \c AllowedSubtags. + /** * Data structure to store the allowed id/type combinations for action 14. The * data can be represented as a tree with 3 types of nodes: @@ -257,7 +259,7 @@ struct AllowedSubtags { /** Custom 'span' of subtags. Required because std::span with an incomplete type is UB. */ using Span = std::pair; - uint32_t id; ///< The identifier for this node. + NodeID id; ///< The identifier for this node. std::variant handler; ///< The handler for this node. }; @@ -299,13 +301,13 @@ static bool ChangeGRFParamValueNames(ByteReader &buf) /** Action14 parameter tags */ static constexpr AllowedSubtags _tags_parameters[] = { - AllowedSubtags{'NAME', ChangeGRFParamName}, - AllowedSubtags{'DESC', ChangeGRFParamDescription}, - AllowedSubtags{'TYPE', ChangeGRFParamType}, - AllowedSubtags{'LIMI', ChangeGRFParamLimits}, - AllowedSubtags{'MASK', ChangeGRFParamMask}, - AllowedSubtags{'VALU', ChangeGRFParamValueNames}, - AllowedSubtags{'DFLT', ChangeGRFParamDefault}, + AllowedSubtags{"NAME", ChangeGRFParamName}, + AllowedSubtags{"DESC", ChangeGRFParamDescription}, + AllowedSubtags{"TYPE", ChangeGRFParamType}, + AllowedSubtags{"LIMI", ChangeGRFParamLimits}, + AllowedSubtags{"MASK", ChangeGRFParamMask}, + AllowedSubtags{"VALU", ChangeGRFParamValueNames}, + AllowedSubtags{"DFLT", ChangeGRFParamDefault}, }; /** @@ -343,20 +345,20 @@ static bool HandleParameterInfo(ByteReader &buf) /** Action14 tags for the INFO node */ static constexpr AllowedSubtags _tags_info[] = { - 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}, + 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}, }; /** Action14 root tags */ static constexpr AllowedSubtags _tags_root[] = { - AllowedSubtags{'INFO', std::make_pair(std::begin(_tags_info), std::end(_tags_info))}, + AllowedSubtags{"INFO", std::make_pair(std::begin(_tags_info), std::end(_tags_info))}, }; @@ -406,7 +408,7 @@ static bool SkipUnknownInfo(ByteReader &buf, uint8_t type) * @param subtags Allowed subtags. * @return Whether all tags could be handled. */ -static bool HandleNode(uint8_t type, uint32_t id, ByteReader &buf, std::span subtags) +static bool HandleNode(uint8_t type, NodeID id, ByteReader &buf, std::span subtags) { /* Visitor to get a subtag handler's type. */ struct type_visitor { @@ -445,11 +447,11 @@ static bool HandleNode(uint8_t type, uint32_t id, ByteReader &buf, std::span subtags { uint8_t type = buf.ReadByte(); while (type != 0) { - uint32_t id = buf.ReadDWord(); + NodeID id = buf.ReadLabel(); if (!HandleNode(type, id, buf, subtags)) return false; type = buf.ReadByte(); }