12#include "../currency.h"
13#include "../landscape.h"
14#include "../language.h"
16#include "../string_func.h"
18#include "../newgrf_badge.h"
19#include "../newgrf_badge_type.h"
20#include "../newgrf_cargo.h"
21#include "../newgrf_engine.h"
22#include "../newgrf_sound.h"
23#include "../vehicle_base.h"
30#include "table/strings.h"
32#include "../safeguards.h"
43template <
typename T,
typename TGetTableFunc>
47 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
51 std::vector<T> &translation_table = gettable(*_cur.
grffile);
52 translation_table.clear();
53 translation_table.reserve(last);
54 for (uint
id = first;
id < last; ++id) {
55 translation_table.push_back(T(std::byteswap(buf.
ReadDWord())));
59 if (grf_override !=
nullptr) {
61 GrfMsg(1,
"LoadTranslationTable: Copying {} translation table to override GRFID '{}'", name, std::byteswap(grf_override->grfid));
62 std::vector<T> &override_table = gettable(*grf_override);
63 override_table = translation_table;
69static ChangeInfoResult LoadBadgeTranslationTable(uint first, uint last,
ByteReader &buf, std::vector<BadgeID> &translation_table,
const char *name)
71 if (first != 0 && first != std::size(translation_table)) {
72 GrfMsg(1,
"LoadBadgeTranslationTable: {} translation table must start at zero or {}", name, std::size(translation_table));
76 if (first == 0) translation_table.clear();
77 translation_table.reserve(last);
78 for (uint
id = first;
id < last; ++id) {
95 for (
int i = 0; i < 4; i++) output.push_back(reader.
ReadByte());
112 return LoadTranslationTable<CargoLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<CargoLabel> & {
return grf.
cargo_list; },
"Cargo");
115 return LoadTranslationTable<RailTypeLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<RailTypeLabel> & {
return grf.
railtype_list; },
"Rail type");
118 return LoadTranslationTable<RoadTypeLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<RoadTypeLabel> & {
return grf.
roadtype_list; },
"Road type");
121 return LoadTranslationTable<RoadTypeLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<RoadTypeLabel> & {
return grf.
tramtype_list; },
"Tram type");
124 return LoadBadgeTranslationTable(first, last, buf, _cur.
grffile->
badge_list,
"Badge");
132 for (uint
id = first;
id < last; ++id) {
140 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring",
id);
168 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
184 GrfMsg(1,
"GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
196 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
208 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
220 GrfMsg(1,
"GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
227 GrfMsg(1,
"GlobalVarChangeInfo: The snowline can only be set once ({})", last);
229 GrfMsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf.Remaining());
231 auto snow_line = std::make_unique<SnowLine>();
235 uint8_t &level = snow_line->table[i][j];
237 if (_cur.
grffile->grf_version >= 8) {
248 snow_line->highest_value = std::max(snow_line->highest_value, level);
249 snow_line->lowest_value = std::min(snow_line->lowest_value, level);
267 if (lang ==
nullptr) {
268 GrfMsg(1,
"GlobalVarChangeInfo: Language {} is not known, ignoring", curidx);
282 if (plural_form >= LANGUAGE_MAX_PLURAL) {
283 GrfMsg(1,
"GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form);
291 while (newgrf_id != 0) {
307 GrfMsg(1,
"GlobalVarChangeInfo: Gender name {} is not known, ignoring",
StrMakeValid(name));
314 GrfMsg(1,
"GlobalVarChangeInfo: Case name {} is not known, ignoring",
StrMakeValid(name));
338 return LoadTranslationTable<CargoLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<CargoLabel> & {
return grf.
cargo_list; },
"Cargo");
341 return LoadTranslationTable<RailTypeLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<RailTypeLabel> & {
return grf.
railtype_list; },
"Rail type");
344 return LoadTranslationTable<RoadTypeLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<RoadTypeLabel> & {
return grf.
roadtype_list; },
"Road type");
347 return LoadTranslationTable<RoadTypeLabel>(first, last, buf, [](
GRFFile &grf) -> std::vector<RoadTypeLabel> & {
return grf.
tramtype_list; },
"Tram type");
350 return LoadBadgeTranslationTable(first, last, buf, _cur.
grffile->
badge_list,
"Badge");
359 for (uint
id = first;
id < last; ++id) {
456 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
514 *value = bits.
base();
523 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
532 *value = _openttd_newgrf_version;
547 default:
return false;
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.
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 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 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
The maximum year of the original TTD.
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
static TickCounter counter
Monotonic counter, in ticks, since start of game.
static constexpr bool IsLeapYear(Year year)
Checks whether the given year is a leap year or not.
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.
@ CURRENCY_END
always the last item
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.
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.
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.
@ 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.
NewGRF buffer reader definition.
@ GRFP_USE_MASK
Bitmask to get only the use palette use states.
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.
void AddStringForMapping(GRFStringID source, std::function< void(StringID)> &&func)
Record a static StringID for getting translated later.
NewGRF string mapping definition.
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.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ SP_CUSTOM
No profile, special "custom" highscore.
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.
size_t Utf8Decode(char32_t *c, const char *s)
Decode and consume the next UTF-8 encoded character.
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 map_height_limit
the maximum allowed heightlevel
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.
std::vector< BadgeID > badge_list
Badge translation table (local index -> global index)
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
std::unordered_map< uint8_t, LanguageMap > language_map
Mappings related to the languages.
PriceMultipliers price_base_multipliers
Price base multipliers as set by the grf.
LandscapeType landscape
the landscape we're currently in
ConstructionSettings construction
construction of things in-game
GameCreationSettings game_creation
settings used during the creation of a game (map)
VehicleSettings vehicle
options for vehicles
GRFFile * grffile
Currently processed GRF file.
GRFConfig * grfconfig
Config of the currently processed GRF file.
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.
uint8_t road_side
the side of the road vehicles drive on
bool disable_elrails
when true, the elrails are disabled
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.