12#include "../engine_base.h"
14#include "../newgrf_engine.h"
15#include "../newgrf_text.h"
16#include "../newgrf_badge.h"
17#include "../newgrf_badge_type.h"
18#include "../newgrf_cargo.h"
19#include "../newgrf_station.h"
20#include "../newgrf_airporttiles.h"
21#include "../string_func.h"
26#include "table/strings.h"
28#include "../safeguards.h"
49 bool new_scheme = _cur.
grffile->grf_version >= 7;
52 if (feature >= GSF_END && feature != 0x48) {
53 GrfMsg(1,
"FeatureNewName: Unsupported feature 0x{:02X}, skipping", feature);
59 bool generic =
HasBit(lang, 7);
63 }
else if (feature <= GSF_AIRCRAFT || feature == GSF_BADGES) {
71 uint16_t endid =
id + num;
73 GrfMsg(6,
"FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
74 id, endid, feature, lang);
77 uint32_t feature_overlay =
generic ? 0 : ((feature + 1) << 16);
79 for (;
id < endid && buf.HasData();
id++) {
80 const std::string_view name = buf.
ReadString();
81 GrfMsg(8,
"FeatureNewName: 0x{:04X} <- {}",
id,
StrMakeValid(name));
85 case GSF_ROADVEHICLES:
90 if (e ==
nullptr)
break;
100 auto found = _cur.
grffile->badge_map.find(
id);
101 if (found == std::end(_cur.
grffile->badge_map)) {
102 GrfMsg(1,
"FeatureNewName: Attempt to name undefined badge 0x{:X}, ignoring",
id);
119 switch (
GB(
id, 8, 8)) {
121 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
122 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
130 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
131 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
138 if (
GB(
id, 0, 8) >= _cur.
grffile->airtspec.size() || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
139 GrfMsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring",
GB(
id, 0, 8));
146 if (
GB(
id, 0, 8) >= _cur.
grffile->housespec.size() || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
147 GrfMsg(1,
"FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.",
GB(
id, 0, 8));
154 GrfMsg(7,
"FeatureNewName: Unsupported ID (0x{:04X})",
id);
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Class to read from a NewGRF file.
uint16_t ReadWord()
Read a single Word (16 bits).
std::string_view ReadString()
Read a string.
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
StringID name
Name of this class.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Engine * GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access)
Returns the engine associated to a certain internal_id, resp.
Badge * GetBadge(BadgeID index)
Get a badge if it exists.
NewGRF buffer reader definition.
@ Static
GRF file is used statically (can be used in any MP game)
NewGRF internal processing state.
NewGRF internal processing state for vehicles.
StringID AddGRFString(uint32_t grfid, GRFStringID stringid, uint8_t langid_to_add, bool new_scheme, bool allow_newlines, std::string_view text_to_add, StringID def_string)
Add the new read string into our structure.
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
StringID string_id
Default name of engine.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
GRFFile * grffile
Currently processed GRF file.
GRFConfig * grfconfig
Config of the currently processed GRF file.
VehicleType
Available vehicle types.