13#include "../newgrf_engine.h"
14#include "../newgrf_cargo.h"
15#include "../timer/timer_game_calendar.h"
17#include "../engine_func.h"
18#include "../vehicle_base.h"
24#include "table/strings.h"
26#include "../safeguards.h"
49 if (target < 0x80 || target == 0x9E)
return;
58static uint32_t GetPatchVariable(uint8_t param)
84 case 0x11:
return SPR_2CCMAP_BASE;
101 uint8_t max_edge = std::max(log_X, log_Y);
103 if (log_X == log_Y) {
106 if (max_edge == log_Y)
SetBit(map_bits, 1);
109 return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
110 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
119 return SPR_SLOPES_BASE;
130 GrfMsg(2,
"ParamSet: Unknown Patch variable 0x{:02X}.", param);
135static uint32_t PerformGRM(std::span<uint32_t> grm, uint16_t count, uint8_t op, uint8_t target,
const char *type)
148 for (uint i = start; i < std::size(grm); i++) {
152 if (op == 2 || op == 3)
break;
157 if (size == count)
break;
162 if (op == 0 || op == 3) {
163 GrfMsg(2,
"ParamSet: GRM: Reserving {} {} at {}", count, type, start);
164 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
170 if (op != 4 && op != 5) {
172 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type);
177 GrfMsg(1,
"ParamSet: GRM: Unable to allocate {} {}", count, type);
212 if (buf.Remaining() >= 4) data = buf.
ReadDWord();
221 if (target < 0x80 && target < std::size(_cur.
grffile->param)) {
222 GrfMsg(7,
"ParamSet: Param {} already defined, skipping", target);
226 oper =
GB(oper, 0, 7);
230 if (
GB(data, 0, 8) == 0xFF) {
231 if (data == 0x0000FFFF) {
233 src1 = GetPatchVariable(src1);
237 uint8_t feature =
GB(data, 8, 8);
238 uint16_t count =
GB(data, 16, 16);
240 if (_cur.
stage == GLS_RESERVE) {
241 if (feature == 0x08) {
245 if (_cur.
spriteid + count >= 16384) {
246 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count);
252 GrfMsg(4,
"ParamSet: GRM: Allocated {} sprites at {}", count, _cur.
spriteid);
259 }
else if (_cur.
stage == GLS_ACTIVATION) {
288 GrfMsg(4,
"ParamSet: GRM: Using pre-allocated sprites at {}", src1);
296 GrfMsg(1,
"ParamSet: GRM: Unsupported operation {} for general sprites", op);
303 src1 = PerformGRM(
_grm_cargoes, count, op, target,
"cargoes");
307 default: GrfMsg(1,
"ParamSet: GRM: Unsupported feature 0x{:X}", feature);
return;
324 }
else if (src1 == 0xFE) {
336 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
337 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
359 res = (int32_t)src1 * (int32_t)src2;
363 if ((int32_t)src2 < 0) {
364 res = src1 >> -(int32_t)src2;
366 res = src1 << (src2 & 0x1F);
371 if ((int32_t)src2 < 0) {
372 res = (int32_t)src1 >> -(int32_t)src2;
374 res = (int32_t)src1 << (src2 & 0x1F);
398 res = (int32_t)src1 / (int32_t)src2;
414 res = (int32_t)src1 % (int32_t)src2;
418 default: GrfMsg(0,
"ParamSet: Unknown operation {}, skipping", oper);
return;
447 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
460 GrfMiscBits safe_bits = GrfMiscBit::SecondRockyTileSet;
471 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
477 if (target >= std::size(_cur.
grffile->param)) _cur.
grffile->param.resize(target + 1);
478 _cur.
grffile->param[target] = res;
480 GrfMsg(7,
"ParamSet: Skipping unknown target 0x{:02X}", target);
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
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 Timpl & Set()
Set all bits.
constexpr Timpl & Reset(Tvalue_type value)
Reset the value-th bit.
Class to read from a NewGRF file.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
This struct contains all the info that is needed to draw and construct tracks.
uint16_t cost_multiplier
Cost multiplier for building this rail type.
static constexpr TimerGame< struct Calendar >::Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
const uint8_t _engine_counts[4]
Number of engines of each vehicle type in original engine data.
const uint8_t _engine_offsets[4]
Offset of the first engine of each vehicle type in original engine data.
bool _networking
are we in networking mode?
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig &c)
Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desync...
GRFFile * GetFileByGRFID(uint32_t grfid)
Obtain a NewGRF file by its grfID.
GrfMiscBits _misc_grf_features
Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
GRFError * DisableGrf(StringID message, GRFConfig *config)
Disable a GRF.
@ TrainWidth32Pixels
Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable;.
static std::array< uint32_t, NUM_CARGO *2 > _grm_cargoes
Contains the GRF ID of the owner of a cargo if it has been reserved.
static void ParamSet(ByteReader &buf)
Action 0x0D: Set parameter.
static std::array< uint32_t, 256 > _grm_engines
Contains the GRF ID of the owner of a vehicle if it has been reserved.
NewGRF buffer reader definition.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
@ GCS_DISABLED
GRF file is disabled.
@ Static
GRF file is used statically (can be used in any MP game)
NewGRF internal processing state.
@ RAILTYPE_END
Used for iterations.
@ RAILTYPE_ELECTRIC
Electric rails.
@ RAILTYPE_RAIL
Standard non-electric rails.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static const SpriteID SPR_SHORE_BASE
shore tiles - action 05-0D
uint8_t map_height_limit
the maximum allowed heightlevel
Information about GRF, used in the game and (part of it) in savegames.
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
GRFStatus status
NOSAVE: GRFStatus, enum.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
Dynamic data of a loaded NewGRF.
uint32_t GetParam(uint number) const
Get GRF Parameter with range checking.
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.
TimerGameCalendar::Year starting_year
starting date
uint32_t generation_seed
noise seed for world generation
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.
uint32_t nfo_line
Currently processed pseudo sprite number in the GRF.
SpriteID spriteid
First available SpriteID for loading realsprites.
GRFConfig * grfconfig
Config of the currently processed GRF file.
GrfLoadingStage stage
Current loading stage.
int skip_sprites
Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file)
static debug_inline uint LogX()
Logarithm of the map size along the X side.
static uint LogY()
Logarithm of the map size along the y side.
bool dynamic_engines
enable dynamic allocation of engine data
uint8_t freight_trains
value to multiply the weight of cargo by
uint8_t plane_speed
divisor for speed of aircraft
bool disable_elrails
when true, the elrails are disabled