31#include "table/strings.h"
44template <
typename T,
typename TGetTableFunc>
48 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
52 std::vector<T> &translation_table = gettable(*_cur_gps.grffile);
53 translation_table.clear();
54 translation_table.reserve(last);
55 for (uint
id = first;
id < last; ++id) {
60 if (grf_override !=
nullptr) {
62 GrfMsg(1,
"LoadTranslationTable: Copying {} translation table to override GRFID {:08X}", name,
std::byteswap(grf_override->grfid));
63 std::vector<T> &override_table = gettable(*grf_override);
64 override_table = translation_table;
70static ChangeInfoResult LoadBadgeTranslationTable(uint first, uint last,
ByteReader &buf, std::vector<BadgeID> &translation_table, std::string_view name)
72 if (first != 0 && first != std::size(translation_table)) {
73 GrfMsg(1,
"LoadBadgeTranslationTable: {} translation table must start at zero or {}", name, std::size(translation_table));
77 if (first == 0) translation_table.clear();
78 translation_table.reserve(last);
79 for (uint
id = first;
id < last; ++id) {
96 for (
int i = 0; i < 4; i++) output.push_back(reader.
ReadByte());
114 _cur_gps.grffile->cargo_list_is_fallback =
false;
127 return LoadBadgeTranslationTable(first, last, buf, _cur_gps.grffile->badge_list,
"Badge");
135 for (uint
id = first;
id < last; ++id) {
141 _cur_gps.grffile->price_base_multipliers[id] = std::min<int>(factor - 8, MAX_PRICE_MODIFIER);
143 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring",
id);
171 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
188 GrfMsg(1,
"GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
200 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
212 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
219 TimerGameCalendar::Year year_euro{buf.
ReadWord()};
224 GrfMsg(1,
"GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
231 GrfMsg(1,
"GlobalVarChangeInfo: The snowline can only be set once ({})", last);
233 GrfMsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf.Remaining());
235 auto snow_line = std::make_unique<SnowLine>();
239 uint8_t &level = snow_line->table[i][j];
241 if (_cur_gps.grffile->grf_version >= 8) {
242 if (level != 0xFF) level = level * (1 +
_settings_game.construction.map_height_limit) / 256;
248 level = level * (1 +
_settings_game.construction.map_height_limit) / 128;
252 snow_line->highest_value = std::max(snow_line->highest_value, level);
253 snow_line->lowest_value = std::min(snow_line->lowest_value, level);
271 if (lang ==
nullptr) {
272 GrfMsg(1,
"GlobalVarChangeInfo: Language {} is not known, ignoring", curidx);
286 if (plural_form >= LANGUAGE_MAX_PLURAL) {
287 GrfMsg(1,
"GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form);
289 _cur_gps.grffile->language_map[curidx].plural_form = plural_form;
295 while (newgrf_id != 0) {
310 GrfMsg(1,
"GlobalVarChangeInfo: Gender name {} is not known, ignoring",
StrMakeValid(name));
312 _cur_gps.grffile->language_map[curidx].gender_map.push_back(map);
317 GrfMsg(1,
"GlobalVarChangeInfo: Case name {} is not known, ignoring",
StrMakeValid(name));
319 _cur_gps.grffile->language_map[curidx].case_map.push_back(map);
342 _cur_gps.grffile->cargo_list_is_fallback =
false;
355 return LoadBadgeTranslationTable(first, last, buf, _cur_gps.grffile->badge_list,
"Badge");
364 for (uint
id = first;
id < last; ++id) {
461 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
519 *value = bits.
base();
528 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
537 *value = _openttd_newgrf_version;
552 default:
return false;
556template <>
ChangeInfoResult GrfChangeInfoHandler<GSF_GLOBALVAR>::Reserve(uint first, uint last,
int prop,
ByteReader &buf) {
return GlobalVarReserveInfo(first, last, prop, buf); }
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
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 enable_if_t< is_integral_v< T >, T > byteswap(T x) noexcept
Custom implementation of std::byteswap; remove once we build with C++23.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Set()
Set all bits.
Class to read from a NewGRF file.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint16_t ReadWord()
Read a single Word (16 bits).
std::string_view ReadString()
Read a NUL-terminated string.
uint8_t ReadByte()
Read a single byte (8 bits).
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static Date date
Current date in days (day counter).
static Year year
Current year, starting at 0.
static DateFract date_fract
Fractional part of the day.
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_MAX_YEAR
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
static TickCounter counter
Monotonic counter, in ticks, since start of game.
static constexpr bool IsLeapYear(Year year)
std::pair< size_t, char32_t > DecodeUtf8(std::string_view buf)
Decode a character from UTF-8.
uint8_t GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id)
Will return the ottd's index correspondence to the ttdpatch's id.
std::array< CurrencySpec, CURRENCY_END > _currency_specs
Array of currencies used by the system.
Functions to handle different currencies.
@ CURRENCY_END
always the last item
Functions related to debugging.
@ End
Price base end marker.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
bool IsSnowLineSet()
Has a snow line table already been loaded.
void SetSnowLine(std::unique_ptr< SnowLine > &&snow_line)
Set a variable snow line, as loaded from a newgrf file.
Functions related to OTTD's landscape.
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
@ Arctic
Landscape with snow levels.
Information about languages and their files.
static const uint8_t MAX_NUM_GENDERS
Maximum number of supported genders.
const LanguageMetadata * GetLanguage(uint8_t newgrflangid)
Get the language with the given NewGRF language ID.
static const uint8_t MAX_NUM_CASES
Maximum number of supported cases.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
GRFFile * GetCurrentGRFOverride()
Get overridden GRF for current GRF if present.
void SetNewGRFOverride(uint32_t source_grfid, uint32_t target_grfid)
Set the override for a NewGRF.
GrfMiscBits _misc_grf_features
Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
Base for the NewGRF implementation.
@ TrainWidth32Pixels
Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable;.
bool GetGlobalVariable(uint8_t param, uint32_t *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
static ChangeInfoResult LoadTranslationTable(uint first, uint last, ByteReader &buf, TGetTableFunc gettable, std::string_view name)
Load a cargo- or railtype-translation table.
static ChangeInfoResult GlobalVarChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for global variables.
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.
Badge & GetOrCreateBadge(std::string_view label)
Register a badge label and return its global index.
Functions related to NewGRF badges.
Types related to NewGRF badges.
NewGRF buffer reader definition.
Cargo support for NewGRFs.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
@ GRFP_USE_MASK
Bitmask to get only the use palette use states.
Functions for NewGRF engines.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
@ CIR_UNKNOWN
Variable is unknown.
@ CIR_SUCCESS
Variable was parsed and read.
NewGRF internal processing state for vehicles.
Functions related to NewGRF provided sounds.
void AddStringForMapping(GRFStringID source, std::function< void(StringID)> &&func)
Record a static StringID for getting translated later.
NewGRF string mapping definition.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
static const char32_t NFO_UTF8_IDENTIFIER
This character (thorn) indicates a unicode string to NFO.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
@ RAILTYPE_ELECTRIC
Electric rails.
@ RAILTYPE_RAIL
Standard non-electric rails.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ SP_CUSTOM
No profile, special "custom" highscore.
Definition of base types and functions in a cross-platform compatible way.
void StrMakeValidInPlace(char *str, StringValidationSettings settings)
Scans the string for invalid characters and replaces them with a question mark '?
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
Functions related to low-level strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const uint MAX_LANG
Maximum number of languages supported by the game, and the NewGRF specs.
uint8_t palette
GRFPalette, bitset.
Dynamic data of a loaded NewGRF.
std::vector< RailTypeLabel > railtype_list
Railtype translation table.
std::vector< RoadTypeLabel > roadtype_list
Roadtype translation table (road).
std::vector< RoadTypeLabel > tramtype_list
Roadtype translation table (tram).
std::vector< CargoLabel > cargo_list
Cargo translation table (local ID -> label).
uint traininfo_vehicle_width
Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details.
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
Mapping between NewGRF and OpenTTD IDs.
uint8_t newgrf_id
NewGRF's internal ID for a case/gender.
uint8_t openttd_id
OpenTTD's internal ID for a case/gender.
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Handling of UTF-8 encoded data.
Base class for all vehicles.