12#include "../newgrf_engine.h"
13#include "../newgrf_badge.h"
14#include "../newgrf_badge_type.h"
15#include "../newgrf_cargo.h"
16#include "../timer/timer_game_calendar.h"
18#include "../vehicle_base.h"
22#include "../table/strings.h"
24#include "../safeguards.h"
90 std::vector<BadgeID> badges;
91 badges.reserve(count);
94 uint16_t local_index = buf.
ReadWord();
96 GrfMsg(1,
"ReadBadgeList: Badge label {} out of range (max {}), skipping.", local_index, std::size(_cur.
grffile->
badge_list) - 1);
103 if (std::ranges::find(badges, index) != std::end(badges))
continue;
105 badges.push_back(index);
112bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property)
115 default: NOT_REACHED();
125 GrfMsg(1,
"{}: Ignoring property 0x{:02X} of feature 0x{:02X} (not implemented)", caller, property, feature);
129 GrfMsg(0,
"{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature);
143 template <GrfSpecFeature TFeature>
149 default: NOT_REACHED();
154 static constexpr Invoker funcs[] {
155 Invoke<GSF_TRAINS>, Invoke<GSF_ROADVEHICLES>, Invoke<GSF_SHIPS>, Invoke<GSF_AIRCRAFT>,
156 Invoke<GSF_STATIONS>, Invoke<GSF_CANALS>, Invoke<GSF_BRIDGES>, Invoke<GSF_HOUSES>,
157 Invoke<GSF_GLOBALVAR>, Invoke<GSF_INDUSTRYTILES>, Invoke<GSF_INDUSTRIES>, Invoke<GSF_CARGOES>,
158 Invoke<GSF_SOUNDFX>, Invoke<GSF_AIRPORTS>,
nullptr , Invoke<GSF_OBJECTS>,
159 Invoke<GSF_RAILTYPES>, Invoke<GSF_AIRPORTTILES>, Invoke<GSF_ROADTYPES>, Invoke<GSF_TRAMTYPES>,
160 Invoke<GSF_ROADSTOPS>, Invoke<GSF_BADGES>,
165 Invoker func = feature < std::size(funcs) ? funcs[feature] :
nullptr;
167 return func(first, last, prop, buf, stage);
190 if (feature >= GSF_END) {
191 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
195 GrfMsg(6,
"FeatureChangeInfo: Feature 0x{:02X}, {} properties, to apply to {}+{}",
196 feature, numprops, engine, numinfo);
199 ChangeInfoResult cir_test = InvokeGrfChangeInfoHandler::Invoke(feature, 0, 0, 0, buf, GLS_ACTIVATION);
202 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
209 while (numprops-- && buf.HasData()) {
212 ChangeInfoResult cir = InvokeGrfChangeInfoHandler::Invoke(feature, engine, engine + numinfo, prop, buf, GLS_ACTIVATION);
213 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
225 if (feature == GSF_BRIDGES && numprops == 1) {
229 if (prop == 0x0D)
return;
230 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
235 for (uint i = 0; i < numinfo; i++) {
257 ChangeInfoResult cir_test = InvokeGrfChangeInfoHandler::Invoke(feature, 0, 0, 0, buf, GLS_RESERVE);
260 GrfMsg(1,
"ReserveChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
268 while (numprops-- && buf.HasData()) {
271 ChangeInfoResult cir = InvokeGrfChangeInfoHandler::Invoke(feature, index, index + numinfo, prop, buf, GLS_RESERVE);
272 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
constexpr T SetBit(T &x, const uint8_t y)
Set 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.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint16_t ReadWord()
Read a single Word (16 bits).
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
GRFError * DisableGrf(StringID message, GRFConfig *config)
Disable a GRF.
ChangeInfoResult CommonVehicleChangeInfo(EngineInfo *ei, int prop, ByteReader &buf)
Define properties common to all vehicles.
std::vector< BadgeID > ReadBadgeList(ByteReader &buf, GrfSpecFeature feature)
Read a list of badges.
void SkipBadgeList(ByteReader &buf)
Skip a list of badges.
void MarkBadgeSeen(BadgeID index, GrfSpecFeature feature)
Mark a badge a seen (used) by a feature.
NewGRF buffer reader definition.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
@ Static
GRF file is used statically (can be used in any MP game)
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
@ CIR_DISABLED
GRF was disabled due to error.
@ CIR_UNKNOWN
Variable is unknown.
@ CIR_UNHANDLED
Variable was parsed but unread.
@ CIR_SUCCESS
Variable was parsed and read.
@ PROP_VEHICLE_LOAD_AMOUNT
Loading speed.
Information about a vehicle.
TimerGameCalendar::Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life.
LandscapeTypes climates
Climates supported by the engine.
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
TimerGameCalendar::Year lifelength
Lifetime of a single vehicle.
Information about GRF, used in the game and (part of it) in savegames.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
Information about why GRF had problems during initialisation.
std::array< uint32_t, 2 > param_value
Values of GRF parameters to show for message and custom_message.
uint32_t grf_features
Bitset of GrfSpecFeature the grf uses.
std::vector< BadgeID > badge_list
Badge translation table (local index -> global index)
GRFFile * grffile
Currently processed GRF file.
Helper class to invoke a GrfChangeInfoHandler.
Templated helper to make a type-safe 'typedef' representing a single POD value.