21#include "table/strings.h"
84 if (_cur_gps.grffile->indtspec.size() < last) _cur_gps.grffile->indtspec.resize(last);
86 for (uint
id = first;
id < last; ++id) {
87 auto &tsp = _cur_gps.grffile->indtspec[id];
89 if (prop != 0x08 && tsp ==
nullptr) {
91 if (cir > ret) ret = cir;
100 GrfMsg(
Severity::Warning,
"IndustryTilesChangeInfo: Attempt to use new industry tile {} as substitute industry tile for {}. Ignoring.", subs_id,
id);
105 if (tsp ==
nullptr) {
106 tsp = std::make_unique<IndustryTileSpec>(_industry_tile_specs[subs_id]);
114 tsp->grf_prop.local_id = id;
115 tsp->grf_prop.subst_id = subs_id;
116 tsp->grf_prop.SetGRFFile(_cur_gps.grffile);
117 _industile_mngr.AddEntityID(
id, _cur_gps.grffile->grfid, subs_id);
127 GrfMsg(
Severity::Warning,
"IndustryTilesChangeInfo: Attempt to override new industry tile {} with industry tile id {}. Ignoring.", ovrid,
id);
131 _industile_mngr.Add(
id, _cur_gps.grffile->grfid, ovrid);
140 tsp->acceptance[prop - 0x0A] =
Clamp(
GB(acctp, 8, 8), 0, 16);
141 tsp->accepts_cargo_label[prop - 0x0A] =
CT_INVALID;
154 tsp->animation.frames = buf.
ReadByte();
159 tsp->animation.speed = buf.
ReadByte();
171 uint8_t num_cargoes = buf.
ReadByte();
172 if (num_cargoes > std::size(tsp->acceptance)) {
177 for (uint i = 0; i < std::size(tsp->acceptance); i++) {
178 if (i < num_cargoes) {
181 tsp->acceptance[i] =
static_cast<int8_t
>(buf.
ReadByte());
184 tsp->acceptance[i] = 0;
186 if (i < std::size(tsp->accepts_cargo_label)) tsp->accepts_cargo_label[i] =
CT_INVALID;
251 for (uint8_t j = 0; j < num_table; j++) {
252 for (uint k = 0;; k++) {
254 if (x == 0xFE && k == 0) {
261 if (x == 0 && y == 0x80)
break;
284 buf.Skip(num_inputs * num_outputs * 2);
306 const size_t size = layout.size();
307 if (size == 0)
return false;
309 for (
size_t i = 0; i < size - 1; i++) {
310 for (
size_t j = i + 1; j < size; j++) {
311 if (layout[i].ti.x == layout[j].ti.x &&
312 layout[i].ti.y == layout[j].ti.y) {
318 bool have_regular_tile =
false;
319 for (
const auto &tilelayout : layout) {
321 have_regular_tile =
true;
326 return have_regular_tile;
347 if (_cur_gps.grffile->industryspec.size() < last) _cur_gps.grffile->industryspec.resize(last);
349 for (uint
id = first;
id < last; ++id) {
350 auto &indsp = _cur_gps.grffile->industryspec[id];
352 if (prop != 0x08 && indsp ==
nullptr) {
354 if (cir > ret) ret = cir;
361 if (subs_id == 0xFF) {
368 GrfMsg(
Severity::Warning,
"_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id,
id);
375 if (indsp ==
nullptr) {
378 indsp->enabled =
true;
379 indsp->grf_prop.local_id = id;
380 indsp->grf_prop.subst_id = subs_id;
381 indsp->grf_prop.SetGRFFile(_cur_gps.grffile);
394 GrfMsg(
Severity::Warning,
"IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid,
id);
397 indsp->grf_prop.override_id = ovrid;
398 _industry_mngr.Add(
id, _cur_gps.grffile->grfid, ovrid);
403 uint8_t num_layouts = buf.
ReadByte();
404 size_t definition_size = buf.
ReadDWord();
405 size_t definition_end = definition_size + buf.
GetBytesRead();
407 std::vector<IndustryTileLayout> layouts;
408 layouts.reserve(num_layouts);
412 for (uint8_t j = 0; j < num_layouts; j++) {
413 bool invalid_layout =
false;
416 for (uint k = 0;; k++) {
418 GrfMsg(
Severity::Notice,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.",
id);
420 definition_end = SIZE_MAX;
427 if (it.ti.
x == 0xFE && k == 0) {
433 GrfMsg(
Severity::Error,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry {}",
id);
438 GrfMsg(
Severity::Error,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}",
id);
448 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
456 if (it.gfx == 0xFE) {
461 int tempid = _industile_mngr.GetID(local_tile_id, _cur_gps.grffile->grfid);
464 GrfMsg(
Severity::Warning,
"IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id,
id);
465 invalid_layout =
true;
470 }
else if (it.gfx == 0xFF) {
472 it.ti.
x = (int8_t)
GB(it.ti.
x, 0, 8);
473 it.ti.
y = (int8_t)
GB(it.ti.
y, 0, 8);
482 if (_cur_gps.grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
484 GrfMsg(
Severity::Warning,
"IndustriesChangeInfo: Attempt to use invalid industry tile {} with industry id {}. Ignoring.", it.gfx,
id);
485 invalid_layout =
true;
489 if (invalid_layout)
continue;
493 GrfMsg(
Severity::Error,
"IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring",
id);
495 layouts.push_back(layout);
500 indsp->layouts = std::move(layouts);
521 indsp->cost_multiplier = buf.
ReadByte();
541 indsp->production_rate[prop - 0x12] = buf.
ReadByte();
545 indsp->minimal_cargo = buf.
ReadByte();
549 uint8_t num_sounds = buf.
ReadByte();
551 std::vector<uint8_t> sounds;
552 sounds.reserve(num_sounds);
553 for (uint8_t j = 0; j < num_sounds; ++j) {
557 indsp->random_sounds = std::move(sounds);
562 for (uint8_t j = 0; j < 3; j++) indsp->conflicting[j] = buf.
ReadByte();
589 indsp->input_cargo_multiplier[prop - 0x1C][0] =
GB(multiples, 0, 16);
590 indsp->input_cargo_multiplier[prop - 0x1C][1] =
GB(multiples, 16, 16);
599 indsp->prospecting_chance = buf.
ReadDWord();
604 auto mask = indsp->callback_mask.base();
605 SB(mask, (prop - 0x21) * 8, 8, buf.
ReadByte());
611 indsp->removal_cost_multiplier = buf.
ReadDWord();
617 indsp->station_name = STR_NULL;
625 uint8_t num_cargoes = buf.
ReadByte();
626 if (num_cargoes > std::size(indsp->produced_cargo)) {
631 for (
size_t i = 0; i < std::size(indsp->produced_cargo); i++) {
632 if (i < num_cargoes) {
634 indsp->produced_cargo[i] = cargo;
638 if (i < std::size(indsp->produced_cargo_label)) indsp->produced_cargo_label[i] =
CT_INVALID;
644 uint8_t num_cargoes = buf.
ReadByte();
645 if (num_cargoes > std::size(indsp->accepts_cargo)) {
650 for (
size_t i = 0; i < std::size(indsp->accepts_cargo); i++) {
651 if (i < num_cargoes) {
653 indsp->accepts_cargo[i] = cargo;
657 if (i < std::size(indsp->accepts_cargo_label)) indsp->accepts_cargo_label[i] =
CT_INVALID;
663 uint8_t num_cargoes = buf.
ReadByte();
664 if (num_cargoes >
lengthof(indsp->production_rate)) {
669 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
670 if (i < num_cargoes) {
671 indsp->production_rate[i] = buf.
ReadByte();
673 indsp->production_rate[i] = 0;
680 uint8_t num_inputs = buf.
ReadByte();
681 uint8_t num_outputs = buf.
ReadByte();
682 if (num_inputs > std::size(indsp->accepts_cargo) || num_outputs > std::size(indsp->produced_cargo)) {
687 for (
size_t i = 0; i < std::size(indsp->accepts_cargo); i++) {
688 for (
size_t j = 0; j < std::size(indsp->produced_cargo); j++) {
690 if (i < num_inputs && j < num_outputs) mult = buf.
ReadWord();
691 indsp->input_cargo_multiplier[i][j] = mult;
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.
static constexpr CargoLabel CT_INVALID
Invalid cargo type.
static constexpr CargoType INVALID_CARGO
Invalid marker for cargoes.
CargoType
Cargo slots to indicate a cargo type within a game.
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).
size_t GetBytesRead() const
Get number of already read bytes.
uint8_t ReadByte()
Read a single byte (8 bits).
Functions related to debugging.
@ Warning
Warning, wrong but okay if you don't know.
@ Error
Error, but we are recovering.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Accessors to map for industries.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
static const IndustryGfx INDUSTRYTILE_NOANIM
Sentinel value to mark industry tiles as having no animation.
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
static constexpr IndustryGfx GFX_WATERTILE_SPECIALCHECK
Sentinel marker in industry layout to perform a water tile check.
static const IndustryGfx NUM_INDUSTRYTILES_PER_GRF
Maximum number of industry tiles per NewGRF.
EnumBitSet< IndustryAnimationTrigger, uint8_t > IndustryAnimationTriggers
Bitset of IndustryAnimationTrigger elements.
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
static const IndustryType NUM_INDUSTRYTYPES_PER_GRF
maximum number of industry types per NewGRF; limited to 128 because bit 7 has a special meaning in so...
EnumBitSet< IndustryLifeType, uint8_t > IndustryLifeTypes
Bitset of IndustryLifeType elements.
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
EnumBitSet< IndustryBehaviour, uint32_t > IndustryBehaviours
Bitset of IndustryBehaviour elements.
EnumBitSet< IndustryTileSpecialFlag, uint8_t > IndustryTileSpecialFlags
Bitset of IndustryTileSpecialFlag elements.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
GRFError * DisableGrf(StringID message, GRFConfig *config)
Disable a GRF.
@ IndustryTiles
Industry tiles feature.
@ Industries
Industries feature.
std::vector< BadgeID > ReadBadgeList(ByteReader &buf, GrfSpecFeature feature)
Read a list of badges.
void SkipBadgeList(ByteReader &buf)
Skip a list of badges.
const IndustrySpec _origin_industry_specs[NEW_INDUSTRYOFFSET]
Extern declaration for _origin_industry_specs in table/build_industry.h.
static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader &buf)
Ignore an industry property.
static ChangeInfoResult IndustriesChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for industries.
static ChangeInfoResult IndustrytilesChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for industry tiles.
static bool ValidateIndustryLayout(const IndustryTileLayout &layout)
Validate the industry layout; e.g.
static ChangeInfoResult IgnoreIndustryTileProperty(int prop, ByteReader &buf)
Ignore an industry tile property.
AnimationStatus
Statuses of animation within NewGRFs.
NewGRF buffer reader definition.
EnumBitSet< IndustryTileCallbackMask, uint8_t > IndustryTileCallbackMasks
Bitset of IndustryTileCallbackMask elements.
EnumBitSet< IndustryCallbackMask, uint16_t > IndustryCallbackMasks
Bitset of IndustryCallbackMask elements.
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
Cargo support for NewGRFs.
Functions for NewGRF industries.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ Success
Variable was parsed and read.
@ Unhandled
Variable was parsed but unread.
@ Unknown
Variable is unknown.
@ Disabled
GRF was disabled due to error.
@ InvalidId
Attempt to modify an invalid ID.
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.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Slope
Enumeration for the slope-type.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
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.
static ChangeInfoResult Reserve(uint first, uint last, int prop, ByteReader &buf)
Implementation of the GrfLoadingStage::Reserve stage of this feature.
static ChangeInfoResult Activation(uint first, uint last, int prop, ByteReader &buf)
Implementation of the GrfLoadingStage::Activation stage of this feature.
Defines the data structure for constructing industry.
Definition of one tile in an industry tile layout.
Colour for pixel/line drawing.
int16_t x
The x value of the coordinate.
int16_t y
The y value of the coordinate.