53 #include "table/strings.h"
70 const std::vector<GRFFile *> &GetAllGRFFiles()
119 this->skip_sprites = 0;
121 for (uint i = 0; i < GSF_END; i++) {
122 this->spritesets[i].clear();
125 memset(this->spritegroups, 0,
sizeof(this->spritegroups));
138 assert(feature < GSF_END);
139 for (uint i = 0; i < numsets; i++) {
140 SpriteSet &set = this->spritesets[feature][first_set + i];
141 set.
sprite = first_sprite + i * numents;
154 assert(feature < GSF_END);
155 return !this->spritesets[feature].empty();
167 assert(feature < GSF_END);
168 return this->spritesets[feature].find(set) != this->spritesets[feature].end();
180 return this->spritesets[feature].find(set)->second.sprite;
192 return this->spritesets[feature].find(set)->second.num_sprites;
205 template <VehicleType T>
208 return image_index == 0xFD || IsValidImageIndex<T>(image_index);
220 ByteReader(
byte *data,
byte *end) : data(data), end(end) { }
222 inline byte *ReadBytes(
size_t size)
224 if (data + size >= end) {
235 inline byte ReadByte()
237 if (data < end)
return *(data)++;
243 uint16_t val = ReadByte();
244 return val | (ReadByte() << 8);
247 uint16_t ReadExtendedByte()
249 uint16_t val = ReadByte();
250 return val == 0xFF ? ReadWord() : val;
255 uint32_t val = ReadWord();
256 return val | (ReadWord() << 16);
259 uint32_t ReadVarSize(
byte size)
262 case 1:
return ReadByte();
263 case 2:
return ReadWord();
264 case 4:
return ReadDWord();
271 const char *ReadString()
273 char *
string =
reinterpret_cast<char *
>(data);
274 size_t string_length =
ttd_strnlen(
string, Remaining());
276 if (string_length == Remaining()) {
278 string[string_length - 1] =
'\0';
279 GrfMsg(7,
"String was not terminated with a zero byte.");
289 inline size_t Remaining()
const
294 inline bool HasData(
size_t count = 1)
const
296 return data + count <= end;
304 inline void Skip(
size_t len)
313 typedef void (*SpecialSpriteHandler)(
ByteReader *buf);
327 uint16_t cargo_allowed;
328 uint16_t cargo_disallowed;
329 RailTypeLabel railtypelabel;
330 uint8_t roadtramtype;
345 }
else if (this->refittability ==
UNSET) {
346 this->refittability =
EMPTY;
351 static std::vector<GRFTempEngineData>
_gted;
366 GRFLocation(uint32_t grfid, uint32_t nfoline) : grfid(grfid), nfoline(nfoline) { }
370 return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
375 return this->grfid == other.grfid && this->nfoline == other.nfoline;
379 static std::map<GRFLocation, SpriteID> _grm_sprites;
380 typedef std::map<GRFLocation, std::vector<byte>> GRFLineToSpriteOverride;
381 static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
393 void GrfMsgI(
int severity,
const std::string &msg)
406 if (file->grfid == grfid)
return file;
419 if (file->filename == filename)
return file;
439 if (config !=
nullptr) {
450 if (message == STR_NULL)
return nullptr;
452 config->error = {STR_NEWGRF_ERROR_MSG_FATAL, message};
454 return &config->error.value();
465 typedef std::vector<StringIDMapping> StringIDMappingVector;
466 static StringIDMappingVector _string_to_grf_mapping;
475 *target = STR_UNDEFINED;
476 _string_to_grf_mapping.push_back({_cur.
grffile->grfid, source, target});
489 static const StringID units_volume[] = {
490 STR_ITEMS, STR_PASSENGERS, STR_TONS, STR_BAGS,
491 STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS,
492 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
493 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
494 STR_TONS, STR_TONS, STR_BAGS, STR_LITERS,
495 STR_TONS, STR_LITERS, STR_TONS, STR_ITEMS,
496 STR_BAGS, STR_LITERS, STR_TONS, STR_ITEMS,
497 STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
503 #define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
504 static_assert(stringend - stringid == end - begin); \
505 if (str >= begin && str <= end) return str + (stringid - begin)
508 TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING, STR_CARGO_PLURAL_FIZZY_DRINKS);
509 TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING, STR_CARGO_SINGULAR_FIZZY_DRINK);
510 if (str >= 0x004E && str <= 0x006D)
return units_volume[str - 0x004E];
511 TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING, STR_QUANTITY_FIZZY_DRINKS);
512 TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING, STR_ABBREV_FIZZY_DRINKS);
513 TEXTID_TO_STRINGID(0x00D1, 0x00E0, STR_COLOUR_DARK_BLUE, STR_COLOUR_WHITE);
518 TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, STR_TOWN_BUILDING_NAME_OLD_HOUSES_1);
519 TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1);
520 TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1, STR_TOWN_BUILDING_NAME_PIGGY_BANK_1);
523 TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE, STR_INDUSTRY_NAME_SUGAR_MINE);
524 TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION, STR_NEWS_INDUSTRY_PLANTED);
525 TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL, STR_NEWS_INDUSTRY_CLOSURE_LACK_OF_TREES);
526 TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_FARM);
527 TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_FARM);
530 case 0x4830:
return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
531 case 0x4831:
return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
532 case 0x483B:
return STR_ERROR_CAN_ONLY_BE_POSITIONED;
534 #undef TEXTID_TO_STRINGID
536 if (str == STR_NULL)
return STR_EMPTY;
538 Debug(grf, 0,
"Unknown StringID 0x{:04X} remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
577 static std::map<uint32_t, uint32_t> _grf_id_overrides;
586 _grf_id_overrides[source_grfid] = target_grfid;
587 GrfMsg(5,
"SetNewGRFOverride: Added override of 0x{:X} to 0x{:X}",
BSWAP32(source_grfid),
BSWAP32(target_grfid));
602 uint32_t scope_grfid = INVALID_GRFID;
605 scope_grfid = file->grfid;
606 uint32_t
override = _grf_id_overrides[file->grfid];
608 scope_grfid =
override;
610 if (grf_match ==
nullptr) {
611 GrfMsg(5,
"Tried mapping from GRFID {:x} to {:x} but target is not loaded",
BSWAP32(file->grfid),
BSWAP32(
override));
613 GrfMsg(5,
"Mapping from GRFID {:x} to {:x}",
BSWAP32(file->grfid),
BSWAP32(
override));
618 EngineID engine = _engine_mngr.
GetID(type, internal_id, scope_grfid);
627 EngineID engine = _engine_mngr.
GetID(type, internal_id, INVALID_GRFID);
633 GrfMsg(5,
"Replaced engine at index {} for GRFID {:x}, type {}, index {}", e->
index,
BSWAP32(file->grfid), type, internal_id);
637 if (!static_access) {
639 eid->
grfid = scope_grfid;
645 if (static_access)
return nullptr;
648 GrfMsg(0,
"Can't allocate any more engines");
659 assert(_engine_mngr.size() == e->
index);
660 _engine_mngr.push_back({
675 GrfMsg(5,
"Created new engine at index {} for GRFID {:x}, type {}, index {}", e->
index,
BSWAP32(file->grfid), type, internal_id);
692 uint32_t scope_grfid = INVALID_GRFID;
694 scope_grfid = file->grfid;
695 uint32_t
override = _grf_id_overrides[file->grfid];
696 if (
override != 0) scope_grfid =
override;
699 return _engine_mngr.
GetID(type, internal_id, scope_grfid);
739 grf_sprite->
sprite = buf->ReadWord();
740 grf_sprite->
pal = buf->ReadWord();
745 bool custom_sprite =
HasBit(grf_sprite->
pal, 15) != invert_action1_flag;
749 uint index =
GB(grf_sprite->
sprite, 0, 14);
751 GrfMsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset {}", index);
752 grf_sprite->
sprite = SPR_IMG_QUERY;
753 grf_sprite->
pal = PAL_NONE;
756 if (max_sprite_offset !=
nullptr) *max_sprite_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
761 GrfMsg(1,
"ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite");
762 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
768 uint index =
GB(grf_sprite->
pal, 0, 14);
770 GrfMsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset {} for 'palette'", index);
771 grf_sprite->
pal = PAL_NONE;
774 if (max_palette_offset !=
nullptr) *max_palette_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
779 GrfMsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette");
780 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
809 regs.delta.
parent[0] = buf->ReadByte();
810 regs.delta.
parent[1] = buf->ReadByte();
821 GrfMsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 ({}) exceeding the maximal allowed value {}", regs.
sprite_var10,
TLR_MAX_VAR10);
822 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
830 GrfMsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 ({}) exceeding the maximal allowed value {}", regs.
palette_var10,
TLR_MAX_VAR10);
831 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
850 bool has_flags =
HasBit(num_building_sprites, 6);
851 ClrBit(num_building_sprites, 6);
854 dts->
Allocate(num_building_sprites);
856 std::vector<uint16_t> max_sprite_offset(num_building_sprites + 1, 0);
857 std::vector<uint16_t> max_palette_offset(num_building_sprites + 1, 0);
864 GrfMsg(1,
"ReadSpriteLayout: Spritelayout uses invalid flag 0x{:X} for ground sprite", flags & ~(valid_flags & ~
TLF_NON_GROUND_FLAGS));
865 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
872 for (uint i = 0; i < num_building_sprites; i++) {
875 flags =
ReadSpriteLayoutSprite(buf, has_flags,
false, use_cur_spritesets, feature, &seq->image, max_sprite_offset.data() + i + 1, max_palette_offset.data() + i + 1);
878 if (flags & ~valid_flags) {
879 GrfMsg(1,
"ReadSpriteLayout: Spritelayout uses unknown flag 0x{:X}", flags & ~valid_flags);
880 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
884 seq->
delta_x = buf->ReadByte();
885 seq->delta_y = buf->ReadByte();
887 if (!no_z_position) seq->
delta_z = buf->ReadByte();
890 seq->size_x = buf->ReadByte();
891 seq->size_y = buf->ReadByte();
892 seq->size_z = buf->ReadByte();
900 bool is_consistent =
true;
902 for (uint i = 0; i < num_building_sprites + 1; i++) {
903 if (max_sprite_offset[i] > 0) {
907 is_consistent =
false;
911 if (max_palette_offset[i] > 0) {
915 is_consistent =
false;
924 if (!is_consistent || dts->registers !=
nullptr) {
928 for (uint i = 0; i < num_building_sprites + 1; i++) {
943 CargoTypes result = 0;
961 if (base_pointer == 0) {
962 *index = INVALID_PRICE;
966 static const uint32_t start = 0x4B34;
967 static const uint32_t size = 6;
969 if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) {
970 GrfMsg(1,
"{}: Unsupported running cost base 0x{:04X}, ignoring", error_location, base_pointer);
974 *index = (
Price)((base_pointer - start) / size);
1003 ei->decay_speed = buf->ReadByte();
1020 ei->load_amount = buf->ReadByte();
1042 for (
int i = 0; i < numinfo; i++) {
1051 uint8_t tracktype = buf->ReadByte();
1053 if (tracktype < _cur.grffile->railtype_list.size()) {
1058 switch (tracktype) {
1059 case 0:
_gted[e->
index].railtypelabel = rvi->
engclass >= 2 ? RAILTYPE_LABEL_ELECTRIC : RAILTYPE_LABEL_RAIL;
break;
1060 case 1:
_gted[e->
index].railtypelabel = RAILTYPE_LABEL_MONO;
break;
1061 case 2:
_gted[e->
index].railtypelabel = RAILTYPE_LABEL_MAGLEV;
break;
1063 GrfMsg(1,
"RailVehicleChangeInfo: Invalid track type {} specified, ignoring", tracktype);
1076 uint16_t speed = buf->ReadWord();
1077 if (speed == 0xFFFF) speed = 0;
1084 rvi->
power = buf->ReadWord();
1087 if (rvi->
power != 0) {
1105 uint8_t spriteid = buf->ReadByte();
1106 uint8_t orig_spriteid = spriteid;
1110 if (spriteid < 0xFD) spriteid >>= 1;
1112 if (IsValidNewGRFImageIndex<VEH_TRAIN>(spriteid)) {
1113 rvi->image_index = spriteid;
1115 GrfMsg(1,
"RailVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1116 rvi->image_index = 0;
1122 uint8_t dual = buf->ReadByte();
1127 rvi->railveh_type = rvi->
power == 0 ?
1139 uint8_t ctype = buf->ReadByte();
1141 if (ctype == 0xFF) {
1143 ei->cargo_type = INVALID_CARGO;
1144 }
else if (_cur.
grffile->grf_version >= 8) {
1149 ei->cargo_type = ctype;
1151 ei->cargo_type = INVALID_CARGO;
1152 GrfMsg(2,
"RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1159 SB(rvi->
weight, 0, 8, buf->ReadByte());
1167 GrfMsg(2,
"RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored.");
1179 uint8_t traction = buf->ReadByte();
1182 if (traction <= 0x07) {
1184 }
else if (traction <= 0x27) {
1186 }
else if (traction <= 0x31) {
1188 }
else if (traction <= 0x37) {
1190 }
else if (traction <= 0x41) {
1216 ei->refit_cost = buf->ReadByte();
1220 uint32_t mask = buf->ReadDWord();
1221 _gted[e->
index].UpdateRefittability(mask != 0);
1258 byte weight = buf->ReadByte();
1261 GrfMsg(2,
"RailVehicleChangeInfo: Nonsensical weight of {} tons, ignoring", weight << 8);
1282 _gted[e->
index].cargo_allowed = buf->ReadWord();
1288 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1302 uint8_t count = buf->ReadByte();
1303 _gted[e->
index].UpdateRefittability(prop == 0x2C && count != 0);
1305 CargoTypes &ctt = prop == 0x2C ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1351 for (
int i = 0; i < numinfo; i++) {
1362 _gted[e->
index].roadtramtype = buf->ReadByte() + 1;
1370 rvi->running_cost = buf->ReadByte();
1378 uint8_t spriteid = buf->ReadByte();
1379 uint8_t orig_spriteid = spriteid;
1382 if (spriteid == 0xFF) spriteid = 0xFD;
1384 if (spriteid < 0xFD) spriteid >>= 1;
1386 if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
1387 rvi->image_index = spriteid;
1389 GrfMsg(1,
"RoadVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1390 rvi->image_index = 0;
1396 rvi->capacity = buf->ReadByte();
1401 uint8_t ctype = buf->ReadByte();
1403 if (ctype == 0xFF) {
1405 ei->cargo_type = INVALID_CARGO;
1406 }
else if (_cur.
grffile->grf_version >= 8) {
1411 ei->cargo_type = ctype;
1413 ei->cargo_type = INVALID_CARGO;
1414 GrfMsg(2,
"RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1421 rvi->cost_factor = buf->ReadByte();
1429 rvi->
power = buf->ReadByte();
1433 rvi->
weight = buf->ReadByte();
1437 _gted[e->
index].rv_max_speed = buf->ReadByte();
1441 uint32_t mask = buf->ReadDWord();
1442 _gted[e->
index].UpdateRefittability(mask != 0);
1461 ei->refit_cost = buf->ReadByte();
1474 _gted[e->
index].cargo_allowed = buf->ReadWord();
1480 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1512 uint8_t count = buf->ReadByte();
1513 _gted[e->
index].UpdateRefittability(prop == 0x24 && count != 0);
1515 CargoTypes &ctt = prop == 0x24 ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1557 for (
int i = 0; i < numinfo; i++) {
1566 uint8_t spriteid = buf->ReadByte();
1567 uint8_t orig_spriteid = spriteid;
1570 if (spriteid == 0xFF) spriteid = 0xFD;
1572 if (spriteid < 0xFD) spriteid >>= 1;
1574 if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
1575 svi->image_index = spriteid;
1577 GrfMsg(1,
"ShipVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1578 svi->image_index = 0;
1588 svi->cost_factor = buf->ReadByte();
1597 uint8_t ctype = buf->ReadByte();
1599 if (ctype == 0xFF) {
1601 ei->cargo_type = INVALID_CARGO;
1602 }
else if (_cur.
grffile->grf_version >= 8) {
1607 ei->cargo_type = ctype;
1609 ei->cargo_type = INVALID_CARGO;
1610 GrfMsg(2,
"ShipVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1617 svi->capacity = buf->ReadWord();
1621 svi->running_cost = buf->ReadByte();
1629 uint32_t mask = buf->ReadDWord();
1630 _gted[e->
index].UpdateRefittability(mask != 0);
1641 ei->refit_cost = buf->ReadByte();
1662 _gted[e->
index].cargo_allowed = buf->ReadWord();
1668 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1696 uint8_t count = buf->ReadByte();
1697 _gted[e->
index].UpdateRefittability(prop == 0x1E && count != 0);
1699 CargoTypes &ctt = prop == 0x1E ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1725 svi->
acceleration = std::max<uint8_t>(1, buf->ReadByte());
1749 for (
int i = 0; i < numinfo; i++) {
1758 uint8_t spriteid = buf->ReadByte();
1759 uint8_t orig_spriteid = spriteid;
1762 if (spriteid == 0xFF) spriteid = 0xFD;
1764 if (spriteid < 0xFD) spriteid >>= 1;
1766 if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
1767 avi->image_index = spriteid;
1769 GrfMsg(1,
"AircraftVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1770 avi->image_index = 0;
1776 if (buf->ReadByte() == 0) {
1784 SB(avi->
subtype, 1, 1, (buf->ReadByte() != 0 ? 1 : 0));
1788 avi->cost_factor = buf->ReadByte();
1792 avi->
max_speed = (buf->ReadByte() * 128) / 10;
1796 avi->acceleration = buf->ReadByte();
1800 avi->running_cost = buf->ReadByte();
1816 uint32_t mask = buf->ReadDWord();
1817 _gted[e->
index].UpdateRefittability(mask != 0);
1828 ei->refit_cost = buf->ReadByte();
1841 _gted[e->
index].cargo_allowed = buf->ReadWord();
1847 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1865 uint8_t count = buf->ReadByte();
1866 _gted[e->
index].UpdateRefittability(prop == 0x1D && count != 0);
1868 CargoTypes &ctt = prop == 0x1D ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1915 GrfMsg(1,
"StationChangeInfo: Station {} is invalid, max {}, ignoring", stid + numinfo,
NUM_STATIONS_PER_GRF);
1920 if (_cur.
grffile->stations.size() < stid + numinfo) _cur.
grffile->stations.resize(stid + numinfo);
1922 for (
int i = 0; i < numinfo; i++) {
1926 if (statspec ==
nullptr && prop != 0x08) {
1927 GrfMsg(2,
"StationChangeInfo: Attempt to modify undefined station {}, ignoring", stid + i);
1934 if (statspec ==
nullptr) {
1935 _cur.
grffile->stations[stid + i] = std::make_unique<StationSpec>();
1936 statspec = _cur.
grffile->stations[stid + i].get();
1940 uint32_t classid = buf->ReadDWord();
1941 statspec->
cls_id = StationClass::Allocate(
BSWAP32(classid));
1946 uint16_t tiles = buf->ReadExtendedByte();
1950 for (uint t = 0; t < tiles; t++) {
1954 if (buf->HasData(4) && *(uint32_t*)buf->Data() == 0) {
1957 dts->
Clone(&_station_display_datas_rail[t % 8]);
1965 static std::vector<DrawTileSeqStruct> tmp_layout;
1972 dtss.
delta_x = buf->ReadByte();
1974 dtss.delta_y = buf->ReadByte();
1975 dtss.
delta_z = buf->ReadByte();
1976 dtss.size_x = buf->ReadByte();
1977 dtss.size_y = buf->ReadByte();
1978 dtss.size_z = buf->ReadByte();
1984 dts->
Clone(tmp_layout.data());
1989 GrfMsg(1,
"StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i);
1996 uint16_t srcid = buf->ReadExtendedByte();
1997 const StationSpec *srcstatspec = srcid >= _cur.
grffile->stations.size() ? nullptr : _cur.
grffile->stations[srcid].get();
1999 if (srcstatspec ==
nullptr) {
2000 GrfMsg(1,
"StationChangeInfo: Station {} is not defined, cannot copy sprite layout to {}.", srcid, stid + i);
2007 for (
const auto &it : srcstatspec->
renderdata) {
2027 while (buf->HasData()) {
2028 byte length = buf->ReadByte();
2029 byte number = buf->ReadByte();
2031 if (length == 0 || number == 0)
break;
2033 if (statspec->
layouts.size() < length) statspec->
layouts.resize(length);
2034 if (statspec->
layouts[length - 1].size() < number) statspec->
layouts[length - 1].resize(number);
2036 const byte *layout = buf->ReadBytes(length * number);
2037 statspec->
layouts[length - 1][number - 1].assign(layout, layout + length * number);
2040 for (
auto &tile : statspec->
layouts[length - 1][number - 1]) {
2041 if ((tile & 6) != tile) {
2042 GrfMsg(1,
"StationChangeInfo: Invalid tile {} in layout {}x{}", tile, length, number);
2050 uint16_t srcid = buf->ReadExtendedByte();
2051 const StationSpec *srcstatspec = srcid >= _cur.
grffile->stations.size() ? nullptr : _cur.
grffile->stations[srcid].get();
2053 if (srcstatspec ==
nullptr) {
2054 GrfMsg(1,
"StationChangeInfo: Station {} is not defined, cannot copy tile layout to {}.", srcid, stid + i);
2067 statspec->
pylons = buf->ReadByte();
2071 if (_cur.
grffile->grf_version >= 7) {
2079 statspec->
flags = buf->ReadByte();
2083 statspec->
wires = buf->ReadByte();
2087 statspec->
blocked = buf->ReadByte();
2091 statspec->animation.
frames = buf->ReadByte();
2092 statspec->animation.
status = buf->ReadByte();
2096 statspec->animation.
speed = buf->ReadByte();
2100 statspec->animation.
triggers = buf->ReadWord();
2106 uint16_t tiles = buf->ReadExtendedByte();
2110 for (uint t = 0; t < tiles; t++) {
2112 uint num_building_sprites = buf->ReadByte();
2119 GrfMsg(1,
"StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i);
2161 if (
id + numinfo > CF_END) {
2162 GrfMsg(1,
"CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring",
id + numinfo, CF_END);
2166 for (
int i = 0; i < numinfo; i++) {
2175 cp->
flags = buf->ReadByte();
2200 GrfMsg(1,
"BridgeChangeInfo: Bridge {} is invalid, max {}, ignoring", brid + numinfo,
MAX_BRIDGES);
2204 for (
int i = 0; i < numinfo; i++) {
2210 byte year = buf->ReadByte();
2225 bridge->
price = buf->ReadByte();
2229 bridge->
speed = buf->ReadWord();
2230 if (bridge->
speed == 0) bridge->
speed = UINT16_MAX;
2234 byte tableid = buf->ReadByte();
2235 byte numtables = buf->ReadByte();
2242 for (; numtables-- != 0; tableid++) {
2244 GrfMsg(1,
"BridgeChangeInfo: Table {} >= 7, skipping", tableid);
2245 for (
byte sprite = 0; sprite < 32; sprite++) buf->ReadDWord();
2250 bridge->
sprite_table[tableid] = MallocT<PalSpriteID>(32);
2253 for (
byte sprite = 0; sprite < 32; sprite++) {
2267 bridge->
flags = buf->ReadByte();
2276 if (newone != STR_UNDEFINED) bridge->
material = newone;
2283 if (newone != STR_UNDEFINED) bridge->
transport_name[prop - 0x11] = newone;
2288 bridge->
price = buf->ReadWord();
2345 for (uint j = 0; j < 4; j++) buf->ReadByte();
2349 byte count = buf->ReadByte();
2350 for (
byte j = 0; j < count; j++) buf->ReadByte();
2355 buf->Skip(buf->ReadByte() * 2);
2378 GrfMsg(1,
"TownHouseChangeInfo: Too many houses loaded ({}), max ({}). Ignoring.", hid + numinfo,
NUM_HOUSES_PER_GRF);
2383 if (_cur.
grffile->housespec.size() < hid + numinfo) _cur.
grffile->housespec.resize(hid + numinfo);
2385 for (
int i = 0; i < numinfo; i++) {
2388 if (prop != 0x08 && housespec ==
nullptr) {
2391 if (cir > ret) ret = cir;
2397 byte subs_id = buf->ReadByte();
2398 if (subs_id == 0xFF) {
2405 GrfMsg(2,
"TownHouseChangeInfo: Attempt to use new house {} as substitute house for {}. Ignoring.", subs_id, hid + i);
2410 if (housespec ==
nullptr) {
2412 _cur.
grffile->housespec[hid + i] = std::make_unique<HouseSpec>(*HouseSpec::Get(subs_id));
2413 housespec = _cur.
grffile->housespec[hid + i].get();
2417 housespec->
grf_prop.subst_id = subs_id;
2426 housespec->
building_flags &= ~(BUILDING_IS_CHURCH | BUILDING_IS_STADIUM);
2446 uint16_t years = buf->ReadWord();
2466 int8_t goods = buf->ReadByte();
2503 byte override = buf->ReadByte();
2507 GrfMsg(2,
"TownHouseChangeInfo: Attempt to override new house {} with house id {}. Ignoring.",
override, hid + i);
2511 _house_mngr.
Add(hid + i, _cur.
grffile->grfid,
override);
2520 for (uint j = 0; j < 4; j++) housespec->
random_colour[j] =
static_cast<Colours
>(
GB(buf->ReadByte(), 0, 4));
2542 housespec->
class_id = AllocateHouseClassID(buf->ReadByte(), _cur.
grffile->grfid);
2550 uint32_t cargotypes = buf->ReadDWord();
2553 if (cargotypes == 0xFFFFFFFF)
break;
2555 for (uint j = 0; j < 3; j++) {
2557 uint8_t cargo_part =
GB(cargotypes, 8 * j, 8);
2576 byte count = buf->ReadByte();
2577 for (
byte j = 0; j < count; j++) {
2585 housespec->
min_year = buf->ReadWord();
2589 housespec->
max_year = buf->ReadWord();
2593 uint count = buf->ReadByte();
2646 template <
typename T>
2650 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
2654 translation_table.clear();
2655 for (
int i = 0; i < numinfo; i++) {
2656 translation_table.push_back(T(
BSWAP32(buf->ReadDWord())));
2671 for (
int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
2705 for (
int i = 0; i < numinfo; i++) {
2708 int factor = buf->ReadByte();
2709 uint price = gvid + i;
2711 if (price < PR_END) {
2714 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring", price);
2723 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2732 uint32_t rate = buf->ReadDWord();
2740 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
2747 uint16_t options = buf->ReadWord();
2756 GrfMsg(1,
"GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
2768 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2780 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2792 GrfMsg(1,
"GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
2799 GrfMsg(1,
"GlobalVarChangeInfo: The snowline can only be set once ({})", numinfo);
2801 GrfMsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf->Remaining());
2807 table[i][j] = buf->ReadByte();
2808 if (_cur.
grffile->grf_version >= 8) {
2811 if (table[i][j] >= 128) {
2833 uint curidx = gvid + i;
2835 if (lang ==
nullptr) {
2836 GrfMsg(1,
"GlobalVarChangeInfo: Language {} is not known, ignoring", curidx);
2841 while (buf->ReadByte() != 0) {
2851 uint plural_form = buf->ReadByte();
2852 if (plural_form >= LANGUAGE_MAX_PLURAL) {
2853 GrfMsg(1,
"GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form);
2860 byte newgrf_id = buf->ReadByte();
2861 while (newgrf_id != 0) {
2862 const char *name = buf->ReadString();
2877 GrfMsg(1,
"GlobalVarChangeInfo: Gender name {} is not known, ignoring", name);
2884 GrfMsg(1,
"GlobalVarChangeInfo: Case name {} is not known, ignoring", name);
2889 newgrf_id = buf->ReadByte();
2925 for (
int i = 0; i < numinfo; i++) {
2949 uint32_t s = buf->ReadDWord();
2950 uint32_t t = buf->ReadDWord();
2957 while (buf->ReadByte() != 0) {
2985 GrfMsg(2,
"CargoChangeInfo: Cargo type {} out of range (max {})", cid + numinfo,
NUM_CARGO - 1);
2989 for (
int i = 0; i < numinfo; i++) {
2994 cs->
bitnum = buf->ReadByte();
3033 cs->
sprite = buf->ReadWord();
3037 cs->
weight = buf->ReadByte();
3041 cs->transit_periods[0] = buf->ReadByte();
3045 cs->transit_periods[1] = buf->ReadByte();
3053 cs->rating_colour = buf->ReadByte();
3057 cs->legend_colour = buf->ReadByte();
3065 cs->
classes = buf->ReadWord();
3074 uint8_t substitute_type = buf->ReadByte();
3076 switch (substitute_type) {
3083 GrfMsg(1,
"CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type);
3099 cs->
multiplier = std::max<uint16_t>(1u, buf->ReadWord());
3103 uint8_t substitute_type = buf->ReadByte();
3105 switch (substitute_type) {
3109 GrfMsg(1,
"CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type);
3142 if (_cur.
grffile->sound_offset == 0) {
3143 GrfMsg(1,
"SoundEffectChangeInfo: No effects defined, skipping");
3148 GrfMsg(1,
"SoundEffectChangeInfo: Attempting to change undefined sound effect ({}), max ({}). Ignoring.", sid + numinfo,
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
3152 for (
int i = 0; i < numinfo; i++) {
3157 sound->volume = buf->ReadByte();
3161 sound->priority = buf->ReadByte();
3165 SoundID orig_sound = buf->ReadByte();
3168 GrfMsg(1,
"SoundEffectChangeInfo: Original sound {} not defined (max {})", orig_sound,
ORIGINAL_SAMPLE_COUNT);
3170 SoundEntry *old_sound = GetSound(orig_sound);
3173 *old_sound = *sound;
3215 buf->Skip(buf->ReadByte() * 2);
3238 GrfMsg(1,
"IndustryTilesChangeInfo: Too many industry tiles loaded ({}), max ({}). Ignoring.", indtid + numinfo,
NUM_INDUSTRYTILES_PER_GRF);
3243 if (_cur.
grffile->indtspec.size() < indtid + numinfo) _cur.
grffile->indtspec.resize(indtid + numinfo);
3245 for (
int i = 0; i < numinfo; i++) {
3248 if (prop != 0x08 && tsp ==
nullptr) {
3250 if (cir > ret) ret = cir;
3256 byte subs_id = buf->ReadByte();
3259 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to use new industry tile {} as substitute industry tile for {}. Ignoring.", subs_id, indtid + i);
3264 if (tsp ==
nullptr) {
3265 _cur.
grffile->indtspec[indtid + i] = std::make_unique<IndustryTileSpec>(_industry_tile_specs[subs_id]);
3266 tsp = _cur.
grffile->indtspec[indtid + i].get();
3285 byte ovrid = buf->ReadByte();
3289 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to override new industry tile {} with industry tile id {}. Ignoring.", ovrid, indtid + i);
3293 _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
3300 uint16_t acctp = buf->ReadWord();
3303 tsp->accepts_cargo_label[prop - 0x0A] =
CT_INVALID;
3333 byte num_cargoes = buf->ReadByte();
3334 if (num_cargoes > std::size(tsp->
acceptance)) {
3339 for (uint i = 0; i < std::size(tsp->
acceptance); i++) {
3340 if (i < num_cargoes) {
3343 tsp->
acceptance[i] = (int8_t)buf->ReadByte();
3408 byte num_table = buf->ReadByte();
3409 for (
byte j = 0; j < num_table; j++) {
3410 for (uint k = 0;; k++) {
3411 byte x = buf->ReadByte();
3412 if (x == 0xFE && k == 0) {
3418 byte y = buf->ReadByte();
3419 if (x == 0 && y == 0x80)
break;
3421 byte gfx = buf->ReadByte();
3422 if (gfx == 0xFE) buf->ReadWord();
3429 for (
byte j = 0; j < 3; j++) buf->ReadByte();
3436 buf->Skip(buf->ReadByte());
3440 int num_inputs = buf->ReadByte();
3441 int num_outputs = buf->ReadByte();
3442 buf->Skip(num_inputs * num_outputs * 2);
3460 const size_t size = layout.size();
3461 if (size == 0)
return false;
3463 for (
size_t i = 0; i < size - 1; i++) {
3464 for (
size_t j = i + 1; j < size; j++) {
3465 if (layout[i].ti.x == layout[j].ti.x &&
3466 layout[i].ti.y == layout[j].ti.y) {
3472 bool have_regular_tile =
false;
3473 for (
const auto &tilelayout : layout) {
3475 have_regular_tile =
true;
3480 return have_regular_tile;
3496 GrfMsg(1,
"IndustriesChangeInfo: Too many industries loaded ({}), max ({}). Ignoring.", indid + numinfo,
NUM_INDUSTRYTYPES_PER_GRF);
3501 if (_cur.
grffile->industryspec.size() < indid + numinfo) _cur.
grffile->industryspec.resize(indid + numinfo);
3503 for (
int i = 0; i < numinfo; i++) {
3506 if (prop != 0x08 && indsp ==
nullptr) {
3508 if (cir > ret) ret = cir;
3514 byte subs_id = buf->ReadByte();
3515 if (subs_id == 0xFF) {
3518 _industry_specs[indid + i].
enabled =
false;
3522 GrfMsg(2,
"_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id, indid + i);
3529 if (indsp ==
nullptr) {
3530 _cur.
grffile->industryspec[indid + i] = std::make_unique<IndustrySpec>(_origin_industry_specs[subs_id]);
3531 indsp = _cur.
grffile->industryspec[indid + i].get();
3535 indsp->
grf_prop.subst_id = subs_id;
3545 byte ovrid = buf->ReadByte();
3549 GrfMsg(2,
"IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid, indid + i);
3553 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3558 byte new_num_layouts = buf->ReadByte();
3559 uint32_t definition_size = buf->ReadDWord();
3560 uint32_t bytes_read = 0;
3561 std::vector<IndustryTileLayout> new_layouts;
3564 for (
byte j = 0; j < new_num_layouts; j++) {
3567 for (uint k = 0;; k++) {
3568 if (bytes_read >= definition_size) {
3569 GrfMsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.", indid);
3571 definition_size = UINT32_MAX;
3577 it.ti.
x = buf->ReadByte();
3580 if (it.ti.
x == 0xFE && k == 0) {
3582 IndustryType type = buf->ReadByte();
3583 byte laynbr = buf->ReadByte();
3586 if (type >=
lengthof(_origin_industry_specs)) {
3587 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry {}", indid);
3591 if (laynbr >= _origin_industry_specs[type].layouts.size()) {
3592 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}", indid);
3596 layout = _origin_industry_specs[type].layouts[laynbr];
3600 it.ti.
y = buf->ReadByte();
3603 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
3609 it.gfx = buf->ReadByte();
3612 if (it.gfx == 0xFE) {
3614 int local_tile_id = buf->ReadWord();
3618 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3621 GrfMsg(2,
"IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id, indid);
3627 it.ti.
x = (int8_t)
GB(it.ti.
x, 0, 8);
3628 it.ti.
y = (int8_t)
GB(it.ti.
y, 0, 8);
3637 if (_cur.
grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
3643 GrfMsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring", indid);
3647 new_layouts.push_back(layout);
3677 for (
byte j = 0; j < 2; j++) {
3684 for (
byte j = 0; j < 3; j++) {
3693 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3706 sounds[j] = buf->ReadByte();
3722 for (
byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3748 uint32_t multiples = buf->ReadDWord();
3764 byte aflag = buf->ReadByte();
3774 uint16_t str = buf->ReadWord();
3784 byte num_cargoes = buf->ReadByte();
3785 if (num_cargoes >
lengthof(indsp->produced_cargo)) {
3790 for (uint i = 0; i <
lengthof(indsp->produced_cargo); i++) {
3791 if (i < num_cargoes) {
3793 indsp->produced_cargo[i] = cargo;
3795 indsp->produced_cargo[i] = INVALID_CARGO;
3803 byte num_cargoes = buf->ReadByte();
3810 if (i < num_cargoes) {
3822 byte num_cargoes = buf->ReadByte();
3823 if (num_cargoes >
lengthof(indsp->production_rate)) {
3828 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
3829 if (i < num_cargoes) {
3830 indsp->production_rate[i] = buf->ReadByte();
3832 indsp->production_rate[i] = 0;
3839 byte num_inputs = buf->ReadByte();
3840 byte num_outputs = buf->ReadByte();
3847 for (uint j = 0; j <
lengthof(indsp->produced_cargo); j++) {
3849 if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
3873 for (
int i = 0; i < as->
num_table; i++) {
3878 }
while ((++it)->ti.x != -0x80);
3879 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3882 as->
table = table_list;
3904 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3909 if (_cur.
grffile->airportspec.size() < airport + numinfo) _cur.
grffile->airportspec.resize(airport + numinfo);
3911 for (
int i = 0; i < numinfo; i++) {
3914 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
3915 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring", airport + i);
3921 byte subs_id = buf->ReadByte();
3922 if (subs_id == 0xFF) {
3929 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id, airport + i);
3936 if (as ==
nullptr) {
3938 as = _cur.
grffile->airportspec[airport + i].get();
3945 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3957 uint32_t defsize = buf->ReadDWord();
3963 for (
byte j = 0; j < as->
num_table; j++) {
3965 for (
int k = 0;; k++) {
3966 att[k].
ti.
x = buf->ReadByte();
3967 att[k].
ti.
y = buf->ReadByte();
3969 if (att[k].ti.x == 0 && att[k].
ti.
y == 0x80) {
3972 att[k].
ti.
x = -0x80;
3981 att[k].
gfx = buf->ReadByte();
3983 if (att[k].gfx == 0xFE) {
3985 int local_tile_id = buf->ReadWord();
3988 uint16_t tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3991 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id, airport + i);
3994 att[k].
gfx = tempid;
3996 }
else if (att[k].gfx == 0xFF) {
3997 att[k].
ti.
x = (int8_t)
GB(att[k].ti.x, 0, 8);
3998 att[k].
ti.
y = (int8_t)
GB(att[k].ti.y, 0, 8);
4009 tile_table[j] = CallocT<AirportTileTable>(size);
4010 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
4013 for (
int j = 0; j < old_num_table; j++) {
4019 as->
table = tile_table;
4022 for (
int i = 0; i < as->
num_table; i++) {
4023 free(tile_table[i]);
4125 GrfMsg(1,
"ObjectChangeInfo: Too many objects loaded ({}), max ({}). Ignoring.",
id + numinfo,
NUM_OBJECTS_PER_GRF);
4130 if (_cur.
grffile->objectspec.size() <
id + numinfo) _cur.
grffile->objectspec.resize(
id + numinfo);
4132 for (
int i = 0; i < numinfo; i++) {
4135 if (prop != 0x08 && spec ==
nullptr) {
4138 if (cir > ret) ret = cir;
4145 if (spec ==
nullptr) {
4146 _cur.
grffile->objectspec[
id + i] = std::make_unique<ObjectSpec>();
4147 spec = _cur.
grffile->objectspec[
id + i].get();
4153 uint32_t classid = buf->ReadDWord();
4169 spec->
climate = buf->ReadByte();
4173 spec->
size = buf->ReadByte();
4174 if (
GB(spec->
size, 0, 4) == 0 ||
GB(spec->
size, 4, 4) == 0) {
4175 GrfMsg(0,
"ObjectChangeInfo: Invalid object size requested (0x{:X}) for object id {}. Ignoring.", spec->
size,
id + i);
4220 spec->
height = buf->ReadByte();
4224 spec->
views = buf->ReadByte();
4226 GrfMsg(2,
"ObjectChangeInfo: Invalid number of views ({}) for object id {}. Ignoring.", spec->
views,
id + i);
4259 GrfMsg(1,
"RailTypeChangeInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4263 for (
int i = 0; i < numinfo; i++) {
4276 uint16_t str = buf->ReadWord();
4278 if (_cur.
grffile->grf_version < 8) {
4308 int n = buf->ReadByte();
4309 for (
int j = 0; j != n; j++) {
4310 RailTypeLabel label = buf->ReadDWord();
4370 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4389 GrfMsg(1,
"RailTypeReserveInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4393 for (
int i = 0; i < numinfo; i++) {
4397 RailTypeLabel rtl = buf->ReadDWord();
4406 _cur.
grffile->railtype_map[
id + i] = rt;
4424 int n = buf->ReadByte();
4425 for (
int j = 0; j != n; j++) {
4430 GrfMsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set",
id + i);
4437 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4478 GrfMsg(1,
"RoadTypeChangeInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4482 for (
int i = 0; i < numinfo; i++) {
4495 uint16_t str = buf->ReadWord();
4522 int n = buf->ReadByte();
4523 for (
int j = 0; j != n; j++) {
4524 RoadTypeLabel label = buf->ReadDWord();
4529 if (GetRoadTramType(resolved_rt) == rtt) {
4532 GrfMsg(1,
"RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt);
4577 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4608 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4612 for (
int i = 0; i < numinfo; i++) {
4615 RoadTypeLabel rtl = buf->ReadDWord();
4622 }
else if (GetRoadTramType(rt) != rtt) {
4623 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid type (road/tram), ignoring",
id + numinfo);
4627 type_map[
id + i] = rt;
4644 int n = buf->ReadByte();
4645 for (
int j = 0; j != n; j++) {
4650 GrfMsg(1,
"RoadTypeReserveInfo: Ignoring property 1D for road type {} because no label was set",
id + i);
4656 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4680 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_ROAD);
4685 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_TRAM);
4693 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", airtid + numinfo,
NUM_AIRPORTTILES_PER_GRF);
4698 if (_cur.
grffile->airtspec.size() < airtid + numinfo) _cur.
grffile->airtspec.resize(airtid + numinfo);
4700 for (
int i = 0; i < numinfo; i++) {
4703 if (prop != 0x08 && tsp ==
nullptr) {
4704 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.", airtid + i);
4710 byte subs_id = buf->ReadByte();
4713 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id, airtid + i);
4718 if (tsp ==
nullptr) {
4720 tsp = _cur.
grffile->airtspec[airtid + i].get();
4735 byte override = buf->ReadByte();
4739 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.",
override, airtid + i);
4743 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4818 GrfMsg(1,
"RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring",
id + numinfo,
NUM_ROADSTOPS_PER_GRF);
4822 if (_cur.
grffile->roadstops.size() <
id + numinfo) _cur.
grffile->roadstops.resize(
id + numinfo);
4824 for (
int i = 0; i < numinfo; i++) {
4827 if (rs ==
nullptr && prop != 0x08) {
4828 GrfMsg(1,
"RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring",
id + i);
4830 if (cir > ret) ret = cir;
4836 if (rs ==
nullptr) {
4837 _cur.
grffile->roadstops[
id + i] = std::make_unique<RoadStopSpec>();
4838 rs = _cur.
grffile->roadstops[
id + i].get();
4841 uint32_t classid = buf->ReadDWord();
4868 rs->animation.
frames = buf->ReadByte();
4869 rs->animation.
status = buf->ReadByte();
4873 rs->animation.
speed = buf->ReadByte();
4877 rs->animation.
triggers = buf->ReadWord();
4881 rs->callback_mask = buf->ReadByte();
4885 rs->flags = (uint8_t)buf->ReadDWord();
4902 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property)
4905 default: NOT_REACHED();
4915 GrfMsg(1,
"{}: Ignoring property 0x{:02X} of feature 0x{:02X} (not implemented)", caller, property, feature);
4919 GrfMsg(0,
"{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature);
4932 static void FeatureChangeInfo(
ByteReader *buf)
4945 static const VCI_Handler handler[] = {
4963 AirportTilesChangeInfo,
4968 static_assert(GSF_END ==
lengthof(handler));
4970 uint8_t feature = buf->ReadByte();
4971 uint8_t numprops = buf->ReadByte();
4972 uint numinfo = buf->ReadByte();
4973 uint engine = buf->ReadExtendedByte();
4975 if (feature >= GSF_END) {
4976 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4980 GrfMsg(6,
"FeatureChangeInfo: Feature 0x{:02X}, {} properties, to apply to {}+{}",
4981 feature, numprops, engine, numinfo);
4983 if (handler[feature] ==
nullptr) {
4984 if (feature != GSF_CARGOES) GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4991 while (numprops-- && buf->HasData()) {
4992 uint8_t prop = buf->ReadByte();
4995 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
5002 uint8_t feature = buf->ReadByte();
5003 uint8_t numprops = buf->ReadByte();
5004 uint numinfo = buf->ReadByte();
5005 buf->ReadExtendedByte();
5007 if (feature == GSF_BRIDGES && numprops == 1) {
5008 uint8_t prop = buf->ReadByte();
5011 if (prop == 0x0D)
return;
5012 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
5013 uint8_t prop = buf->ReadByte();
5016 bool is_safe =
true;
5017 for (uint i = 0; i < numinfo; i++) {
5018 uint32_t s = buf->ReadDWord();
5026 if (is_safe)
return;
5037 static void ReserveChangeInfo(
ByteReader *buf)
5039 uint8_t feature = buf->ReadByte();
5041 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES && feature != GSF_ROADTYPES && feature != GSF_TRAMTYPES)
return;
5043 uint8_t numprops = buf->ReadByte();
5044 uint8_t numinfo = buf->ReadByte();
5045 uint8_t index = buf->ReadExtendedByte();
5047 while (numprops-- && buf->HasData()) {
5048 uint8_t prop = buf->ReadByte();
5052 default: NOT_REACHED();
5058 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
5062 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
5066 cir = RoadTypeReserveInfo(index, numinfo, prop, buf);
5070 cir = TramTypeReserveInfo(index, numinfo, prop, buf);
5074 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
5095 uint8_t feature = buf->ReadByte();
5096 uint16_t num_sets = buf->ReadByte();
5097 uint16_t first_set = 0;
5099 if (num_sets == 0 && buf->HasData(3)) {
5102 first_set = buf->ReadExtendedByte();
5103 num_sets = buf->ReadExtendedByte();
5105 uint16_t num_ents = buf->ReadExtendedByte();
5107 if (feature >= GSF_END) {
5109 GrfMsg(1,
"NewSpriteSet: Unsupported feature 0x{:02X}, skipping {} sprites", feature, _cur.
skip_sprites);
5115 GrfMsg(7,
"New sprite set at {} of feature 0x{:02X}, consisting of {} sets with {} views each (total {})",
5116 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
5119 for (
int i = 0; i < num_sets * num_ents; i++) {
5129 uint16_t num_sets = buf->ReadByte();
5131 if (num_sets == 0 && buf->HasData(3)) {
5134 buf->ReadExtendedByte();
5135 num_sets = buf->ReadExtendedByte();
5137 uint16_t num_ents = buf->ReadExtendedByte();
5141 GrfMsg(3,
"SkipAct1: Skipping {} sprites", _cur.
skip_sprites);
5146 static const SpriteGroup *GetGroupFromGroupID(
byte setid,
byte type, uint16_t groupid)
5148 if (
HasBit(groupid, 15)) {
5153 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5154 GrfMsg(1,
"GetGroupFromGroupID(0x{:02X}:0x{:02X}): Groupid 0x{:04X} does not exist, leaving empty", setid, type, groupid);
5158 return _cur.spritegroups[groupid];
5171 if (
HasBit(spriteid, 15)) {
5177 GrfMsg(1,
"CreateGroupFromGroupID(0x{:02X}:0x{:02X}): Sprite set {} invalid", setid, type, spriteid);
5182 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
5185 assert(spriteset_start + num_sprites <= _cur.
spriteid);
5206 uint8_t feature = buf->ReadByte();
5207 if (feature >= GSF_END) {
5208 GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5212 uint8_t setid = buf->ReadByte();
5213 uint8_t type = buf->ReadByte();
5237 switch (
GB(type, 2, 2)) {
5238 default: NOT_REACHED();
5239 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
5240 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
5241 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
5251 adjust.variable = buf->ReadByte();
5252 if (adjust.variable == 0x7E) {
5254 adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
5259 varadjust = buf->ReadByte();
5260 adjust.shift_num =
GB(varadjust, 0, 5);
5261 adjust.type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
5262 adjust.and_mask = buf->ReadVarSize(varsize);
5264 if (adjust.type != DSGA_TYPE_NONE) {
5265 adjust.add_val = buf->ReadVarSize(varsize);
5266 adjust.divmod_val = buf->ReadVarSize(varsize);
5269 adjust.divmod_val = 0;
5273 }
while (
HasBit(varadjust, 5));
5275 std::vector<DeterministicSpriteGroupRange> ranges;
5276 ranges.resize(buf->ReadByte());
5277 for (uint i = 0; i < ranges.size(); i++) {
5278 ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5279 ranges[i].low = buf->ReadVarSize(varsize);
5280 ranges[i].high = buf->ReadVarSize(varsize);
5283 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5284 group->error_group = ranges.empty() ? group->default_group : ranges[0].group;
5286 group->calculated_result = ranges.empty();
5289 std::vector<uint32_t> bounds;
5290 for (uint i = 0; i < ranges.size(); i++) {
5291 bounds.push_back(ranges[i].low);
5292 if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1);
5294 std::sort(bounds.begin(), bounds.end());
5295 bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
5297 std::vector<const SpriteGroup *> target;
5298 for (uint j = 0; j < bounds.size(); ++j) {
5299 uint32_t v = bounds[j];
5301 for (uint i = 0; i < ranges.size(); i++) {
5302 if (ranges[i].low <= v && v <= ranges[i].high) {
5303 t = ranges[i].group;
5307 target.push_back(t);
5309 assert(target.size() == bounds.size());
5311 for (uint j = 0; j < bounds.size(); ) {
5312 if (target[j] != group->default_group) {
5314 r.group = target[j];
5316 while (j < bounds.size() && target[j] == r.group) {
5319 r.high = j < bounds.size() ? bounds[j] - 1 : UINT32_MAX;
5341 group->count = buf->ReadByte();
5344 uint8_t triggers = buf->ReadByte();
5345 group->triggers =
GB(triggers, 0, 7);
5346 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
5349 byte num_groups = buf->ReadByte();
5351 GrfMsg(1,
"NewSpriteGroup: Random Action 2 nrand should be power of 2");
5354 for (uint i = 0; i < num_groups; i++) {
5355 group->
groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
5366 case GSF_ROADVEHICLES:
5377 byte num_loaded = type;
5378 byte num_loading = buf->ReadByte();
5381 GrfMsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
5385 GrfMsg(6,
"NewSpriteGroup: New SpriteGroup 0x{:02X}, {} loaded, {} loading",
5386 setid, num_loaded, num_loading);
5388 if (num_loaded + num_loading == 0) {
5389 GrfMsg(1,
"NewSpriteGroup: no result, skipping invalid RealSpriteGroup");
5393 if (num_loaded + num_loading == 1) {
5395 uint16_t spriteid = buf->ReadWord();
5397 GrfMsg(8,
"NewSpriteGroup: one result, skipping RealSpriteGroup = subset {}", spriteid);
5401 std::vector<uint16_t> loaded;
5402 std::vector<uint16_t> loading;
5404 for (uint i = 0; i < num_loaded; i++) {
5405 loaded.push_back(buf->ReadWord());
5406 GrfMsg(8,
"NewSpriteGroup: + rg->loaded[{}] = subset {}", i, loaded[i]);
5409 for (uint i = 0; i < num_loading; i++) {
5410 loading.push_back(buf->ReadWord());
5411 GrfMsg(8,
"NewSpriteGroup: + rg->loading[{}] = subset {}", i, loading[i]);
5414 if (std::adjacent_find(loaded.begin(), loaded.end(), std::not_equal_to<>()) == loaded.end() &&
5415 std::adjacent_find(loading.begin(), loading.end(), std::not_equal_to<>()) == loading.end() &&
5416 loaded[0] == loading[0])
5420 GrfMsg(8,
"NewSpriteGroup: same result, skipping RealSpriteGroup = subset {}", loaded[0]);
5429 for (uint16_t spriteid : loaded) {
5431 group->
loaded.push_back(t);
5434 for (uint16_t spriteid : loading) {
5443 case GSF_AIRPORTTILES:
5445 case GSF_INDUSTRYTILES:
5446 case GSF_ROADSTOPS: {
5447 byte num_building_sprites = std::max((uint8_t)1, type);
5455 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
5459 case GSF_INDUSTRIES: {
5461 GrfMsg(1,
"NewSpriteGroup: Unsupported industry production version {}, skipping", type);
5472 for (uint i = 0; i < 3; i++) {
5476 for (uint i = 0; i < 2; i++) {
5479 group->again = buf->ReadByte();
5480 }
else if (type == 1) {
5482 for (uint i = 0; i < 3; i++) {
5486 for (uint i = 0; i < 2; i++) {
5489 group->again = buf->ReadByte();
5490 }
else if (type == 2) {
5494 error->
data =
"too many inputs (max 16)";
5497 for (uint i = 0; i < group->
num_input; i++) {
5498 byte rawcargo = buf->ReadByte();
5507 error->
data =
"duplicate input cargo";
5516 error->
data =
"too many outputs (max 16)";
5519 for (uint i = 0; i < group->
num_output; i++) {
5520 byte rawcargo = buf->ReadByte();
5527 error->
data =
"duplicate output cargo";
5533 group->again = buf->ReadByte();
5541 default: GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5546 _cur.spritegroups[setid] = act_group;
5549 static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
5558 GrfMsg(1,
"TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
5559 return INVALID_CARGO;
5563 if (cs->bitnum == ctype) {
5564 GrfMsg(6,
"TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index());
5569 GrfMsg(5,
"TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype);
5570 return INVALID_CARGO;
5575 GrfMsg(1,
"TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (
unsigned int)_cur.
grffile->
cargo_list.size() - 1);
5576 return INVALID_CARGO;
5582 GrfMsg(5,
"TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
5583 return INVALID_CARGO;
5586 CargoID cid = GetCargoIDByLabel(cl);
5588 GrfMsg(5,
"TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' unsupported, skipping.",
GB(cl.base(), 24, 8),
GB(cl.base(), 16, 8),
GB(cl.base(), 8, 8),
GB(cl.base(), 0, 8));
5589 return INVALID_CARGO;
5592 GrfMsg(6,
"TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' mapped to cargo type {}.",
GB(cl.base(), 24, 8),
GB(cl.base(), 16, 8),
GB(cl.base(), 8, 8),
GB(cl.base(), 0, 8), cid);
5597 static bool IsValidGroupID(uint16_t groupid,
const char *
function)
5599 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5600 GrfMsg(1,
"{}: Spritegroup 0x{:04X} out of range or empty, skipping.",
function, groupid);
5607 static void VehicleMapSpriteGroup(
ByteReader *buf,
byte feature, uint8_t idcount)
5610 static uint last_engines_count;
5611 bool wagover =
false;
5614 if (
HasBit(idcount, 7)) {
5617 idcount =
GB(idcount, 0, 7);
5619 if (last_engines_count == 0) {
5620 GrfMsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
5624 GrfMsg(6,
"VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons",
5625 last_engines_count, idcount);
5627 if (last_engines_count != idcount) {
5628 last_engines =
ReallocT(last_engines, idcount);
5629 last_engines_count = idcount;
5633 std::vector<EngineID> engines;
5634 for (uint i = 0; i < idcount; i++) {
5640 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
5644 engines.push_back(e->
index);
5645 if (!wagover) last_engines[i] = engines[i];
5648 uint8_t cidcount = buf->ReadByte();
5649 for (uint c = 0; c < cidcount; c++) {
5650 uint8_t ctype = buf->ReadByte();
5651 uint16_t groupid = buf->ReadWord();
5652 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
5654 GrfMsg(8,
"VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
5656 CargoID cid = TranslateCargo(feature, ctype);
5659 for (uint i = 0; i < idcount; i++) {
5662 GrfMsg(7,
"VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
5665 SetWagonOverrideSprites(engine, cid, _cur.spritegroups[groupid], last_engines, last_engines_count);
5667 SetCustomEngineSprites(engine, cid, _cur.spritegroups[groupid]);
5672 uint16_t groupid = buf->ReadWord();
5673 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
5675 GrfMsg(8,
"-- Default group id 0x{:04X}", groupid);
5677 for (uint i = 0; i < idcount; i++) {
5690 static void CanalMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5692 std::vector<uint16_t> cfs;
5693 cfs.reserve(idcount);
5694 for (uint i = 0; i < idcount; i++) {
5695 cfs.push_back(buf->ReadExtendedByte());
5698 uint8_t cidcount = buf->ReadByte();
5699 buf->Skip(cidcount * 3);
5701 uint16_t groupid = buf->ReadWord();
5702 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
5704 for (
auto &cf : cfs) {
5706 GrfMsg(1,
"CanalMapSpriteGroup: Canal subset {} out of range, skipping", cf);
5716 static void StationMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5718 if (_cur.
grffile->stations.empty()) {
5719 GrfMsg(1,
"StationMapSpriteGroup: No stations defined, skipping");
5723 std::vector<uint16_t> stations;
5724 stations.reserve(idcount);
5725 for (uint i = 0; i < idcount; i++) {
5726 stations.push_back(buf->ReadExtendedByte());
5729 uint8_t cidcount = buf->ReadByte();
5730 for (uint c = 0; c < cidcount; c++) {
5731 uint8_t ctype = buf->ReadByte();
5732 uint16_t groupid = buf->ReadWord();
5733 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5735 ctype = TranslateCargo(GSF_STATIONS, ctype);
5738 for (
auto &station : stations) {
5741 if (statspec ==
nullptr) {
5742 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5750 uint16_t groupid = buf->ReadWord();
5751 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5753 for (
auto &station : stations) {
5756 if (statspec ==
nullptr) {
5757 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5762 GrfMsg(1,
"StationMapSpriteGroup: Station {} mapped multiple times, skipping", station);
5769 StationClass::Assign(statspec);
5774 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5776 if (_cur.
grffile->housespec.empty()) {
5777 GrfMsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5781 std::vector<uint16_t> houses;
5782 houses.reserve(idcount);
5783 for (uint i = 0; i < idcount; i++) {
5784 houses.push_back(buf->ReadExtendedByte());
5788 uint8_t cidcount = buf->ReadByte();
5789 buf->Skip(cidcount * 3);
5791 uint16_t groupid = buf->ReadWord();
5792 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5794 for (
auto &house : houses) {
5797 if (hs ==
nullptr) {
5798 GrfMsg(1,
"TownHouseMapSpriteGroup: House {} undefined, skipping.", house);
5806 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5808 if (_cur.
grffile->industryspec.empty()) {
5809 GrfMsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5813 std::vector<uint16_t> industries;
5814 industries.reserve(idcount);
5815 for (uint i = 0; i < idcount; i++) {
5816 industries.push_back(buf->ReadExtendedByte());
5820 uint8_t cidcount = buf->ReadByte();
5821 buf->Skip(cidcount * 3);
5823 uint16_t groupid = buf->ReadWord();
5824 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5826 for (
auto &industry : industries) {
5829 if (indsp ==
nullptr) {
5830 GrfMsg(1,
"IndustryMapSpriteGroup: Industry {} undefined, skipping", industry);
5838 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5840 if (_cur.
grffile->indtspec.empty()) {
5841 GrfMsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5845 std::vector<uint16_t> indtiles;
5846 indtiles.reserve(idcount);
5847 for (uint i = 0; i < idcount; i++) {
5848 indtiles.push_back(buf->ReadExtendedByte());
5852 uint8_t cidcount = buf->ReadByte();
5853 buf->Skip(cidcount * 3);
5855 uint16_t groupid = buf->ReadWord();
5856 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5858 for (
auto &indtile : indtiles) {
5861 if (indtsp ==
nullptr) {
5862 GrfMsg(1,
"IndustrytileMapSpriteGroup: Industry tile {} undefined, skipping", indtile);
5870 static void CargoMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5872 std::vector<uint16_t> cargoes;
5873 cargoes.reserve(idcount);
5874 for (uint i = 0; i < idcount; i++) {
5875 cargoes.push_back(buf->ReadExtendedByte());
5879 uint8_t cidcount = buf->ReadByte();
5880 buf->Skip(cidcount * 3);
5882 uint16_t groupid = buf->ReadWord();
5883 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5885 for (
auto &cid : cargoes) {
5887 GrfMsg(1,
"CargoMapSpriteGroup: Cargo ID {} out of range, skipping", cid);
5893 cs->group = _cur.spritegroups[groupid];
5897 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5899 if (_cur.
grffile->objectspec.empty()) {
5900 GrfMsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5904 std::vector<uint16_t> objects;
5905 objects.reserve(idcount);
5906 for (uint i = 0; i < idcount; i++) {
5907 objects.push_back(buf->ReadExtendedByte());
5910 uint8_t cidcount = buf->ReadByte();
5911 for (uint c = 0; c < cidcount; c++) {
5912 uint8_t ctype = buf->ReadByte();
5913 uint16_t groupid = buf->ReadWord();
5914 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5917 if (ctype != 0xFF) {
5918 GrfMsg(1,
"ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype);
5922 for (
auto &
object : objects) {
5925 if (spec ==
nullptr) {
5926 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5934 uint16_t groupid = buf->ReadWord();
5935 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5937 for (
auto &
object : objects) {
5940 if (spec ==
nullptr) {
5941 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5946 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} mapped multiple times, skipping",
object);
5956 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5958 std::vector<uint8_t> railtypes;
5959 railtypes.reserve(idcount);
5960 for (uint i = 0; i < idcount; i++) {
5961 uint16_t
id = buf->ReadExtendedByte();
5962 railtypes.push_back(id < RAILTYPE_END ? _cur.grffile->railtype_map[
id] :
INVALID_RAILTYPE);
5965 uint8_t cidcount = buf->ReadByte();
5966 for (uint c = 0; c < cidcount; c++) {
5967 uint8_t ctype = buf->ReadByte();
5968 uint16_t groupid = buf->ReadWord();
5969 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5971 if (ctype >= RTSG_END)
continue;
5974 for (
auto &railtype : railtypes) {
5979 rti->
group[ctype] = _cur.spritegroups[groupid];
5988 static void RoadTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount, RoadTramType rtt)
5992 std::vector<uint8_t> roadtypes;
5993 roadtypes.reserve(idcount);
5994 for (uint i = 0; i < idcount; i++) {
5995 uint16_t
id = buf->ReadExtendedByte();
5999 uint8_t cidcount = buf->ReadByte();
6000 for (uint c = 0; c < cidcount; c++) {
6001 uint8_t ctype = buf->ReadByte();
6002 uint16_t groupid = buf->ReadWord();
6003 if (!IsValidGroupID(groupid,
"RoadTypeMapSpriteGroup"))
continue;
6005 if (ctype >= ROTSG_END)
continue;
6008 for (
auto &roadtype : roadtypes) {
6013 rti->
group[ctype] = _cur.spritegroups[groupid];
6022 static void AirportMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6024 if (_cur.
grffile->airportspec.empty()) {
6025 GrfMsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
6029 std::vector<uint16_t> airports;
6030 airports.reserve(idcount);
6031 for (uint i = 0; i < idcount; i++) {
6032 airports.push_back(buf->ReadExtendedByte());
6036 uint8_t cidcount = buf->ReadByte();
6037 buf->Skip(cidcount * 3);
6039 uint16_t groupid = buf->ReadWord();
6040 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
6042 for (
auto &airport : airports) {
6045 if (as ==
nullptr) {
6046 GrfMsg(1,
"AirportMapSpriteGroup: Airport {} undefined, skipping", airport);
6054 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6056 if (_cur.
grffile->airtspec.empty()) {
6057 GrfMsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
6061 std::vector<uint16_t> airptiles;
6062 airptiles.reserve(idcount);
6063 for (uint i = 0; i < idcount; i++) {
6064 airptiles.push_back(buf->ReadExtendedByte());
6068 uint8_t cidcount = buf->ReadByte();
6069 buf->Skip(cidcount * 3);
6071 uint16_t groupid = buf->ReadWord();
6072 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
6074 for (
auto &airptile : airptiles) {
6077 if (airtsp ==
nullptr) {
6078 GrfMsg(1,
"AirportTileMapSpriteGroup: Airport tile {} undefined, skipping", airptile);
6086 static void RoadStopMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6088 if (_cur.
grffile->roadstops.empty()) {
6089 GrfMsg(1,
"RoadStopMapSpriteGroup: No roadstops defined, skipping");
6093 std::vector<uint16_t> roadstops;
6094 roadstops.reserve(idcount);
6095 for (uint i = 0; i < idcount; i++) {
6096 roadstops.push_back(buf->ReadExtendedByte());
6099 uint8_t cidcount = buf->ReadByte();
6100 for (uint c = 0; c < cidcount; c++) {
6101 uint8_t ctype = buf->ReadByte();
6102 uint16_t groupid = buf->ReadWord();
6103 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
continue;
6105 ctype = TranslateCargo(GSF_ROADSTOPS, ctype);
6108 for (
auto &roadstop : roadstops) {
6111 if (roadstopspec ==
nullptr) {
6112 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping", roadstop);
6120 uint16_t groupid = buf->ReadWord();
6121 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
return;
6123 for (
auto &roadstop : roadstops) {
6126 if (roadstopspec ==
nullptr) {
6127 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping.", roadstop);
6132 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} mapped multiple times, skipping", roadstop);
6139 RoadStopClass::Assign(roadstopspec);
6144 static void FeatureMapSpriteGroup(
ByteReader *buf)
6160 uint8_t feature = buf->ReadByte();
6161 uint8_t idcount = buf->ReadByte();
6163 if (feature >= GSF_END) {
6164 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6172 uint16_t groupid = buf->ReadWord();
6173 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
6175 GrfMsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature 0x{:02X}", feature);
6184 GrfMsg(6,
"FeatureMapSpriteGroup: Feature 0x{:02X}, {} ids", feature, idcount);
6188 case GSF_ROADVEHICLES:
6191 VehicleMapSpriteGroup(buf, feature, idcount);
6195 CanalMapSpriteGroup(buf, idcount);
6199 StationMapSpriteGroup(buf, idcount);
6203 TownHouseMapSpriteGroup(buf, idcount);
6206 case GSF_INDUSTRIES:
6207 IndustryMapSpriteGroup(buf, idcount);
6210 case GSF_INDUSTRYTILES:
6211 IndustrytileMapSpriteGroup(buf, idcount);
6215 CargoMapSpriteGroup(buf, idcount);
6219 AirportMapSpriteGroup(buf, idcount);
6223 ObjectMapSpriteGroup(buf, idcount);
6227 RailTypeMapSpriteGroup(buf, idcount);
6231 RoadTypeMapSpriteGroup(buf, idcount, RTT_ROAD);
6235 RoadTypeMapSpriteGroup(buf, idcount, RTT_TRAM);
6238 case GSF_AIRPORTTILES:
6239 AirportTileMapSpriteGroup(buf, idcount);
6243 RoadStopMapSpriteGroup(buf, idcount);
6247 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6271 bool new_scheme = _cur.
grffile->grf_version >= 7;
6273 uint8_t feature = buf->ReadByte();
6274 if (feature >= GSF_END && feature != 0x48) {
6275 GrfMsg(1,
"FeatureNewName: Unsupported feature 0x{:02X}, skipping", feature);
6279 uint8_t lang = buf->ReadByte();
6280 uint8_t num = buf->ReadByte();
6281 bool generic =
HasBit(lang, 7);
6284 id = buf->ReadWord();
6285 }
else if (feature <= GSF_AIRCRAFT) {
6286 id = buf->ReadExtendedByte();
6288 id = buf->ReadByte();
6293 uint16_t endid =
id + num;
6295 GrfMsg(6,
"FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
6296 id, endid, feature, lang);
6298 for (;
id < endid && buf->HasData();
id++) {
6299 const char *name = buf->ReadString();
6300 GrfMsg(8,
"FeatureNewName: 0x{:04X} <- {}",
id, name);
6304 case GSF_ROADVEHICLES:
6309 if (e ==
nullptr)
break;
6323 switch (
GB(
id, 8, 8)) {
6325 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6326 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6334 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6335 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6342 if (
GB(
id, 0, 8) >= _cur.
grffile->airtspec.size() || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
6343 GrfMsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring",
GB(
id, 0, 8));
6350 if (
GB(
id, 0, 8) >= _cur.
grffile->housespec.size() || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
6351 GrfMsg(1,
"FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.",
GB(
id, 0, 8));
6353 _cur.
grffile->housespec[
GB(
id, 0, 8)]->building_name =
AddGRFString(_cur.
grffile->grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6358 GrfMsg(7,
"FeatureNewName: Unsupported ID (0x{:04X})",
id);
6377 if (offset >= max_sprites) {
6378 GrfMsg(1,
"GraphicsNew: {} sprite offset must be less than {}, skipping", name, max_sprites);
6379 uint orig_num = num;
6384 if (offset + num > max_sprites) {
6385 GrfMsg(4,
"GraphicsNew: {} sprite overflow, truncating...", name);
6386 uint orig_num = num;
6387 num = std::max(max_sprites - offset, 0);
6388 return orig_num - num;
6417 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
6419 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
6449 uint8_t type = buf->ReadByte();
6450 uint16_t num = buf->ReadExtendedByte();
6451 uint16_t offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
6457 GrfMsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
6474 GrfMsg(2,
"GraphicsNew: Custom graphics (type 0x{:02X}) sprite block of length {} (unimplemented, ignoring)", type, num);
6485 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
6492 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) count must be at least {}. Only {} were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
6502 GrfMsg(2,
"GraphicsNew: Replacing sprites {} to {} of {} (type 0x{:02X}) at SpriteID 0x{:04X}", offset, offset + num - 1, action5_type->
name, type, replace);
6514 bool dup_oneway_sprites = ((type == 0x09) && (offset + num <= SPR_ONEWAY_SLOPE_N_OFFSET));
6516 for (; num > 0; num--) {
6518 int load_index = (replace == 0 ? _cur.
spriteid++ : replace++);
6520 if (dup_oneway_sprites) {
6521 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
6522 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_S_OFFSET);
6538 GrfMsg(3,
"SkipAct5: Skipping {} sprites", _cur.
skip_sprites);
6591 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
6621 *value = _game_mode;
6655 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
6664 *value = _openttd_newgrf_version;
6679 default:
return false;
6683 static uint32_t GetParamVal(
byte param, uint32_t *cond_val)
6702 if (cond_val ==
nullptr) {
6706 uint32_t index = *cond_val / 0x20;
6722 GrfMsg(1,
"Unsupported in-game variable 0x{:02X}", param);
6743 size_t pos = file.
GetPos();
6749 GrfMsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
6752 file.
SeekTo(pos, SEEK_SET);
6758 std::vector<byte> &preload_sprite = _grf_line_to_action6_sprite_override[location];
6761 if (preload_sprite.empty()) {
6762 preload_sprite.resize(num);
6763 file.
ReadBlock(preload_sprite.data(), num);
6767 file.
SeekTo(pos, SEEK_SET);
6778 param_num = buf->ReadByte();
6779 if (param_num == 0xFF)
break;
6783 param_size = buf->ReadByte();
6787 add_value =
HasBit(param_size, 7);
6788 param_size =
GB(param_size, 0, 7);
6791 offset = buf->ReadExtendedByte();
6795 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
6796 GrfMsg(2,
"CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4));
6800 GrfMsg(8,
"CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset);
6803 for (i = 0; i < param_size && offset + i < num; i++) {
6804 uint32_t value = GetParamVal(param_num + i / 4,
nullptr);
6807 if (i % 4 == 0) carry =
false;
6810 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
6811 preload_sprite[offset + i] =
GB(new_value, 0, 8);
6813 carry = new_value >= 256;
6815 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6847 uint32_t cond_val = 0;
6851 uint8_t param = buf->ReadByte();
6852 uint8_t paramsize = buf->ReadByte();
6853 uint8_t condtype = buf->ReadByte();
6860 switch (paramsize) {
6861 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6862 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6863 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6864 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6868 if (param < 0x80 && _cur.grffile->param_end <= param) {
6869 GrfMsg(7,
"SkipIf: Param {} undefined, skipping test", param);
6873 GrfMsg(7,
"SkipIf: Test condtype {}, param 0x{:02X}, condval 0x{:08X}", condtype, param, cond_val);
6878 if (condtype >= 0x0B) {
6909 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6911 }
else if (param == 0x88) {
6921 if (condtype != 10 && c ==
nullptr) {
6922 GrfMsg(7,
"SkipIf: GRFID 0x{:08X} unknown, skipping test",
BSWAP32(cond_val));
6949 default: GrfMsg(1,
"SkipIf: Unsupported GRF condition type {:02X}. Ignoring", condtype);
return;
6953 uint32_t param_val = GetParamVal(param, &cond_val);
6955 case 0x00: result = !!(param_val & (1 << cond_val));
6957 case 0x01: result = !(param_val & (1 << cond_val));
6959 case 0x02: result = (param_val & mask) == cond_val;
6961 case 0x03: result = (param_val & mask) != cond_val;
6963 case 0x04: result = (param_val & mask) < cond_val;
6965 case 0x05: result = (param_val & mask) > cond_val;
6967 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6972 GrfMsg(2,
"SkipIf: Not skipping sprites, test was false");
6976 uint8_t numsprites = buf->ReadByte();
6984 if (label.label != numsprites)
continue;
6987 if (choice ==
nullptr) choice = &label;
6989 if (label.nfo_line > _cur.
nfo_line) {
6995 if (choice !=
nullptr) {
6996 GrfMsg(2,
"SkipIf: Jumping to label 0x{:X} at line {}, test was true", choice->label, choice->nfo_line);
7002 GrfMsg(2,
"SkipIf: Skipping {} sprites, test was true", numsprites);
7021 uint8_t grf_version = buf->ReadByte();
7022 uint32_t grfid = buf->ReadDWord();
7023 const char *name = buf->ReadString();
7027 if (grf_version < 2 || grf_version > 8) {
7029 Debug(grf, 0,
"{}: NewGRF \"{}\" (GRFID {:08X}) uses GRF version {}, which is incompatible with this version of OpenTTD.", _cur.
grfconfig->
filename, name,
BSWAP32(grfid), grf_version);
7037 if (buf->HasData()) {
7038 const char *info = buf->ReadString();
7056 uint8_t version = buf->ReadByte();
7057 uint32_t grfid = buf->ReadDWord();
7058 const char *name = buf->ReadString();
7061 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
7065 if (_cur.
grffile->grfid != grfid) {
7066 Debug(grf, 0,
"GRFInfo: GRFID {:08X} in FILESCAN stage does not match GRFID {:08X} in INIT/RESERVE/ACTIVATION stage",
BSWAP32(_cur.
grffile->grfid),
BSWAP32(grfid));
7070 _cur.
grffile->grf_version = version;
7088 uint8_t num_sets = buf->ReadByte();
7090 for (uint i = 0; i < num_sets; i++) {
7091 uint8_t num_sprites = buf->ReadByte();
7092 uint16_t first_sprite = buf->ReadWord();
7094 GrfMsg(2,
"SpriteReplace: [Set {}] Changing {} sprites, beginning with {}",
7095 i, num_sprites, first_sprite
7098 for (uint j = 0; j < num_sprites; j++) {
7099 int load_index = first_sprite + j;
7105 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
7115 uint8_t num_sets = buf->ReadByte();
7117 for (uint i = 0; i < num_sets; i++) {
7124 GrfMsg(3,
"SkipActA: Skipping {} sprites", _cur.
skip_sprites);
7146 STR_NEWGRF_ERROR_VERSION_NUMBER,
7147 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
7148 STR_NEWGRF_ERROR_UNSET_SWITCH,
7149 STR_NEWGRF_ERROR_INVALID_PARAMETER,
7150 STR_NEWGRF_ERROR_LOAD_BEFORE,
7151 STR_NEWGRF_ERROR_LOAD_AFTER,
7152 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
7156 STR_NEWGRF_ERROR_MSG_INFO,
7157 STR_NEWGRF_ERROR_MSG_WARNING,
7158 STR_NEWGRF_ERROR_MSG_ERROR,
7159 STR_NEWGRF_ERROR_MSG_FATAL
7162 byte severity = buf->ReadByte();
7163 byte lang = buf->ReadByte();
7164 byte message_id = buf->ReadByte();
7167 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
7171 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
7172 GrfMsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage {}", _cur.
stage);
7177 if (severity >=
lengthof(sevstr)) {
7178 GrfMsg(7,
"GRFLoadError: Invalid severity id {}. Setting to 2 (non-fatal error).", severity);
7180 }
else if (severity == 3) {
7189 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
7190 GrfMsg(7,
"GRFLoadError: Invalid message id.");
7194 if (buf->Remaining() <= 1) {
7195 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7205 if (message_id == 0xFF) {
7207 if (buf->HasData()) {
7208 const char *message = buf->ReadString();
7212 GrfMsg(7,
"GRFLoadError: No custom message supplied.");
7216 error->
message = msgstr[message_id];
7219 if (buf->HasData()) {
7220 const char *data = buf->ReadString();
7224 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7225 error->
data.clear();
7229 for (uint i = 0; i < error->
param_value.size() && buf->HasData(); i++) {
7230 uint param_number = buf->ReadByte();
7242 if (!buf->HasData())
return;
7244 const char *text = buf->ReadString();
7245 GrfMsg(2,
"GRFComment: {}", text);
7251 uint8_t target = buf->ReadByte();
7254 if (target < 0x80 || target == 0x9E)
return;
7268 static uint32_t GetPatchVariable(uint8_t param)
7278 case 0x0F:
return 0;
7294 case 0x11:
return SPR_2CCMAP_BASE;
7311 byte max_edge = std::max(log_X, log_Y);
7313 if (log_X == log_Y) {
7316 if (max_edge == log_Y)
SetBit(map_bits, 1);
7319 return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
7320 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
7329 return SPR_SLOPES_BASE;
7340 GrfMsg(2,
"ParamSet: Unknown Patch variable 0x{:02X}.", param);
7346 static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint8_t op, uint8_t target,
const char *type)
7359 for (uint i = start; i < num_ids; i++) {
7363 if (op == 2 || op == 3)
break;
7368 if (size == count)
break;
7371 if (size == count) {
7373 if (op == 0 || op == 3) {
7374 GrfMsg(2,
"ParamSet: GRM: Reserving {} {} at {}", count, type, start);
7375 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
7381 if (op != 4 && op != 5) {
7383 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type);
7388 GrfMsg(1,
"ParamSet: GRM: Unable to allocate {} {}", count, type);
7418 uint8_t target = buf->ReadByte();
7419 uint8_t oper = buf->ReadByte();
7420 uint32_t src1 = buf->ReadByte();
7421 uint32_t src2 = buf->ReadByte();
7424 if (buf->Remaining() >= 4) data = buf->ReadDWord();
7433 if (target < 0x80 && target < _cur.grffile->param_end) {
7434 GrfMsg(7,
"ParamSet: Param {} already defined, skipping", target);
7438 oper =
GB(oper, 0, 7);
7442 if (
GB(data, 0, 8) == 0xFF) {
7443 if (data == 0x0000FFFF) {
7445 src1 = GetPatchVariable(src1);
7449 uint8_t feature =
GB(data, 8, 8);
7450 uint16_t count =
GB(data, 16, 16);
7452 if (_cur.
stage == GLS_RESERVE) {
7453 if (feature == 0x08) {
7457 if (_cur.
spriteid + count >= 16384) {
7458 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count);
7464 GrfMsg(4,
"ParamSet: GRM: Allocated {} sprites at {}", count, _cur.
spriteid);
7471 }
else if (_cur.
stage == GLS_ACTIVATION) {
7500 GrfMsg(4,
"ParamSet: GRM: Using pre-allocated sprites at {}", src1);
7508 GrfMsg(1,
"ParamSet: GRM: Unsupported operation {} for general sprites", op);
7519 default: GrfMsg(1,
"ParamSet: GRM: Unsupported feature 0x{:X}", feature);
return;
7536 }
else if (src1 == 0xFE) {
7548 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
7549 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
7571 res = (int32_t)src1 * (int32_t)src2;
7575 if ((int32_t)src2 < 0) {
7576 res = src1 >> -(int32_t)src2;
7578 res = src1 << (src2 & 0x1F);
7583 if ((int32_t)src2 < 0) {
7584 res = (int32_t)src1 >> -(int32_t)src2;
7586 res = (int32_t)src1 << (src2 & 0x1F);
7610 res = (int32_t)src1 / (int32_t)src2;
7626 res = (int32_t)src1 % (int32_t)src2;
7630 default: GrfMsg(0,
"ParamSet: Unknown operation {}, skipping", oper);
return;
7659 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7670 uint32_t safe_bits = 0;
7671 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
7680 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7684 if (target < 0x80) {
7685 _cur.
grffile->param[target] = res;
7689 GrfMsg(7,
"ParamSet: Skipping unknown target 0x{:02X}", target);
7703 uint8_t num = buf->ReadByte();
7705 for (uint i = 0; i < num; i++) {
7706 uint32_t grfid = buf->ReadDWord();
7728 uint8_t num = buf->ReadByte();
7730 for (uint i = 0; i < num; i++) {
7731 uint32_t grfid = buf->ReadDWord();
7735 if (file !=
nullptr && file != _cur.
grfconfig) {
7736 GrfMsg(2,
"GRFInhibit: Deactivating file '{}'", file->
filename);
7753 uint32_t grfid = _cur.
grffile->grfid;
7757 byte id = buf->ReadByte();
7758 GrfMsg(6,
"FeatureTownName: definition 0x{:02X}",
id & 0x7F);
7763 bool new_scheme = _cur.
grffile->grf_version >= 7;
7765 byte lang = buf->ReadByte();
7771 const char *name = buf->ReadString();
7774 GrfMsg(6,
"FeatureTownName: lang 0x{:X} -> '{}'", lang, lang_name);
7776 style =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
7778 lang = buf->ReadByte();
7779 }
while (lang != 0);
7780 townname->
styles.emplace_back(style,
id);
7783 uint8_t parts = buf->ReadByte();
7784 GrfMsg(6,
"FeatureTownName: {} parts", parts);
7787 for (uint partnum = 0; partnum < parts; partnum++) {
7789 uint8_t texts = buf->ReadByte();
7790 partlist.
bitstart = buf->ReadByte();
7791 partlist.
bitcount = buf->ReadByte();
7793 GrfMsg(6,
"FeatureTownName: part {} contains {} texts and will use GB(seed, {}, {})", partnum, texts, partlist.
bitstart, partlist.
bitcount);
7795 partlist.
parts.reserve(texts);
7796 for (uint textnum = 0; textnum < texts; textnum++) {
7798 part.
prob = buf->ReadByte();
7801 byte ref_id = buf->ReadByte();
7803 GrfMsg(0,
"FeatureTownName: definition 0x{:02X} doesn't exist, deactivating", ref_id);
7804 DelGRFTownName(grfid);
7809 GrfMsg(6,
"FeatureTownName: part {}, text {}, uses intermediate definition 0x{:02X} (with probability {})", partnum, textnum, ref_id, part.
prob & 0x7F);
7811 const char *text = buf->ReadString();
7813 GrfMsg(6,
"FeatureTownName: part {}, text {}, '{}' (with probability {})", partnum, textnum, part.
text, part.
prob);
7817 GrfMsg(6,
"FeatureTownName: part {}, total probability {}", partnum, partlist.
maxprob);
7829 byte nfo_label = buf->ReadByte();
7833 GrfMsg(2,
"DefineGotoLabel: GOTO target with label 0x{:02X}", nfo_label);
7847 if (file ==
nullptr || file->sound_offset == 0) {
7848 GrfMsg(1,
"ImportGRFSound: Source file not available");
7852 if (sound_id >= file->num_sounds) {
7853 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
7857 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid);
7859 *sound = *GetSound(file->sound_offset + sound_id);
7862 sound->volume = 128;
7863 sound->priority = 0;
7874 sound->volume = 0x80;
7875 sound->priority = 0;
7877 if (offs != SIZE_MAX) {
7879 sound->file = _cur.
file;
7880 sound->file_offset = offs;
7892 uint16_t num = buf->ReadWord();
7893 if (num == 0)
return;
7896 if (_cur.
grffile->sound_offset == 0) {
7897 _cur.
grffile->sound_offset = GetNumSounds();
7898 _cur.
grffile->num_sounds = num;
7901 sound = GetSound(_cur.
grffile->sound_offset);
7906 for (
int i = 0; i < num; i++) {
7911 bool invalid = i >= _cur.
grffile->num_sounds;
7913 size_t offs = file.
GetPos();
7918 if (grf_container_version >= 2 && type == 0xFD) {
7921 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7923 }
else if (len != 4) {
7924 GrfMsg(1,
"GRFSound: Invalid sprite section import");
7934 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7941 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7949 if (_cur.
stage == GLS_INIT) {
7950 if (grf_container_version >= 2) {
7951 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7960 if (_cur.
stage == GLS_ACTIVATION) {
7963 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
7971 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
7987 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur.
skip_sprites);
8000 uint8_t num_def = buf->ReadByte();
8002 for (uint i = 0; i < num_def; i++) {
8004 uint8_t num_char = buf->ReadByte();
8005 uint16_t base_char = buf->ReadWord();
8007 if (size >= FS_END) {
8008 GrfMsg(1,
"LoadFontGlyph: Size {} is not supported, ignoring", size);
8011 GrfMsg(7,
"LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
8013 for (uint c = 0; c < num_char; c++) {
8031 uint8_t num_def = buf->ReadByte();
8033 for (uint i = 0; i < num_def; i++) {
8044 GrfMsg(3,
"SkipAct12: Skipping {} sprites", _cur.
skip_sprites);
8057 uint32_t grfid = buf->ReadDWord();
8060 GrfMsg(7,
"TranslateGRFStrings: GRFID 0x{:08X} unknown, skipping action 13",
BSWAP32(grfid));
8069 error->
data =
GetString(STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE);
8079 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
8080 byte num_strings = buf->ReadByte();
8081 uint16_t first_id = buf->ReadWord();
8083 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
8084 GrfMsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x{:04X}, number: 0x{:02X})", first_id, num_strings);
8088 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
8089 const char *
string = buf->ReadString();
8092 GrfMsg(7,
"TranslateGRFString: Ignoring empty string.");
8096 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
8125 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got {}, ignoring this field", len);
8137 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got {}, ignoring this field", len);
8140 char data = buf->ReadByte();
8148 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'PALS', ignoring this field", data);
8163 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got {}, ignoring this field", len);
8166 char data = buf->ReadByte();
8172 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'BLTR', ignoring this field", data);
8185 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got {}, ignoring this field", len);
8198 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got {}, ignoring this field", len);
8203 GrfMsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
8234 GrfMsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got {}, ignoring this field", len);
8241 GrfMsg(3,
"StaticGRFInfo: unknown parameter type {}, ignoring this field", type);
8251 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
8253 }
else if (len != 8) {
8254 GrfMsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got {}, ignoring this field", len);
8257 uint32_t min_value = buf->ReadDWord();
8258 uint32_t max_value = buf->ReadDWord();
8259 if (min_value <= max_value) {
8263 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field");
8272 if (len < 1 || len > 3) {
8273 GrfMsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got {}, ignoring this field", len);
8276 byte param_nr = buf->ReadByte();
8278 GrfMsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param {}, ignoring this field", param_nr);
8294 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got {}, ignoring this field", len);
8330 this->handler.data = handler;
8342 this->handler.text = handler;
8354 this->handler.call_handler =
true;
8355 this->handler.u.branch = handler;
8367 this->handler.call_handler =
false;
8368 this->handler.u.subtags =
subtags;
8397 byte type = buf->ReadByte();
8399 uint32_t
id = buf->ReadDWord();
8401 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
8403 type = buf->ReadByte();
8407 byte langid = buf->ReadByte();
8408 const char *name_string = buf->ReadString();
8419 type = buf->ReadByte();
8444 byte type = buf->ReadByte();
8446 uint32_t
id = buf->ReadDWord();
8448 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
8450 type = buf->ReadByte();
8463 type = buf->ReadByte();
8500 byte new_type = buf->ReadByte();
8501 while (new_type != 0) {
8504 new_type = buf->ReadByte();
8515 uint16_t size = buf->ReadWord();
8539 while ((tag = &subtags[i++])->type != 0) {
8542 default: NOT_REACHED();
8545 byte langid = buf->ReadByte();
8546 return tag->handler.
text(langid, buf->ReadString());
8550 size_t len = buf->ReadWord();
8551 if (buf->Remaining() < len)
return false;
8552 return tag->handler.
data(len, buf);
8557 return tag->handler.u.branch(buf);
8563 GrfMsg(2,
"StaticGRFInfo: unknown type/id combination found, type={:c}, id={:x}", type,
id);
8575 byte type = buf->ReadByte();
8577 uint32_t
id = buf->ReadDWord();
8578 if (!
HandleNode(type,
id, buf, subtags))
return false;
8579 type = buf->ReadByte();
8700 file->stations.clear();
8708 file->housespec.clear();
8716 for (
auto &as : file->airportspec) {
8717 if (as !=
nullptr) {
8719 for (
int j = 0; j < as->
num_table; j++) {
8728 file->airportspec.clear();
8729 file->airtspec.clear();
8737 file->industryspec.clear();
8738 file->indtspec.clear();
8746 file->objectspec.clear();
8750 static void ResetCustomRoadStops()
8753 file->roadstops.clear();
8782 CleanUpGRFTownNames();
8826 ObjectClass::Reset();
8831 StationClass::Reset();
8835 AirportClass::Reset();
8841 RoadStopClass::Reset();
8842 ResetCustomRoadStops();
8868 _grf_id_overrides.clear();
8870 InitializeSoundPool();
8897 if (!cs->IsValid())
continue;
8917 if (newfile !=
nullptr) {
8923 newfile =
new GRFFile(config);
8941 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8946 std::fill(std::begin(this->railtype_map), std::end(this->railtype_map),
INVALID_RAILTYPE);
8953 std::fill(std::begin(this->roadtype_map), std::end(this->roadtype_map),
INVALID_ROADTYPE);
8957 std::fill(std::begin(this->tramtype_map), std::end(this->tramtype_map),
INVALID_ROADTYPE);
8962 this->param = config->
param;
8979 CargoID cid = GetCargoIDByLabel(label);
8980 if (cid != INVALID_CARGO)
return label;
8992 if (std::holds_alternative<CargoLabel>(label))
return std::get<CargoLabel>(label);
8993 if (std::holds_alternative<MixedCargoType>(label)) {
8994 switch (std::get<MixedCargoType>(label)) {
8998 default: NOT_REACHED();
9009 CargoTypes original_known_cargoes = 0;
9017 bool only_defaultcargo;
9025 if (
_gted[engine].defaultcargo_grf ==
nullptr) {
9028 static constexpr
byte T = 1 << LT_TEMPERATE;
9029 static constexpr
byte A = 1 << LT_ARCTIC;
9030 static constexpr
byte S = 1 << LT_TROPIC;
9031 static constexpr
byte Y = 1 << LT_TOYLAND;
9032 static const struct DefaultRefitMasks {
9035 CargoTypes cargo_allowed;
9036 CargoTypes cargo_disallowed;
9037 } _default_refit_masks[] = {
9039 {T | A | S , CT_MAIL,
CC_MAIL, 0},
9042 {T | A , CT_COAL,
CC_BULK, 0},
9043 { S , CT_COPPER_ORE,
CC_BULK, 0},
9059 switch (label.base()) {
9063 _gted[engine].cargo_disallowed = 0;
9068 _gted[engine].cargo_disallowed = 0;
9087 _gted[engine].cargo_disallowed = 0;
9091 for (
const auto &drm : _default_refit_masks) {
9093 if (drm.cargo_label != label)
continue;
9095 _gted[engine].cargo_allowed = drm.cargo_allowed;
9096 _gted[engine].cargo_disallowed = drm.cargo_disallowed;
9101 _gted[engine].ctt_exclude_mask = original_known_cargoes;
9104 _gted[engine].UpdateRefittability(
_gted[engine].cargo_allowed != 0);
9111 CargoTypes mask = 0;
9112 CargoTypes not_mask = 0;
9113 CargoTypes xor_mask = ei->refit_mask;
9119 if (
_gted[engine].cargo_allowed != 0) {
9122 if (
_gted[engine].cargo_allowed & cs->classes)
SetBit(mask, cs->Index());
9123 if (
_gted[engine].cargo_disallowed & cs->classes)
SetBit(not_mask, cs->Index());
9127 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
9130 ei->refit_mask |=
_gted[engine].ctt_include_mask;
9131 ei->refit_mask &= ~
_gted[engine].ctt_exclude_mask;
9140 ei->cargo_type = INVALID_CARGO;
9148 if (file ==
nullptr) file = e->
GetGRF();
9149 if (file !=
nullptr && file->grf_version >= 8 && !file->
cargo_list.empty()) {
9151 byte best_local_slot = UINT8_MAX;
9153 byte local_slot = file->
cargo_map[cargo_type];
9154 if (local_slot < best_local_slot) {
9155 best_local_slot = local_slot;
9156 ei->cargo_type = cargo_type;
9186 for (uint i = 0; i < CF_END; i++) {
9198 if (e->
GetGRF() ==
nullptr) {
9201 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
9234 default: NOT_REACHED();
9246 if (parent != e->
index)
continue;
9251 GrfMsg(1,
"FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->
index].internal_id, e->
GetGRF()->filename);
9267 switch (cs.label.base()) {
9269 case CT_MAIL.base(): cs.town_production_effect =
TPE_MAIL;
break;
9270 default: cs.town_production_effect =
TPE_NONE;
break;
9273 if (!cs.IsValid()) {
9274 cs.name = cs.name_single = cs.units_volume = STR_NEWGRF_INVALID_CARGO;
9275 cs.quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
9276 cs.abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
9300 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
9310 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines multitile house {} with non-zero population on additional tiles. Disabling house.", filename, hs->
grf_prop.
local_id);
9318 Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->
grf_prop.
local_id);
9325 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} without a size but marked it as available. Disabling house.", filename, hs->
grf_prop.
local_id);
9344 if (hs ==
nullptr || !hs->
enabled)
continue;
9349 if (min_year == 0)
return;
9353 if (hs ==
nullptr || !hs->
enabled)
continue;
9377 if (file->housespec.empty())
continue;
9379 size_t num_houses = file->housespec.size();
9380 for (
size_t i = 0; i < num_houses; i++) {
9381 HouseSpec *hs = file->housespec[i].get();
9383 if (hs ==
nullptr)
continue;
9385 const HouseSpec *next1 = (i + 1 < num_houses ? file->housespec[i + 1].get() :
nullptr);
9386 const HouseSpec *next2 = (i + 2 < num_houses ? file->housespec[i + 2].get() :
nullptr);
9387 const HouseSpec *next3 = (i + 3 < num_houses ? file->housespec[i + 3].get() :
nullptr);
9446 for (
const auto &indsp : file->industryspec) {
9447 if (indsp ==
nullptr || !indsp->
enabled)
continue;
9454 if (strid != STR_UNDEFINED) indsp->
name = strid;
9457 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
9472 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
9478 for (
const auto &indtsp : file->indtspec) {
9479 if (indtsp !=
nullptr) {
9480 _industile_mngr.SetEntitySpec(indtsp.get());
9485 for (
auto &indsp : _industry_specs) {
9492 indsp.
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
9496 for (uint i = 0; i <
lengthof(indsp.produced_cargo); ++i) {
9504 for (
auto &indtsp : _industry_tile_specs) {
9520 for (
auto &objectspec : file->objectspec) {
9521 if (objectspec !=
nullptr && objectspec->grf_prop.grffile !=
nullptr && objectspec->IsEnabled()) {
9538 for (
auto &as : file->airportspec) {
9539 if (as !=
nullptr && as->
enabled) {
9540 _airport_mngr.SetEntitySpec(as.get());
9544 for (
auto &ats : file->airtspec) {
9545 if (ats !=
nullptr && ats->enabled) {
9546 _airporttile_mngr.SetEntitySpec(ats.get());
9558 static void DecodeSpecialSprite(
byte *buf, uint num, GrfLoadingStage stage)
9572 static const SpecialSpriteHandler handlers[][GLS_END] = {
9573 {
nullptr, SafeChangeInfo,
nullptr,
nullptr, ReserveChangeInfo, FeatureChangeInfo, },
9574 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
9575 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, NewSpriteGroup, },
9576 {
nullptr,
GRFUnsafe,
nullptr,
nullptr,
nullptr, FeatureMapSpriteGroup, },
9577 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, FeatureNewName, },
9578 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
9579 {
nullptr,
nullptr,
nullptr, CfgApply, CfgApply, CfgApply, },
9580 {
nullptr,
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, },
9581 { ScanInfo,
nullptr,
nullptr, GRFInfo, GRFInfo, GRFInfo, },
9582 {
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, SkipIf, },
9583 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
9584 {
nullptr,
nullptr,
nullptr, GRFLoadError, GRFLoadError, GRFLoadError, },
9585 {
nullptr,
nullptr,
nullptr, GRFComment,
nullptr, GRFComment, },
9587 {
nullptr, SafeGRFInhibit,
nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
9590 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
9593 {
StaticGRFInfo,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
9598 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
9599 if (it == _grf_line_to_action6_sprite_override.end()) {
9605 buf = _grf_line_to_action6_sprite_override[location].data();
9606 GrfMsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
9616 byte action = bufp->ReadByte();
9618 if (action == 0xFF) {
9619 GrfMsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
9620 }
else if (action == 0xFE) {
9621 GrfMsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
9622 }
else if (action >=
lengthof(handlers)) {
9623 GrfMsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x{:02X}", action);
9624 }
else if (handlers[action][stage] ==
nullptr) {
9625 GrfMsg(7,
"DecodeSpecialSprite: Skipping action 0x{:02X} in stage {}", action, stage);
9627 GrfMsg(7,
"DecodeSpecialSprite: Handling action 0x{:02X} in stage {}", action, stage);
9628 handlers[action][stage](bufp);
9631 GrfMsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
9647 Debug(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '{}'", config->
filename);
9650 if (grf_container_version == 0) {
9651 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9655 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
9661 if (grf_container_version >= 2) file.
ReadDword();
9664 if (grf_container_version >= 2) {
9666 byte compression = file.
ReadByte();
9667 if (compression != 0) {
9668 Debug(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
9677 if (num == 4 && file.
ReadByte() == 0xFF) {
9680 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9688 while ((num = (grf_container_version >= 2 ? file.
ReadDword() : file.
ReadWord())) != 0) {
9694 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
9705 GrfMsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
9706 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
9710 if (grf_container_version >= 2 && type == 0xFD) {
9733 const std::string &filename = config->
filename;
9744 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
9746 if (_cur.
grffile ==
nullptr) UserError(
"File '{}' lost in cache.\n", filename);
9753 SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
9807 DupSprite(SPR_ROAD_DEPOT + 0, SPR_TRAMWAY_DEPOT_NO_TRACK + 0);
9808 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 1, SPR_TRAMWAY_DEPOT_NO_TRACK + 1);
9809 DupSprite(SPR_ROAD_DEPOT + 2, SPR_TRAMWAY_DEPOT_NO_TRACK + 2);
9810 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 3, SPR_TRAMWAY_DEPOT_NO_TRACK + 3);
9811 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 4, SPR_TRAMWAY_DEPOT_NO_TRACK + 4);
9812 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 5, SPR_TRAMWAY_DEPOT_NO_TRACK + 5);
9823 static const uint32_t override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
9827 std::vector<int> grf_overrides(num_grfs, -1);
9828 for (
int i = 0; i < num_grfs; i++) {
9830 uint32_t
override = _grf_id_overrides[source->grfid];
9831 if (
override == 0)
continue;
9834 if (dest ==
nullptr)
continue;
9837 assert(grf_overrides[i] >= 0);
9841 for (
int i = 0; i < num_grfs; i++) {
9842 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
9850 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9853 Debug(grf, 3,
"'{}' overrides price base multiplier {} of '{}'", source->filename, p, dest->filename);
9859 for (
int i = num_grfs - 1; i >= 0; i--) {
9860 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9868 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9871 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, source->filename, dest->filename);
9877 for (
int i = 0; i < num_grfs; i++) {
9878 if (grf_overrides[i] < 0)
continue;
9886 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9887 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9889 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, dest->filename, source->filename);
9897 if (file->grf_version >= 8)
continue;
9898 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9899 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9901 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9904 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9911 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9912 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9913 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9915 price_base_multipliers[p] = 0;
9920 Debug(grf, 3,
"'{}' sets global price base multiplier {}", file->
filename, p);
9922 price_base_multipliers[p] = 0;
9924 Debug(grf, 3,
"'{}' sets local price base multiplier {}", file->
filename, p);
9939 _string_to_grf_mapping.clear();
9942 _grf_line_to_action6_sprite_override.clear();
10005 if (file ==
nullptr ||
_gted[e->
index].roadtramtype == 0) {
10014 if (
_gted[e->
index].roadtramtype < list->size())
10016 RoadTypeLabel rtl = (*list)[
_gted[e->
index].roadtramtype];
10045 _grm_sprites.clear();
10103 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
10110 if (stage == GLS_RESERVE) {
10111 static const uint32_t overrides[][2] = {
10112 { 0x44442202, 0x44440111 },
10113 { 0x6D620402, 0x6D620401 },
10114 { 0x4D656f20, 0x4D656F17 },
10116 for (
size_t i = 0; i <
lengthof(overrides); i++) {
10122 uint num_non_static = 0;
10124 _cur.
stage = stage;
10131 Debug(grf, 0,
"NewGRF file is missing '{}'; disabling", c->
filename);
10140 Debug(grf, 0,
"'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
10142 c->
error = {STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED};
10151 if (stage == GLS_RESERVE) {
10153 }
else if (stage == GLS_ACTIVATION) {
10158 Debug(sprite, 2,
"LoadNewGRF: Currently {} sprites are loaded", _cur.
spriteid);