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);
2575 byte count = buf->ReadByte();
2576 for (
byte j = 0; j < count; j++) {
2584 housespec->
min_year = buf->ReadWord();
2588 housespec->
max_year = buf->ReadWord();
2592 uint count = buf->ReadByte();
2645 template <
typename T>
2649 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
2653 translation_table.clear();
2654 for (
int i = 0; i < numinfo; i++) {
2655 translation_table.push_back(T(
BSWAP32(buf->ReadDWord())));
2670 for (
int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
2704 for (
int i = 0; i < numinfo; i++) {
2707 int factor = buf->ReadByte();
2708 uint price = gvid + i;
2710 if (price < PR_END) {
2713 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring", price);
2722 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2731 uint32_t rate = buf->ReadDWord();
2739 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
2746 uint16_t options = buf->ReadWord();
2755 GrfMsg(1,
"GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
2767 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2779 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2791 GrfMsg(1,
"GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
2798 GrfMsg(1,
"GlobalVarChangeInfo: The snowline can only be set once ({})", numinfo);
2800 GrfMsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf->Remaining());
2806 table[i][j] = buf->ReadByte();
2807 if (_cur.
grffile->grf_version >= 8) {
2810 if (table[i][j] >= 128) {
2832 uint curidx = gvid + i;
2834 if (lang ==
nullptr) {
2835 GrfMsg(1,
"GlobalVarChangeInfo: Language {} is not known, ignoring", curidx);
2840 while (buf->ReadByte() != 0) {
2850 uint plural_form = buf->ReadByte();
2851 if (plural_form >= LANGUAGE_MAX_PLURAL) {
2852 GrfMsg(1,
"GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form);
2859 byte newgrf_id = buf->ReadByte();
2860 while (newgrf_id != 0) {
2861 const char *name = buf->ReadString();
2876 GrfMsg(1,
"GlobalVarChangeInfo: Gender name {} is not known, ignoring", name);
2883 GrfMsg(1,
"GlobalVarChangeInfo: Case name {} is not known, ignoring", name);
2888 newgrf_id = buf->ReadByte();
2924 for (
int i = 0; i < numinfo; i++) {
2948 uint32_t s = buf->ReadDWord();
2949 uint32_t t = buf->ReadDWord();
2956 while (buf->ReadByte() != 0) {
2984 GrfMsg(2,
"CargoChangeInfo: Cargo type {} out of range (max {})", cid + numinfo,
NUM_CARGO - 1);
2988 for (
int i = 0; i < numinfo; i++) {
2993 cs->
bitnum = buf->ReadByte();
3032 cs->
sprite = buf->ReadWord();
3036 cs->
weight = buf->ReadByte();
3040 cs->transit_periods[0] = buf->ReadByte();
3044 cs->transit_periods[1] = buf->ReadByte();
3052 cs->rating_colour = buf->ReadByte();
3056 cs->legend_colour = buf->ReadByte();
3064 cs->
classes = buf->ReadWord();
3073 uint8_t substitute_type = buf->ReadByte();
3075 switch (substitute_type) {
3082 GrfMsg(1,
"CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type);
3098 cs->
multiplier = std::max<uint16_t>(1u, buf->ReadWord());
3102 uint8_t substitute_type = buf->ReadByte();
3104 switch (substitute_type) {
3108 GrfMsg(1,
"CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type);
3141 if (_cur.
grffile->sound_offset == 0) {
3142 GrfMsg(1,
"SoundEffectChangeInfo: No effects defined, skipping");
3147 GrfMsg(1,
"SoundEffectChangeInfo: Attempting to change undefined sound effect ({}), max ({}). Ignoring.", sid + numinfo,
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
3151 for (
int i = 0; i < numinfo; i++) {
3156 sound->volume = buf->ReadByte();
3160 sound->priority = buf->ReadByte();
3164 SoundID orig_sound = buf->ReadByte();
3167 GrfMsg(1,
"SoundEffectChangeInfo: Original sound {} not defined (max {})", orig_sound,
ORIGINAL_SAMPLE_COUNT);
3169 SoundEntry *old_sound = GetSound(orig_sound);
3172 *old_sound = *sound;
3214 buf->Skip(buf->ReadByte() * 2);
3237 GrfMsg(1,
"IndustryTilesChangeInfo: Too many industry tiles loaded ({}), max ({}). Ignoring.", indtid + numinfo,
NUM_INDUSTRYTILES_PER_GRF);
3242 if (_cur.
grffile->indtspec.size() < indtid + numinfo) _cur.
grffile->indtspec.resize(indtid + numinfo);
3244 for (
int i = 0; i < numinfo; i++) {
3247 if (prop != 0x08 && tsp ==
nullptr) {
3249 if (cir > ret) ret = cir;
3255 byte subs_id = buf->ReadByte();
3258 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to use new industry tile {} as substitute industry tile for {}. Ignoring.", subs_id, indtid + i);
3263 if (tsp ==
nullptr) {
3264 _cur.
grffile->indtspec[indtid + i] = std::make_unique<IndustryTileSpec>(_industry_tile_specs[subs_id]);
3265 tsp = _cur.
grffile->indtspec[indtid + i].get();
3284 byte ovrid = buf->ReadByte();
3288 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to override new industry tile {} with industry tile id {}. Ignoring.", ovrid, indtid + i);
3292 _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
3299 uint16_t acctp = buf->ReadWord();
3331 byte num_cargoes = buf->ReadByte();
3332 if (num_cargoes > std::size(tsp->
acceptance)) {
3337 for (uint i = 0; i < std::size(tsp->
acceptance); i++) {
3338 if (i < num_cargoes) {
3341 tsp->
acceptance[i] = (int8_t)buf->ReadByte();
3406 byte num_table = buf->ReadByte();
3407 for (
byte j = 0; j < num_table; j++) {
3408 for (uint k = 0;; k++) {
3409 byte x = buf->ReadByte();
3410 if (x == 0xFE && k == 0) {
3416 byte y = buf->ReadByte();
3417 if (x == 0 && y == 0x80)
break;
3419 byte gfx = buf->ReadByte();
3420 if (gfx == 0xFE) buf->ReadWord();
3427 for (
byte j = 0; j < 3; j++) buf->ReadByte();
3434 buf->Skip(buf->ReadByte());
3438 int num_inputs = buf->ReadByte();
3439 int num_outputs = buf->ReadByte();
3440 buf->Skip(num_inputs * num_outputs * 2);
3458 const size_t size = layout.size();
3459 if (size == 0)
return false;
3461 for (
size_t i = 0; i < size - 1; i++) {
3462 for (
size_t j = i + 1; j < size; j++) {
3463 if (layout[i].ti.x == layout[j].ti.x &&
3464 layout[i].ti.y == layout[j].ti.y) {
3470 bool have_regular_tile =
false;
3471 for (
const auto &tilelayout : layout) {
3473 have_regular_tile =
true;
3478 return have_regular_tile;
3494 GrfMsg(1,
"IndustriesChangeInfo: Too many industries loaded ({}), max ({}). Ignoring.", indid + numinfo,
NUM_INDUSTRYTYPES_PER_GRF);
3499 if (_cur.
grffile->industryspec.size() < indid + numinfo) _cur.
grffile->industryspec.resize(indid + numinfo);
3501 for (
int i = 0; i < numinfo; i++) {
3504 if (prop != 0x08 && indsp ==
nullptr) {
3506 if (cir > ret) ret = cir;
3512 byte subs_id = buf->ReadByte();
3513 if (subs_id == 0xFF) {
3516 _industry_specs[indid + i].
enabled =
false;
3520 GrfMsg(2,
"_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id, indid + i);
3527 if (indsp ==
nullptr) {
3528 _cur.
grffile->industryspec[indid + i] = std::make_unique<IndustrySpec>(_origin_industry_specs[subs_id]);
3529 indsp = _cur.
grffile->industryspec[indid + i].get();
3533 indsp->
grf_prop.subst_id = subs_id;
3543 byte ovrid = buf->ReadByte();
3547 GrfMsg(2,
"IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid, indid + i);
3551 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3556 byte new_num_layouts = buf->ReadByte();
3557 uint32_t definition_size = buf->ReadDWord();
3558 uint32_t bytes_read = 0;
3559 std::vector<IndustryTileLayout> new_layouts;
3562 for (
byte j = 0; j < new_num_layouts; j++) {
3565 for (uint k = 0;; k++) {
3566 if (bytes_read >= definition_size) {
3567 GrfMsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.", indid);
3569 definition_size = UINT32_MAX;
3575 it.ti.
x = buf->ReadByte();
3578 if (it.ti.
x == 0xFE && k == 0) {
3580 IndustryType type = buf->ReadByte();
3581 byte laynbr = buf->ReadByte();
3584 if (type >=
lengthof(_origin_industry_specs)) {
3585 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry {}", indid);
3589 if (laynbr >= _origin_industry_specs[type].layouts.size()) {
3590 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}", indid);
3594 layout = _origin_industry_specs[type].layouts[laynbr];
3598 it.ti.
y = buf->ReadByte();
3601 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
3607 it.gfx = buf->ReadByte();
3610 if (it.gfx == 0xFE) {
3612 int local_tile_id = buf->ReadWord();
3616 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3619 GrfMsg(2,
"IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id, indid);
3625 it.ti.
x = (int8_t)
GB(it.ti.
x, 0, 8);
3626 it.ti.
y = (int8_t)
GB(it.ti.
y, 0, 8);
3635 if (_cur.
grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
3641 GrfMsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring", indid);
3645 new_layouts.push_back(layout);
3675 for (
byte j = 0; j < 2; j++) {
3682 for (
byte j = 0; j < 3; j++) {
3691 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3704 sounds[j] = buf->ReadByte();
3720 for (
byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3746 uint32_t multiples = buf->ReadDWord();
3762 byte aflag = buf->ReadByte();
3772 uint16_t str = buf->ReadWord();
3782 byte num_cargoes = buf->ReadByte();
3783 if (num_cargoes >
lengthof(indsp->produced_cargo)) {
3788 for (uint i = 0; i <
lengthof(indsp->produced_cargo); i++) {
3789 if (i < num_cargoes) {
3791 indsp->produced_cargo[i] = cargo;
3793 indsp->produced_cargo[i] = INVALID_CARGO;
3801 byte num_cargoes = buf->ReadByte();
3808 if (i < num_cargoes) {
3820 byte num_cargoes = buf->ReadByte();
3821 if (num_cargoes >
lengthof(indsp->production_rate)) {
3826 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
3827 if (i < num_cargoes) {
3828 indsp->production_rate[i] = buf->ReadByte();
3830 indsp->production_rate[i] = 0;
3837 byte num_inputs = buf->ReadByte();
3838 byte num_outputs = buf->ReadByte();
3845 for (uint j = 0; j <
lengthof(indsp->produced_cargo); j++) {
3847 if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
3871 for (
int i = 0; i < as->
num_table; i++) {
3876 }
while ((++it)->ti.x != -0x80);
3877 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3880 as->
table = table_list;
3902 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3907 if (_cur.
grffile->airportspec.size() < airport + numinfo) _cur.
grffile->airportspec.resize(airport + numinfo);
3909 for (
int i = 0; i < numinfo; i++) {
3912 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
3913 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring", airport + i);
3919 byte subs_id = buf->ReadByte();
3920 if (subs_id == 0xFF) {
3927 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id, airport + i);
3934 if (as ==
nullptr) {
3936 as = _cur.
grffile->airportspec[airport + i].get();
3943 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3955 uint32_t defsize = buf->ReadDWord();
3961 for (
byte j = 0; j < as->
num_table; j++) {
3963 for (
int k = 0;; k++) {
3964 att[k].
ti.
x = buf->ReadByte();
3965 att[k].
ti.
y = buf->ReadByte();
3967 if (att[k].ti.x == 0 && att[k].
ti.
y == 0x80) {
3970 att[k].
ti.
x = -0x80;
3979 att[k].
gfx = buf->ReadByte();
3981 if (att[k].gfx == 0xFE) {
3983 int local_tile_id = buf->ReadWord();
3986 uint16_t tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3989 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id, airport + i);
3992 att[k].
gfx = tempid;
3994 }
else if (att[k].gfx == 0xFF) {
3995 att[k].
ti.
x = (int8_t)
GB(att[k].ti.x, 0, 8);
3996 att[k].
ti.
y = (int8_t)
GB(att[k].ti.y, 0, 8);
4007 tile_table[j] = CallocT<AirportTileTable>(size);
4008 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
4011 for (
int j = 0; j < old_num_table; j++) {
4017 as->
table = tile_table;
4020 for (
int i = 0; i < as->
num_table; i++) {
4021 free(tile_table[i]);
4123 GrfMsg(1,
"ObjectChangeInfo: Too many objects loaded ({}), max ({}). Ignoring.",
id + numinfo,
NUM_OBJECTS_PER_GRF);
4128 if (_cur.
grffile->objectspec.size() <
id + numinfo) _cur.
grffile->objectspec.resize(
id + numinfo);
4130 for (
int i = 0; i < numinfo; i++) {
4133 if (prop != 0x08 && spec ==
nullptr) {
4136 if (cir > ret) ret = cir;
4143 if (spec ==
nullptr) {
4144 _cur.
grffile->objectspec[
id + i] = std::make_unique<ObjectSpec>();
4145 spec = _cur.
grffile->objectspec[
id + i].get();
4151 uint32_t classid = buf->ReadDWord();
4167 spec->
climate = buf->ReadByte();
4171 spec->
size = buf->ReadByte();
4172 if (
GB(spec->
size, 0, 4) == 0 ||
GB(spec->
size, 4, 4) == 0) {
4173 GrfMsg(0,
"ObjectChangeInfo: Invalid object size requested (0x{:X}) for object id {}. Ignoring.", spec->
size,
id + i);
4218 spec->
height = buf->ReadByte();
4222 spec->
views = buf->ReadByte();
4224 GrfMsg(2,
"ObjectChangeInfo: Invalid number of views ({}) for object id {}. Ignoring.", spec->
views,
id + i);
4257 GrfMsg(1,
"RailTypeChangeInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4261 for (
int i = 0; i < numinfo; i++) {
4274 uint16_t str = buf->ReadWord();
4276 if (_cur.
grffile->grf_version < 8) {
4306 int n = buf->ReadByte();
4307 for (
int j = 0; j != n; j++) {
4308 RailTypeLabel label = buf->ReadDWord();
4368 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4387 GrfMsg(1,
"RailTypeReserveInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4391 for (
int i = 0; i < numinfo; i++) {
4395 RailTypeLabel rtl = buf->ReadDWord();
4404 _cur.
grffile->railtype_map[
id + i] = rt;
4422 int n = buf->ReadByte();
4423 for (
int j = 0; j != n; j++) {
4428 GrfMsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set",
id + i);
4435 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4476 GrfMsg(1,
"RoadTypeChangeInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4480 for (
int i = 0; i < numinfo; i++) {
4493 uint16_t str = buf->ReadWord();
4520 int n = buf->ReadByte();
4521 for (
int j = 0; j != n; j++) {
4522 RoadTypeLabel label = buf->ReadDWord();
4527 if (GetRoadTramType(resolved_rt) == rtt) {
4530 GrfMsg(1,
"RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt);
4575 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4606 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4610 for (
int i = 0; i < numinfo; i++) {
4613 RoadTypeLabel rtl = buf->ReadDWord();
4620 }
else if (GetRoadTramType(rt) != rtt) {
4621 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid type (road/tram), ignoring",
id + numinfo);
4625 type_map[
id + i] = rt;
4642 int n = buf->ReadByte();
4643 for (
int j = 0; j != n; j++) {
4648 GrfMsg(1,
"RoadTypeReserveInfo: Ignoring property 1D for road type {} because no label was set",
id + i);
4654 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4678 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_ROAD);
4683 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_TRAM);
4691 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", airtid + numinfo,
NUM_AIRPORTTILES_PER_GRF);
4696 if (_cur.
grffile->airtspec.size() < airtid + numinfo) _cur.
grffile->airtspec.resize(airtid + numinfo);
4698 for (
int i = 0; i < numinfo; i++) {
4701 if (prop != 0x08 && tsp ==
nullptr) {
4702 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.", airtid + i);
4708 byte subs_id = buf->ReadByte();
4711 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id, airtid + i);
4716 if (tsp ==
nullptr) {
4718 tsp = _cur.
grffile->airtspec[airtid + i].get();
4733 byte override = buf->ReadByte();
4737 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.",
override, airtid + i);
4741 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4816 GrfMsg(1,
"RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring",
id + numinfo,
NUM_ROADSTOPS_PER_GRF);
4820 if (_cur.
grffile->roadstops.size() <
id + numinfo) _cur.
grffile->roadstops.resize(
id + numinfo);
4822 for (
int i = 0; i < numinfo; i++) {
4825 if (rs ==
nullptr && prop != 0x08) {
4826 GrfMsg(1,
"RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring",
id + i);
4828 if (cir > ret) ret = cir;
4834 if (rs ==
nullptr) {
4835 _cur.
grffile->roadstops[
id + i] = std::make_unique<RoadStopSpec>();
4836 rs = _cur.
grffile->roadstops[
id + i].get();
4839 uint32_t classid = buf->ReadDWord();
4866 rs->animation.
frames = buf->ReadByte();
4867 rs->animation.
status = buf->ReadByte();
4871 rs->animation.
speed = buf->ReadByte();
4875 rs->animation.
triggers = buf->ReadWord();
4879 rs->callback_mask = buf->ReadByte();
4883 rs->flags = (uint8_t)buf->ReadDWord();
4900 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property)
4903 default: NOT_REACHED();
4913 GrfMsg(1,
"{}: Ignoring property 0x{:02X} of feature 0x{:02X} (not implemented)", caller, property, feature);
4917 GrfMsg(0,
"{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature);
4930 static void FeatureChangeInfo(
ByteReader *buf)
4943 static const VCI_Handler handler[] = {
4961 AirportTilesChangeInfo,
4966 static_assert(GSF_END ==
lengthof(handler));
4968 uint8_t feature = buf->ReadByte();
4969 uint8_t numprops = buf->ReadByte();
4970 uint numinfo = buf->ReadByte();
4971 uint engine = buf->ReadExtendedByte();
4973 if (feature >= GSF_END) {
4974 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4978 GrfMsg(6,
"FeatureChangeInfo: Feature 0x{:02X}, {} properties, to apply to {}+{}",
4979 feature, numprops, engine, numinfo);
4981 if (handler[feature] ==
nullptr) {
4982 if (feature != GSF_CARGOES) GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4989 while (numprops-- && buf->HasData()) {
4990 uint8_t prop = buf->ReadByte();
4993 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
5000 uint8_t feature = buf->ReadByte();
5001 uint8_t numprops = buf->ReadByte();
5002 uint numinfo = buf->ReadByte();
5003 buf->ReadExtendedByte();
5005 if (feature == GSF_BRIDGES && numprops == 1) {
5006 uint8_t prop = buf->ReadByte();
5009 if (prop == 0x0D)
return;
5010 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
5011 uint8_t prop = buf->ReadByte();
5014 bool is_safe =
true;
5015 for (uint i = 0; i < numinfo; i++) {
5016 uint32_t s = buf->ReadDWord();
5024 if (is_safe)
return;
5035 static void ReserveChangeInfo(
ByteReader *buf)
5037 uint8_t feature = buf->ReadByte();
5039 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES && feature != GSF_ROADTYPES && feature != GSF_TRAMTYPES)
return;
5041 uint8_t numprops = buf->ReadByte();
5042 uint8_t numinfo = buf->ReadByte();
5043 uint8_t index = buf->ReadExtendedByte();
5045 while (numprops-- && buf->HasData()) {
5046 uint8_t prop = buf->ReadByte();
5050 default: NOT_REACHED();
5056 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
5060 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
5064 cir = RoadTypeReserveInfo(index, numinfo, prop, buf);
5068 cir = TramTypeReserveInfo(index, numinfo, prop, buf);
5072 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
5093 uint8_t feature = buf->ReadByte();
5094 uint16_t num_sets = buf->ReadByte();
5095 uint16_t first_set = 0;
5097 if (num_sets == 0 && buf->HasData(3)) {
5100 first_set = buf->ReadExtendedByte();
5101 num_sets = buf->ReadExtendedByte();
5103 uint16_t num_ents = buf->ReadExtendedByte();
5105 if (feature >= GSF_END) {
5107 GrfMsg(1,
"NewSpriteSet: Unsupported feature 0x{:02X}, skipping {} sprites", feature, _cur.
skip_sprites);
5113 GrfMsg(7,
"New sprite set at {} of feature 0x{:02X}, consisting of {} sets with {} views each (total {})",
5114 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
5117 for (
int i = 0; i < num_sets * num_ents; i++) {
5127 uint16_t num_sets = buf->ReadByte();
5129 if (num_sets == 0 && buf->HasData(3)) {
5132 buf->ReadExtendedByte();
5133 num_sets = buf->ReadExtendedByte();
5135 uint16_t num_ents = buf->ReadExtendedByte();
5139 GrfMsg(3,
"SkipAct1: Skipping {} sprites", _cur.
skip_sprites);
5144 static const SpriteGroup *GetGroupFromGroupID(
byte setid,
byte type, uint16_t groupid)
5146 if (
HasBit(groupid, 15)) {
5151 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5152 GrfMsg(1,
"GetGroupFromGroupID(0x{:02X}:0x{:02X}): Groupid 0x{:04X} does not exist, leaving empty", setid, type, groupid);
5156 return _cur.spritegroups[groupid];
5169 if (
HasBit(spriteid, 15)) {
5175 GrfMsg(1,
"CreateGroupFromGroupID(0x{:02X}:0x{:02X}): Sprite set {} invalid", setid, type, spriteid);
5180 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
5183 assert(spriteset_start + num_sprites <= _cur.
spriteid);
5204 uint8_t feature = buf->ReadByte();
5205 if (feature >= GSF_END) {
5206 GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5210 uint8_t setid = buf->ReadByte();
5211 uint8_t type = buf->ReadByte();
5235 switch (
GB(type, 2, 2)) {
5236 default: NOT_REACHED();
5237 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
5238 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
5239 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
5249 adjust.variable = buf->ReadByte();
5250 if (adjust.variable == 0x7E) {
5252 adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
5257 varadjust = buf->ReadByte();
5258 adjust.shift_num =
GB(varadjust, 0, 5);
5259 adjust.type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
5260 adjust.and_mask = buf->ReadVarSize(varsize);
5262 if (adjust.type != DSGA_TYPE_NONE) {
5263 adjust.add_val = buf->ReadVarSize(varsize);
5264 adjust.divmod_val = buf->ReadVarSize(varsize);
5267 adjust.divmod_val = 0;
5271 }
while (
HasBit(varadjust, 5));
5273 std::vector<DeterministicSpriteGroupRange> ranges;
5274 ranges.resize(buf->ReadByte());
5275 for (uint i = 0; i < ranges.size(); i++) {
5276 ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5277 ranges[i].low = buf->ReadVarSize(varsize);
5278 ranges[i].high = buf->ReadVarSize(varsize);
5281 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5282 group->error_group = ranges.empty() ? group->default_group : ranges[0].group;
5284 group->calculated_result = ranges.empty();
5287 std::vector<uint32_t> bounds;
5288 for (uint i = 0; i < ranges.size(); i++) {
5289 bounds.push_back(ranges[i].low);
5290 if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1);
5292 std::sort(bounds.begin(), bounds.end());
5293 bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
5295 std::vector<const SpriteGroup *> target;
5296 for (uint j = 0; j < bounds.size(); ++j) {
5297 uint32_t v = bounds[j];
5299 for (uint i = 0; i < ranges.size(); i++) {
5300 if (ranges[i].low <= v && v <= ranges[i].high) {
5301 t = ranges[i].group;
5305 target.push_back(t);
5307 assert(target.size() == bounds.size());
5309 for (uint j = 0; j < bounds.size(); ) {
5310 if (target[j] != group->default_group) {
5312 r.group = target[j];
5314 while (j < bounds.size() && target[j] == r.group) {
5317 r.high = j < bounds.size() ? bounds[j] - 1 : UINT32_MAX;
5339 group->count = buf->ReadByte();
5342 uint8_t triggers = buf->ReadByte();
5343 group->triggers =
GB(triggers, 0, 7);
5344 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
5347 byte num_groups = buf->ReadByte();
5349 GrfMsg(1,
"NewSpriteGroup: Random Action 2 nrand should be power of 2");
5352 for (uint i = 0; i < num_groups; i++) {
5353 group->
groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
5364 case GSF_ROADVEHICLES:
5375 byte num_loaded = type;
5376 byte num_loading = buf->ReadByte();
5379 GrfMsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
5383 GrfMsg(6,
"NewSpriteGroup: New SpriteGroup 0x{:02X}, {} loaded, {} loading",
5384 setid, num_loaded, num_loading);
5386 if (num_loaded + num_loading == 0) {
5387 GrfMsg(1,
"NewSpriteGroup: no result, skipping invalid RealSpriteGroup");
5391 if (num_loaded + num_loading == 1) {
5393 uint16_t spriteid = buf->ReadWord();
5395 GrfMsg(8,
"NewSpriteGroup: one result, skipping RealSpriteGroup = subset {}", spriteid);
5399 std::vector<uint16_t> loaded;
5400 std::vector<uint16_t> loading;
5402 for (uint i = 0; i < num_loaded; i++) {
5403 loaded.push_back(buf->ReadWord());
5404 GrfMsg(8,
"NewSpriteGroup: + rg->loaded[{}] = subset {}", i, loaded[i]);
5407 for (uint i = 0; i < num_loading; i++) {
5408 loading.push_back(buf->ReadWord());
5409 GrfMsg(8,
"NewSpriteGroup: + rg->loading[{}] = subset {}", i, loading[i]);
5412 if (std::adjacent_find(loaded.begin(), loaded.end(), std::not_equal_to<>()) == loaded.end() &&
5413 std::adjacent_find(loading.begin(), loading.end(), std::not_equal_to<>()) == loading.end() &&
5414 loaded[0] == loading[0])
5418 GrfMsg(8,
"NewSpriteGroup: same result, skipping RealSpriteGroup = subset {}", loaded[0]);
5427 for (uint16_t spriteid : loaded) {
5429 group->
loaded.push_back(t);
5432 for (uint16_t spriteid : loading) {
5441 case GSF_AIRPORTTILES:
5443 case GSF_INDUSTRYTILES:
5444 case GSF_ROADSTOPS: {
5445 byte num_building_sprites = std::max((uint8_t)1, type);
5453 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
5457 case GSF_INDUSTRIES: {
5459 GrfMsg(1,
"NewSpriteGroup: Unsupported industry production version {}, skipping", type);
5470 for (uint i = 0; i < 3; i++) {
5474 for (uint i = 0; i < 2; i++) {
5477 group->again = buf->ReadByte();
5478 }
else if (type == 1) {
5480 for (uint i = 0; i < 3; i++) {
5484 for (uint i = 0; i < 2; i++) {
5487 group->again = buf->ReadByte();
5488 }
else if (type == 2) {
5492 error->
data =
"too many inputs (max 16)";
5495 for (uint i = 0; i < group->
num_input; i++) {
5496 byte rawcargo = buf->ReadByte();
5505 error->
data =
"duplicate input cargo";
5514 error->
data =
"too many outputs (max 16)";
5517 for (uint i = 0; i < group->
num_output; i++) {
5518 byte rawcargo = buf->ReadByte();
5525 error->
data =
"duplicate output cargo";
5531 group->again = buf->ReadByte();
5539 default: GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5544 _cur.spritegroups[setid] = act_group;
5547 static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
5556 GrfMsg(1,
"TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
5557 return INVALID_CARGO;
5561 if (cs->bitnum == ctype) {
5562 GrfMsg(6,
"TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index());
5567 GrfMsg(5,
"TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype);
5568 return INVALID_CARGO;
5573 GrfMsg(1,
"TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (
unsigned int)_cur.
grffile->
cargo_list.size() - 1);
5574 return INVALID_CARGO;
5580 GrfMsg(5,
"TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
5581 return INVALID_CARGO;
5584 CargoID cid = GetCargoIDByLabel(cl);
5586 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));
5587 return INVALID_CARGO;
5590 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);
5595 static bool IsValidGroupID(uint16_t groupid,
const char *
function)
5597 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5598 GrfMsg(1,
"{}: Spritegroup 0x{:04X} out of range or empty, skipping.",
function, groupid);
5605 static void VehicleMapSpriteGroup(
ByteReader *buf,
byte feature, uint8_t idcount)
5608 static uint last_engines_count;
5609 bool wagover =
false;
5612 if (
HasBit(idcount, 7)) {
5615 idcount =
GB(idcount, 0, 7);
5617 if (last_engines_count == 0) {
5618 GrfMsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
5622 GrfMsg(6,
"VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons",
5623 last_engines_count, idcount);
5625 if (last_engines_count != idcount) {
5626 last_engines =
ReallocT(last_engines, idcount);
5627 last_engines_count = idcount;
5631 std::vector<EngineID> engines;
5632 for (uint i = 0; i < idcount; i++) {
5638 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
5642 engines.push_back(e->
index);
5643 if (!wagover) last_engines[i] = engines[i];
5646 uint8_t cidcount = buf->ReadByte();
5647 for (uint c = 0; c < cidcount; c++) {
5648 uint8_t ctype = buf->ReadByte();
5649 uint16_t groupid = buf->ReadWord();
5650 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
5652 GrfMsg(8,
"VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
5654 CargoID cid = TranslateCargo(feature, ctype);
5657 for (uint i = 0; i < idcount; i++) {
5660 GrfMsg(7,
"VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
5663 SetWagonOverrideSprites(engine, cid, _cur.spritegroups[groupid], last_engines, last_engines_count);
5665 SetCustomEngineSprites(engine, cid, _cur.spritegroups[groupid]);
5670 uint16_t groupid = buf->ReadWord();
5671 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
5673 GrfMsg(8,
"-- Default group id 0x{:04X}", groupid);
5675 for (uint i = 0; i < idcount; i++) {
5688 static void CanalMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5690 std::vector<uint16_t> cfs;
5691 cfs.reserve(idcount);
5692 for (uint i = 0; i < idcount; i++) {
5693 cfs.push_back(buf->ReadExtendedByte());
5696 uint8_t cidcount = buf->ReadByte();
5697 buf->Skip(cidcount * 3);
5699 uint16_t groupid = buf->ReadWord();
5700 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
5702 for (
auto &cf : cfs) {
5704 GrfMsg(1,
"CanalMapSpriteGroup: Canal subset {} out of range, skipping", cf);
5714 static void StationMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5716 if (_cur.
grffile->stations.empty()) {
5717 GrfMsg(1,
"StationMapSpriteGroup: No stations defined, skipping");
5721 std::vector<uint16_t> stations;
5722 stations.reserve(idcount);
5723 for (uint i = 0; i < idcount; i++) {
5724 stations.push_back(buf->ReadExtendedByte());
5727 uint8_t cidcount = buf->ReadByte();
5728 for (uint c = 0; c < cidcount; c++) {
5729 uint8_t ctype = buf->ReadByte();
5730 uint16_t groupid = buf->ReadWord();
5731 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5733 ctype = TranslateCargo(GSF_STATIONS, ctype);
5736 for (
auto &station : stations) {
5739 if (statspec ==
nullptr) {
5740 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5748 uint16_t groupid = buf->ReadWord();
5749 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5751 for (
auto &station : stations) {
5754 if (statspec ==
nullptr) {
5755 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5760 GrfMsg(1,
"StationMapSpriteGroup: Station {} mapped multiple times, skipping", station);
5767 StationClass::Assign(statspec);
5772 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5774 if (_cur.
grffile->housespec.empty()) {
5775 GrfMsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5779 std::vector<uint16_t> houses;
5780 houses.reserve(idcount);
5781 for (uint i = 0; i < idcount; i++) {
5782 houses.push_back(buf->ReadExtendedByte());
5786 uint8_t cidcount = buf->ReadByte();
5787 buf->Skip(cidcount * 3);
5789 uint16_t groupid = buf->ReadWord();
5790 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5792 for (
auto &house : houses) {
5795 if (hs ==
nullptr) {
5796 GrfMsg(1,
"TownHouseMapSpriteGroup: House {} undefined, skipping.", house);
5804 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5806 if (_cur.
grffile->industryspec.empty()) {
5807 GrfMsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5811 std::vector<uint16_t> industries;
5812 industries.reserve(idcount);
5813 for (uint i = 0; i < idcount; i++) {
5814 industries.push_back(buf->ReadExtendedByte());
5818 uint8_t cidcount = buf->ReadByte();
5819 buf->Skip(cidcount * 3);
5821 uint16_t groupid = buf->ReadWord();
5822 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5824 for (
auto &industry : industries) {
5827 if (indsp ==
nullptr) {
5828 GrfMsg(1,
"IndustryMapSpriteGroup: Industry {} undefined, skipping", industry);
5836 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5838 if (_cur.
grffile->indtspec.empty()) {
5839 GrfMsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5843 std::vector<uint16_t> indtiles;
5844 indtiles.reserve(idcount);
5845 for (uint i = 0; i < idcount; i++) {
5846 indtiles.push_back(buf->ReadExtendedByte());
5850 uint8_t cidcount = buf->ReadByte();
5851 buf->Skip(cidcount * 3);
5853 uint16_t groupid = buf->ReadWord();
5854 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5856 for (
auto &indtile : indtiles) {
5859 if (indtsp ==
nullptr) {
5860 GrfMsg(1,
"IndustrytileMapSpriteGroup: Industry tile {} undefined, skipping", indtile);
5868 static void CargoMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5870 std::vector<uint16_t> cargoes;
5871 cargoes.reserve(idcount);
5872 for (uint i = 0; i < idcount; i++) {
5873 cargoes.push_back(buf->ReadExtendedByte());
5877 uint8_t cidcount = buf->ReadByte();
5878 buf->Skip(cidcount * 3);
5880 uint16_t groupid = buf->ReadWord();
5881 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5883 for (
auto &cid : cargoes) {
5885 GrfMsg(1,
"CargoMapSpriteGroup: Cargo ID {} out of range, skipping", cid);
5891 cs->group = _cur.spritegroups[groupid];
5895 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5897 if (_cur.
grffile->objectspec.empty()) {
5898 GrfMsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5902 std::vector<uint16_t> objects;
5903 objects.reserve(idcount);
5904 for (uint i = 0; i < idcount; i++) {
5905 objects.push_back(buf->ReadExtendedByte());
5908 uint8_t cidcount = buf->ReadByte();
5909 for (uint c = 0; c < cidcount; c++) {
5910 uint8_t ctype = buf->ReadByte();
5911 uint16_t groupid = buf->ReadWord();
5912 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5915 if (ctype != 0xFF) {
5916 GrfMsg(1,
"ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype);
5920 for (
auto &
object : objects) {
5923 if (spec ==
nullptr) {
5924 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5932 uint16_t groupid = buf->ReadWord();
5933 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5935 for (
auto &
object : objects) {
5938 if (spec ==
nullptr) {
5939 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5944 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} mapped multiple times, skipping",
object);
5954 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5956 std::vector<uint8_t> railtypes;
5957 railtypes.reserve(idcount);
5958 for (uint i = 0; i < idcount; i++) {
5959 uint16_t
id = buf->ReadExtendedByte();
5960 railtypes.push_back(id < RAILTYPE_END ? _cur.grffile->railtype_map[
id] :
INVALID_RAILTYPE);
5963 uint8_t cidcount = buf->ReadByte();
5964 for (uint c = 0; c < cidcount; c++) {
5965 uint8_t ctype = buf->ReadByte();
5966 uint16_t groupid = buf->ReadWord();
5967 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5969 if (ctype >= RTSG_END)
continue;
5972 for (
auto &railtype : railtypes) {
5977 rti->
group[ctype] = _cur.spritegroups[groupid];
5986 static void RoadTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount, RoadTramType rtt)
5990 std::vector<uint8_t> roadtypes;
5991 roadtypes.reserve(idcount);
5992 for (uint i = 0; i < idcount; i++) {
5993 uint16_t
id = buf->ReadExtendedByte();
5997 uint8_t cidcount = buf->ReadByte();
5998 for (uint c = 0; c < cidcount; c++) {
5999 uint8_t ctype = buf->ReadByte();
6000 uint16_t groupid = buf->ReadWord();
6001 if (!IsValidGroupID(groupid,
"RoadTypeMapSpriteGroup"))
continue;
6003 if (ctype >= ROTSG_END)
continue;
6006 for (
auto &roadtype : roadtypes) {
6011 rti->
group[ctype] = _cur.spritegroups[groupid];
6020 static void AirportMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6022 if (_cur.
grffile->airportspec.empty()) {
6023 GrfMsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
6027 std::vector<uint16_t> airports;
6028 airports.reserve(idcount);
6029 for (uint i = 0; i < idcount; i++) {
6030 airports.push_back(buf->ReadExtendedByte());
6034 uint8_t cidcount = buf->ReadByte();
6035 buf->Skip(cidcount * 3);
6037 uint16_t groupid = buf->ReadWord();
6038 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
6040 for (
auto &airport : airports) {
6043 if (as ==
nullptr) {
6044 GrfMsg(1,
"AirportMapSpriteGroup: Airport {} undefined, skipping", airport);
6052 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6054 if (_cur.
grffile->airtspec.empty()) {
6055 GrfMsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
6059 std::vector<uint16_t> airptiles;
6060 airptiles.reserve(idcount);
6061 for (uint i = 0; i < idcount; i++) {
6062 airptiles.push_back(buf->ReadExtendedByte());
6066 uint8_t cidcount = buf->ReadByte();
6067 buf->Skip(cidcount * 3);
6069 uint16_t groupid = buf->ReadWord();
6070 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
6072 for (
auto &airptile : airptiles) {
6075 if (airtsp ==
nullptr) {
6076 GrfMsg(1,
"AirportTileMapSpriteGroup: Airport tile {} undefined, skipping", airptile);
6084 static void RoadStopMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6086 if (_cur.
grffile->roadstops.empty()) {
6087 GrfMsg(1,
"RoadStopMapSpriteGroup: No roadstops defined, skipping");
6091 std::vector<uint16_t> roadstops;
6092 roadstops.reserve(idcount);
6093 for (uint i = 0; i < idcount; i++) {
6094 roadstops.push_back(buf->ReadExtendedByte());
6097 uint8_t cidcount = buf->ReadByte();
6098 for (uint c = 0; c < cidcount; c++) {
6099 uint8_t ctype = buf->ReadByte();
6100 uint16_t groupid = buf->ReadWord();
6101 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
continue;
6103 ctype = TranslateCargo(GSF_ROADSTOPS, ctype);
6106 for (
auto &roadstop : roadstops) {
6109 if (roadstopspec ==
nullptr) {
6110 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping", roadstop);
6118 uint16_t groupid = buf->ReadWord();
6119 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
return;
6121 for (
auto &roadstop : roadstops) {
6124 if (roadstopspec ==
nullptr) {
6125 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping.", roadstop);
6130 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} mapped multiple times, skipping", roadstop);
6137 RoadStopClass::Assign(roadstopspec);
6142 static void FeatureMapSpriteGroup(
ByteReader *buf)
6158 uint8_t feature = buf->ReadByte();
6159 uint8_t idcount = buf->ReadByte();
6161 if (feature >= GSF_END) {
6162 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6170 uint16_t groupid = buf->ReadWord();
6171 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
6173 GrfMsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature 0x{:02X}", feature);
6182 GrfMsg(6,
"FeatureMapSpriteGroup: Feature 0x{:02X}, {} ids", feature, idcount);
6186 case GSF_ROADVEHICLES:
6189 VehicleMapSpriteGroup(buf, feature, idcount);
6193 CanalMapSpriteGroup(buf, idcount);
6197 StationMapSpriteGroup(buf, idcount);
6201 TownHouseMapSpriteGroup(buf, idcount);
6204 case GSF_INDUSTRIES:
6205 IndustryMapSpriteGroup(buf, idcount);
6208 case GSF_INDUSTRYTILES:
6209 IndustrytileMapSpriteGroup(buf, idcount);
6213 CargoMapSpriteGroup(buf, idcount);
6217 AirportMapSpriteGroup(buf, idcount);
6221 ObjectMapSpriteGroup(buf, idcount);
6225 RailTypeMapSpriteGroup(buf, idcount);
6229 RoadTypeMapSpriteGroup(buf, idcount, RTT_ROAD);
6233 RoadTypeMapSpriteGroup(buf, idcount, RTT_TRAM);
6236 case GSF_AIRPORTTILES:
6237 AirportTileMapSpriteGroup(buf, idcount);
6241 RoadStopMapSpriteGroup(buf, idcount);
6245 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6269 bool new_scheme = _cur.
grffile->grf_version >= 7;
6271 uint8_t feature = buf->ReadByte();
6272 if (feature >= GSF_END && feature != 0x48) {
6273 GrfMsg(1,
"FeatureNewName: Unsupported feature 0x{:02X}, skipping", feature);
6277 uint8_t lang = buf->ReadByte();
6278 uint8_t num = buf->ReadByte();
6279 bool generic =
HasBit(lang, 7);
6282 id = buf->ReadWord();
6283 }
else if (feature <= GSF_AIRCRAFT) {
6284 id = buf->ReadExtendedByte();
6286 id = buf->ReadByte();
6291 uint16_t endid =
id + num;
6293 GrfMsg(6,
"FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
6294 id, endid, feature, lang);
6296 for (;
id < endid && buf->HasData();
id++) {
6297 const char *name = buf->ReadString();
6298 GrfMsg(8,
"FeatureNewName: 0x{:04X} <- {}",
id, name);
6302 case GSF_ROADVEHICLES:
6307 if (e ==
nullptr)
break;
6321 switch (
GB(
id, 8, 8)) {
6323 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6324 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6332 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6333 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6340 if (
GB(
id, 0, 8) >= _cur.
grffile->airtspec.size() || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
6341 GrfMsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring",
GB(
id, 0, 8));
6348 if (
GB(
id, 0, 8) >= _cur.
grffile->housespec.size() || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
6349 GrfMsg(1,
"FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.",
GB(
id, 0, 8));
6351 _cur.
grffile->housespec[
GB(
id, 0, 8)]->building_name =
AddGRFString(_cur.
grffile->grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6356 GrfMsg(7,
"FeatureNewName: Unsupported ID (0x{:04X})",
id);
6375 if (offset >= max_sprites) {
6376 GrfMsg(1,
"GraphicsNew: {} sprite offset must be less than {}, skipping", name, max_sprites);
6377 uint orig_num = num;
6382 if (offset + num > max_sprites) {
6383 GrfMsg(4,
"GraphicsNew: {} sprite overflow, truncating...", name);
6384 uint orig_num = num;
6385 num = std::max(max_sprites - offset, 0);
6386 return orig_num - num;
6415 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
6417 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
6447 uint8_t type = buf->ReadByte();
6448 uint16_t num = buf->ReadExtendedByte();
6449 uint16_t offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
6455 GrfMsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
6472 GrfMsg(2,
"GraphicsNew: Custom graphics (type 0x{:02X}) sprite block of length {} (unimplemented, ignoring)", type, num);
6483 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
6490 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) count must be at least {}. Only {} were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
6500 GrfMsg(2,
"GraphicsNew: Replacing sprites {} to {} of {} (type 0x{:02X}) at SpriteID 0x{:04X}", offset, offset + num - 1, action5_type->
name, type, replace);
6512 bool dup_oneway_sprites = ((type == 0x09) && (offset + num <= SPR_ONEWAY_SLOPE_N_OFFSET));
6514 for (; num > 0; num--) {
6516 int load_index = (replace == 0 ? _cur.
spriteid++ : replace++);
6518 if (dup_oneway_sprites) {
6519 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
6520 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_S_OFFSET);
6536 GrfMsg(3,
"SkipAct5: Skipping {} sprites", _cur.
skip_sprites);
6589 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
6619 *value = _game_mode;
6653 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
6662 *value = _openttd_newgrf_version;
6677 default:
return false;
6681 static uint32_t GetParamVal(
byte param, uint32_t *cond_val)
6700 if (cond_val ==
nullptr) {
6704 uint32_t index = *cond_val / 0x20;
6720 GrfMsg(1,
"Unsupported in-game variable 0x{:02X}", param);
6741 size_t pos = file.
GetPos();
6747 GrfMsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
6750 file.
SeekTo(pos, SEEK_SET);
6756 std::vector<byte> &preload_sprite = _grf_line_to_action6_sprite_override[location];
6759 if (preload_sprite.empty()) {
6760 preload_sprite.resize(num);
6761 file.
ReadBlock(preload_sprite.data(), num);
6765 file.
SeekTo(pos, SEEK_SET);
6776 param_num = buf->ReadByte();
6777 if (param_num == 0xFF)
break;
6781 param_size = buf->ReadByte();
6785 add_value =
HasBit(param_size, 7);
6786 param_size =
GB(param_size, 0, 7);
6789 offset = buf->ReadExtendedByte();
6793 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
6794 GrfMsg(2,
"CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4));
6798 GrfMsg(8,
"CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset);
6801 for (i = 0; i < param_size && offset + i < num; i++) {
6802 uint32_t value = GetParamVal(param_num + i / 4,
nullptr);
6805 if (i % 4 == 0) carry =
false;
6808 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
6809 preload_sprite[offset + i] =
GB(new_value, 0, 8);
6811 carry = new_value >= 256;
6813 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6845 uint32_t cond_val = 0;
6849 uint8_t param = buf->ReadByte();
6850 uint8_t paramsize = buf->ReadByte();
6851 uint8_t condtype = buf->ReadByte();
6858 switch (paramsize) {
6859 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6860 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6861 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6862 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6866 if (param < 0x80 && _cur.grffile->param_end <= param) {
6867 GrfMsg(7,
"SkipIf: Param {} undefined, skipping test", param);
6871 GrfMsg(7,
"SkipIf: Test condtype {}, param 0x{:02X}, condval 0x{:08X}", condtype, param, cond_val);
6876 if (condtype >= 0x0B) {
6907 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6909 }
else if (param == 0x88) {
6919 if (condtype != 10 && c ==
nullptr) {
6920 GrfMsg(7,
"SkipIf: GRFID 0x{:08X} unknown, skipping test",
BSWAP32(cond_val));
6947 default: GrfMsg(1,
"SkipIf: Unsupported GRF condition type {:02X}. Ignoring", condtype);
return;
6951 uint32_t param_val = GetParamVal(param, &cond_val);
6953 case 0x00: result = !!(param_val & (1 << cond_val));
6955 case 0x01: result = !(param_val & (1 << cond_val));
6957 case 0x02: result = (param_val & mask) == cond_val;
6959 case 0x03: result = (param_val & mask) != cond_val;
6961 case 0x04: result = (param_val & mask) < cond_val;
6963 case 0x05: result = (param_val & mask) > cond_val;
6965 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6970 GrfMsg(2,
"SkipIf: Not skipping sprites, test was false");
6974 uint8_t numsprites = buf->ReadByte();
6982 if (label.label != numsprites)
continue;
6985 if (choice ==
nullptr) choice = &label;
6987 if (label.nfo_line > _cur.
nfo_line) {
6993 if (choice !=
nullptr) {
6994 GrfMsg(2,
"SkipIf: Jumping to label 0x{:X} at line {}, test was true", choice->label, choice->nfo_line);
7000 GrfMsg(2,
"SkipIf: Skipping {} sprites, test was true", numsprites);
7019 uint8_t grf_version = buf->ReadByte();
7020 uint32_t grfid = buf->ReadDWord();
7021 const char *name = buf->ReadString();
7025 if (grf_version < 2 || grf_version > 8) {
7027 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);
7035 if (buf->HasData()) {
7036 const char *info = buf->ReadString();
7054 uint8_t version = buf->ReadByte();
7055 uint32_t grfid = buf->ReadDWord();
7056 const char *name = buf->ReadString();
7059 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
7063 if (_cur.
grffile->grfid != grfid) {
7064 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));
7068 _cur.
grffile->grf_version = version;
7086 uint8_t num_sets = buf->ReadByte();
7088 for (uint i = 0; i < num_sets; i++) {
7089 uint8_t num_sprites = buf->ReadByte();
7090 uint16_t first_sprite = buf->ReadWord();
7092 GrfMsg(2,
"SpriteReplace: [Set {}] Changing {} sprites, beginning with {}",
7093 i, num_sprites, first_sprite
7096 for (uint j = 0; j < num_sprites; j++) {
7097 int load_index = first_sprite + j;
7103 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
7113 uint8_t num_sets = buf->ReadByte();
7115 for (uint i = 0; i < num_sets; i++) {
7122 GrfMsg(3,
"SkipActA: Skipping {} sprites", _cur.
skip_sprites);
7144 STR_NEWGRF_ERROR_VERSION_NUMBER,
7145 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
7146 STR_NEWGRF_ERROR_UNSET_SWITCH,
7147 STR_NEWGRF_ERROR_INVALID_PARAMETER,
7148 STR_NEWGRF_ERROR_LOAD_BEFORE,
7149 STR_NEWGRF_ERROR_LOAD_AFTER,
7150 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
7154 STR_NEWGRF_ERROR_MSG_INFO,
7155 STR_NEWGRF_ERROR_MSG_WARNING,
7156 STR_NEWGRF_ERROR_MSG_ERROR,
7157 STR_NEWGRF_ERROR_MSG_FATAL
7160 byte severity = buf->ReadByte();
7161 byte lang = buf->ReadByte();
7162 byte message_id = buf->ReadByte();
7165 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
7169 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
7170 GrfMsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage {}", _cur.
stage);
7175 if (severity >=
lengthof(sevstr)) {
7176 GrfMsg(7,
"GRFLoadError: Invalid severity id {}. Setting to 2 (non-fatal error).", severity);
7178 }
else if (severity == 3) {
7187 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
7188 GrfMsg(7,
"GRFLoadError: Invalid message id.");
7192 if (buf->Remaining() <= 1) {
7193 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7203 if (message_id == 0xFF) {
7205 if (buf->HasData()) {
7206 const char *message = buf->ReadString();
7210 GrfMsg(7,
"GRFLoadError: No custom message supplied.");
7214 error->
message = msgstr[message_id];
7217 if (buf->HasData()) {
7218 const char *data = buf->ReadString();
7222 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7223 error->
data.clear();
7227 for (uint i = 0; i < error->
param_value.size() && buf->HasData(); i++) {
7228 uint param_number = buf->ReadByte();
7240 if (!buf->HasData())
return;
7242 const char *text = buf->ReadString();
7243 GrfMsg(2,
"GRFComment: {}", text);
7249 uint8_t target = buf->ReadByte();
7252 if (target < 0x80 || target == 0x9E)
return;
7266 static uint32_t GetPatchVariable(uint8_t param)
7276 case 0x0F:
return 0;
7292 case 0x11:
return SPR_2CCMAP_BASE;
7309 byte max_edge = std::max(log_X, log_Y);
7311 if (log_X == log_Y) {
7314 if (max_edge == log_Y)
SetBit(map_bits, 1);
7317 return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
7318 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
7327 return SPR_SLOPES_BASE;
7338 GrfMsg(2,
"ParamSet: Unknown Patch variable 0x{:02X}.", param);
7344 static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint8_t op, uint8_t target,
const char *type)
7357 for (uint i = start; i < num_ids; i++) {
7361 if (op == 2 || op == 3)
break;
7366 if (size == count)
break;
7369 if (size == count) {
7371 if (op == 0 || op == 3) {
7372 GrfMsg(2,
"ParamSet: GRM: Reserving {} {} at {}", count, type, start);
7373 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
7379 if (op != 4 && op != 5) {
7381 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type);
7386 GrfMsg(1,
"ParamSet: GRM: Unable to allocate {} {}", count, type);
7416 uint8_t target = buf->ReadByte();
7417 uint8_t oper = buf->ReadByte();
7418 uint32_t src1 = buf->ReadByte();
7419 uint32_t src2 = buf->ReadByte();
7422 if (buf->Remaining() >= 4) data = buf->ReadDWord();
7431 if (target < 0x80 && target < _cur.grffile->param_end) {
7432 GrfMsg(7,
"ParamSet: Param {} already defined, skipping", target);
7436 oper =
GB(oper, 0, 7);
7440 if (
GB(data, 0, 8) == 0xFF) {
7441 if (data == 0x0000FFFF) {
7443 src1 = GetPatchVariable(src1);
7447 uint8_t feature =
GB(data, 8, 8);
7448 uint16_t count =
GB(data, 16, 16);
7450 if (_cur.
stage == GLS_RESERVE) {
7451 if (feature == 0x08) {
7455 if (_cur.
spriteid + count >= 16384) {
7456 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count);
7462 GrfMsg(4,
"ParamSet: GRM: Allocated {} sprites at {}", count, _cur.
spriteid);
7469 }
else if (_cur.
stage == GLS_ACTIVATION) {
7498 GrfMsg(4,
"ParamSet: GRM: Using pre-allocated sprites at {}", src1);
7506 GrfMsg(1,
"ParamSet: GRM: Unsupported operation {} for general sprites", op);
7517 default: GrfMsg(1,
"ParamSet: GRM: Unsupported feature 0x{:X}", feature);
return;
7534 }
else if (src1 == 0xFE) {
7546 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
7547 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
7569 res = (int32_t)src1 * (int32_t)src2;
7573 if ((int32_t)src2 < 0) {
7574 res = src1 >> -(int32_t)src2;
7576 res = src1 << (src2 & 0x1F);
7581 if ((int32_t)src2 < 0) {
7582 res = (int32_t)src1 >> -(int32_t)src2;
7584 res = (int32_t)src1 << (src2 & 0x1F);
7608 res = (int32_t)src1 / (int32_t)src2;
7624 res = (int32_t)src1 % (int32_t)src2;
7628 default: GrfMsg(0,
"ParamSet: Unknown operation {}, skipping", oper);
return;
7657 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7668 uint32_t safe_bits = 0;
7669 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
7678 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7682 if (target < 0x80) {
7683 _cur.
grffile->param[target] = res;
7687 GrfMsg(7,
"ParamSet: Skipping unknown target 0x{:02X}", target);
7701 uint8_t num = buf->ReadByte();
7703 for (uint i = 0; i < num; i++) {
7704 uint32_t grfid = buf->ReadDWord();
7726 uint8_t num = buf->ReadByte();
7728 for (uint i = 0; i < num; i++) {
7729 uint32_t grfid = buf->ReadDWord();
7733 if (file !=
nullptr && file != _cur.
grfconfig) {
7734 GrfMsg(2,
"GRFInhibit: Deactivating file '{}'", file->
filename);
7751 uint32_t grfid = _cur.
grffile->grfid;
7755 byte id = buf->ReadByte();
7756 GrfMsg(6,
"FeatureTownName: definition 0x{:02X}",
id & 0x7F);
7761 bool new_scheme = _cur.
grffile->grf_version >= 7;
7763 byte lang = buf->ReadByte();
7769 const char *name = buf->ReadString();
7772 GrfMsg(6,
"FeatureTownName: lang 0x{:X} -> '{}'", lang, lang_name);
7774 style =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
7776 lang = buf->ReadByte();
7777 }
while (lang != 0);
7778 townname->
styles.emplace_back(style,
id);
7781 uint8_t parts = buf->ReadByte();
7782 GrfMsg(6,
"FeatureTownName: {} parts", parts);
7785 for (uint partnum = 0; partnum < parts; partnum++) {
7787 uint8_t texts = buf->ReadByte();
7788 partlist.
bitstart = buf->ReadByte();
7789 partlist.
bitcount = buf->ReadByte();
7791 GrfMsg(6,
"FeatureTownName: part {} contains {} texts and will use GB(seed, {}, {})", partnum, texts, partlist.
bitstart, partlist.
bitcount);
7793 partlist.
parts.reserve(texts);
7794 for (uint textnum = 0; textnum < texts; textnum++) {
7796 part.
prob = buf->ReadByte();
7799 byte ref_id = buf->ReadByte();
7801 GrfMsg(0,
"FeatureTownName: definition 0x{:02X} doesn't exist, deactivating", ref_id);
7802 DelGRFTownName(grfid);
7807 GrfMsg(6,
"FeatureTownName: part {}, text {}, uses intermediate definition 0x{:02X} (with probability {})", partnum, textnum, ref_id, part.
prob & 0x7F);
7809 const char *text = buf->ReadString();
7811 GrfMsg(6,
"FeatureTownName: part {}, text {}, '{}' (with probability {})", partnum, textnum, part.
text, part.
prob);
7815 GrfMsg(6,
"FeatureTownName: part {}, total probability {}", partnum, partlist.
maxprob);
7827 byte nfo_label = buf->ReadByte();
7831 GrfMsg(2,
"DefineGotoLabel: GOTO target with label 0x{:02X}", nfo_label);
7845 if (file ==
nullptr || file->sound_offset == 0) {
7846 GrfMsg(1,
"ImportGRFSound: Source file not available");
7850 if (sound_id >= file->num_sounds) {
7851 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
7855 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid);
7857 *sound = *GetSound(file->sound_offset + sound_id);
7860 sound->volume = 128;
7861 sound->priority = 0;
7872 sound->volume = 0x80;
7873 sound->priority = 0;
7875 if (offs != SIZE_MAX) {
7877 sound->file = _cur.
file;
7878 sound->file_offset = offs;
7890 uint16_t num = buf->ReadWord();
7891 if (num == 0)
return;
7894 if (_cur.
grffile->sound_offset == 0) {
7895 _cur.
grffile->sound_offset = GetNumSounds();
7896 _cur.
grffile->num_sounds = num;
7899 sound = GetSound(_cur.
grffile->sound_offset);
7904 for (
int i = 0; i < num; i++) {
7909 bool invalid = i >= _cur.
grffile->num_sounds;
7911 size_t offs = file.
GetPos();
7916 if (grf_container_version >= 2 && type == 0xFD) {
7919 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7921 }
else if (len != 4) {
7922 GrfMsg(1,
"GRFSound: Invalid sprite section import");
7932 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7939 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7947 if (_cur.
stage == GLS_INIT) {
7948 if (grf_container_version >= 2) {
7949 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7958 if (_cur.
stage == GLS_ACTIVATION) {
7961 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
7969 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
7985 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur.
skip_sprites);
7998 uint8_t num_def = buf->ReadByte();
8000 for (uint i = 0; i < num_def; i++) {
8002 uint8_t num_char = buf->ReadByte();
8003 uint16_t base_char = buf->ReadWord();
8005 if (size >= FS_END) {
8006 GrfMsg(1,
"LoadFontGlyph: Size {} is not supported, ignoring", size);
8009 GrfMsg(7,
"LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
8011 for (uint c = 0; c < num_char; c++) {
8029 uint8_t num_def = buf->ReadByte();
8031 for (uint i = 0; i < num_def; i++) {
8042 GrfMsg(3,
"SkipAct12: Skipping {} sprites", _cur.
skip_sprites);
8055 uint32_t grfid = buf->ReadDWord();
8058 GrfMsg(7,
"TranslateGRFStrings: GRFID 0x{:08X} unknown, skipping action 13",
BSWAP32(grfid));
8067 error->
data =
GetString(STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE);
8077 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
8078 byte num_strings = buf->ReadByte();
8079 uint16_t first_id = buf->ReadWord();
8081 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
8082 GrfMsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x{:04X}, number: 0x{:02X})", first_id, num_strings);
8086 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
8087 const char *
string = buf->ReadString();
8090 GrfMsg(7,
"TranslateGRFString: Ignoring empty string.");
8094 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
8123 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got {}, ignoring this field", len);
8135 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got {}, ignoring this field", len);
8138 char data = buf->ReadByte();
8146 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'PALS', ignoring this field", data);
8161 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got {}, ignoring this field", len);
8164 char data = buf->ReadByte();
8170 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'BLTR', ignoring this field", data);
8183 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got {}, ignoring this field", len);
8196 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got {}, ignoring this field", len);
8201 GrfMsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
8232 GrfMsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got {}, ignoring this field", len);
8239 GrfMsg(3,
"StaticGRFInfo: unknown parameter type {}, ignoring this field", type);
8249 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
8251 }
else if (len != 8) {
8252 GrfMsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got {}, ignoring this field", len);
8255 uint32_t min_value = buf->ReadDWord();
8256 uint32_t max_value = buf->ReadDWord();
8257 if (min_value <= max_value) {
8261 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field");
8270 if (len < 1 || len > 3) {
8271 GrfMsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got {}, ignoring this field", len);
8274 byte param_nr = buf->ReadByte();
8276 GrfMsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param {}, ignoring this field", param_nr);
8292 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got {}, ignoring this field", len);
8328 this->handler.data = handler;
8340 this->handler.text = handler;
8352 this->handler.call_handler =
true;
8353 this->handler.u.branch = handler;
8365 this->handler.call_handler =
false;
8366 this->handler.u.subtags =
subtags;
8395 byte type = buf->ReadByte();
8397 uint32_t
id = buf->ReadDWord();
8399 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
8401 type = buf->ReadByte();
8405 byte langid = buf->ReadByte();
8406 const char *name_string = buf->ReadString();
8417 type = buf->ReadByte();
8442 byte type = buf->ReadByte();
8444 uint32_t
id = buf->ReadDWord();
8446 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
8448 type = buf->ReadByte();
8461 type = buf->ReadByte();
8498 byte new_type = buf->ReadByte();
8499 while (new_type != 0) {
8502 new_type = buf->ReadByte();
8513 uint16_t size = buf->ReadWord();
8537 while ((tag = &subtags[i++])->type != 0) {
8540 default: NOT_REACHED();
8543 byte langid = buf->ReadByte();
8544 return tag->handler.
text(langid, buf->ReadString());
8548 size_t len = buf->ReadWord();
8549 if (buf->Remaining() < len)
return false;
8550 return tag->handler.
data(len, buf);
8555 return tag->handler.u.branch(buf);
8561 GrfMsg(2,
"StaticGRFInfo: unknown type/id combination found, type={:c}, id={:x}", type,
id);
8573 byte type = buf->ReadByte();
8575 uint32_t
id = buf->ReadDWord();
8576 if (!
HandleNode(type,
id, buf, subtags))
return false;
8577 type = buf->ReadByte();
8698 file->stations.clear();
8706 file->housespec.clear();
8714 for (
auto &as : file->airportspec) {
8715 if (as !=
nullptr) {
8717 for (
int j = 0; j < as->
num_table; j++) {
8726 file->airportspec.clear();
8727 file->airtspec.clear();
8735 file->industryspec.clear();
8736 file->indtspec.clear();
8744 file->objectspec.clear();
8748 static void ResetCustomRoadStops()
8751 file->roadstops.clear();
8780 CleanUpGRFTownNames();
8824 ObjectClass::Reset();
8829 StationClass::Reset();
8833 AirportClass::Reset();
8839 RoadStopClass::Reset();
8840 ResetCustomRoadStops();
8866 _grf_id_overrides.clear();
8868 InitializeSoundPool();
8895 if (!cs->IsValid())
continue;
8915 if (newfile !=
nullptr) {
8921 newfile =
new GRFFile(config);
8939 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8944 std::fill(std::begin(this->railtype_map), std::end(this->railtype_map),
INVALID_RAILTYPE);
8951 std::fill(std::begin(this->roadtype_map), std::end(this->roadtype_map),
INVALID_ROADTYPE);
8955 std::fill(std::begin(this->tramtype_map), std::end(this->tramtype_map),
INVALID_ROADTYPE);
8960 this->param = config->
param;
8977 CargoID cid = GetCargoIDByLabel(label);
8978 if (cid != INVALID_CARGO)
return label;
8990 if (std::holds_alternative<CargoLabel>(label))
return std::get<CargoLabel>(label);
8991 if (std::holds_alternative<MixedCargoType>(label)) {
8992 switch (std::get<MixedCargoType>(label)) {
8996 default: NOT_REACHED();
9007 CargoTypes original_known_cargoes = 0;
9015 bool only_defaultcargo;
9023 if (
_gted[engine].defaultcargo_grf ==
nullptr) {
9026 static constexpr
byte T = 1 << LT_TEMPERATE;
9027 static constexpr
byte A = 1 << LT_ARCTIC;
9028 static constexpr
byte S = 1 << LT_TROPIC;
9029 static constexpr
byte Y = 1 << LT_TOYLAND;
9030 static const struct DefaultRefitMasks {
9033 CargoTypes cargo_allowed;
9034 CargoTypes cargo_disallowed;
9035 } _default_refit_masks[] = {
9037 {T | A | S , CT_MAIL,
CC_MAIL, 0},
9040 {T | A , CT_COAL,
CC_BULK, 0},
9041 { S , CT_COPPER_ORE,
CC_BULK, 0},
9057 switch (label.base()) {
9061 _gted[engine].cargo_disallowed = 0;
9066 _gted[engine].cargo_disallowed = 0;
9085 _gted[engine].cargo_disallowed = 0;
9089 for (
const auto &drm : _default_refit_masks) {
9091 if (drm.cargo_label != label)
continue;
9093 _gted[engine].cargo_allowed = drm.cargo_allowed;
9094 _gted[engine].cargo_disallowed = drm.cargo_disallowed;
9099 _gted[engine].ctt_exclude_mask = original_known_cargoes;
9102 _gted[engine].UpdateRefittability(
_gted[engine].cargo_allowed != 0);
9109 CargoTypes mask = 0;
9110 CargoTypes not_mask = 0;
9111 CargoTypes xor_mask = ei->refit_mask;
9117 if (
_gted[engine].cargo_allowed != 0) {
9120 if (
_gted[engine].cargo_allowed & cs->classes)
SetBit(mask, cs->Index());
9121 if (
_gted[engine].cargo_disallowed & cs->classes)
SetBit(not_mask, cs->Index());
9125 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
9128 ei->refit_mask |=
_gted[engine].ctt_include_mask;
9129 ei->refit_mask &= ~
_gted[engine].ctt_exclude_mask;
9138 ei->cargo_type = INVALID_CARGO;
9146 if (file ==
nullptr) file = e->
GetGRF();
9147 if (file !=
nullptr && file->grf_version >= 8 && !file->
cargo_list.empty()) {
9149 byte best_local_slot = UINT8_MAX;
9151 byte local_slot = file->
cargo_map[cargo_type];
9152 if (local_slot < best_local_slot) {
9153 best_local_slot = local_slot;
9154 ei->cargo_type = cargo_type;
9184 for (uint i = 0; i < CF_END; i++) {
9196 if (e->
GetGRF() ==
nullptr) {
9199 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
9232 default: NOT_REACHED();
9244 if (parent != e->
index)
continue;
9249 GrfMsg(1,
"FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->
index].internal_id, e->
GetGRF()->filename);
9265 switch (cs.label.base()) {
9267 case CT_MAIL.base(): cs.town_production_effect =
TPE_MAIL;
break;
9268 default: cs.town_production_effect =
TPE_NONE;
break;
9271 if (!cs.IsValid()) {
9272 cs.name = cs.name_single = cs.units_volume = STR_NEWGRF_INVALID_CARGO;
9273 cs.quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
9274 cs.abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
9298 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
9308 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);
9316 Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->
grf_prop.
local_id);
9323 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);
9342 if (hs ==
nullptr || !hs->
enabled)
continue;
9347 if (min_year == 0)
return;
9351 if (hs ==
nullptr || !hs->
enabled)
continue;
9375 if (file->housespec.empty())
continue;
9377 size_t num_houses = file->housespec.size();
9378 for (
size_t i = 0; i < num_houses; i++) {
9379 HouseSpec *hs = file->housespec[i].get();
9381 if (hs ==
nullptr)
continue;
9383 const HouseSpec *next1 = (i + 1 < num_houses ? file->housespec[i + 1].get() :
nullptr);
9384 const HouseSpec *next2 = (i + 2 < num_houses ? file->housespec[i + 2].get() :
nullptr);
9385 const HouseSpec *next3 = (i + 3 < num_houses ? file->housespec[i + 3].get() :
nullptr);
9444 for (
const auto &indsp : file->industryspec) {
9445 if (indsp ==
nullptr || !indsp->
enabled)
continue;
9452 if (strid != STR_UNDEFINED) indsp->
name = strid;
9455 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
9470 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
9476 for (
const auto &indtsp : file->indtspec) {
9477 if (indtsp !=
nullptr) {
9478 _industile_mngr.SetEntitySpec(indtsp.get());
9483 for (
auto &indsp : _industry_specs) {
9490 indsp.
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
9494 for (uint i = 0; i <
lengthof(indsp.produced_cargo); ++i) {
9502 for (
auto &indtsp : _industry_tile_specs) {
9518 for (
auto &objectspec : file->objectspec) {
9519 if (objectspec !=
nullptr && objectspec->grf_prop.grffile !=
nullptr && objectspec->IsEnabled()) {
9536 for (
auto &as : file->airportspec) {
9537 if (as !=
nullptr && as->
enabled) {
9538 _airport_mngr.SetEntitySpec(as.get());
9542 for (
auto &ats : file->airtspec) {
9543 if (ats !=
nullptr && ats->enabled) {
9544 _airporttile_mngr.SetEntitySpec(ats.get());
9556 static void DecodeSpecialSprite(
byte *buf, uint num, GrfLoadingStage stage)
9570 static const SpecialSpriteHandler handlers[][GLS_END] = {
9571 {
nullptr, SafeChangeInfo,
nullptr,
nullptr, ReserveChangeInfo, FeatureChangeInfo, },
9572 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
9573 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, NewSpriteGroup, },
9574 {
nullptr,
GRFUnsafe,
nullptr,
nullptr,
nullptr, FeatureMapSpriteGroup, },
9575 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, FeatureNewName, },
9576 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
9577 {
nullptr,
nullptr,
nullptr, CfgApply, CfgApply, CfgApply, },
9578 {
nullptr,
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, },
9579 { ScanInfo,
nullptr,
nullptr, GRFInfo, GRFInfo, GRFInfo, },
9580 {
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, SkipIf, },
9581 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
9582 {
nullptr,
nullptr,
nullptr, GRFLoadError, GRFLoadError, GRFLoadError, },
9583 {
nullptr,
nullptr,
nullptr, GRFComment,
nullptr, GRFComment, },
9585 {
nullptr, SafeGRFInhibit,
nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
9588 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
9591 {
StaticGRFInfo,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
9596 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
9597 if (it == _grf_line_to_action6_sprite_override.end()) {
9603 buf = _grf_line_to_action6_sprite_override[location].data();
9604 GrfMsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
9614 byte action = bufp->ReadByte();
9616 if (action == 0xFF) {
9617 GrfMsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
9618 }
else if (action == 0xFE) {
9619 GrfMsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
9620 }
else if (action >=
lengthof(handlers)) {
9621 GrfMsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x{:02X}", action);
9622 }
else if (handlers[action][stage] ==
nullptr) {
9623 GrfMsg(7,
"DecodeSpecialSprite: Skipping action 0x{:02X} in stage {}", action, stage);
9625 GrfMsg(7,
"DecodeSpecialSprite: Handling action 0x{:02X} in stage {}", action, stage);
9626 handlers[action][stage](bufp);
9629 GrfMsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
9645 Debug(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '{}'", config->
filename);
9648 if (grf_container_version == 0) {
9649 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9653 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
9659 if (grf_container_version >= 2) file.
ReadDword();
9662 if (grf_container_version >= 2) {
9664 byte compression = file.
ReadByte();
9665 if (compression != 0) {
9666 Debug(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
9675 if (num == 4 && file.
ReadByte() == 0xFF) {
9678 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9686 while ((num = (grf_container_version >= 2 ? file.
ReadDword() : file.
ReadWord())) != 0) {
9692 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
9703 GrfMsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
9704 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
9708 if (grf_container_version >= 2 && type == 0xFD) {
9731 const std::string &filename = config->
filename;
9742 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
9744 if (_cur.
grffile ==
nullptr) UserError(
"File '{}' lost in cache.\n", filename);
9751 SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
9805 DupSprite(SPR_ROAD_DEPOT + 0, SPR_TRAMWAY_DEPOT_NO_TRACK + 0);
9806 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 1, SPR_TRAMWAY_DEPOT_NO_TRACK + 1);
9807 DupSprite(SPR_ROAD_DEPOT + 2, SPR_TRAMWAY_DEPOT_NO_TRACK + 2);
9808 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 3, SPR_TRAMWAY_DEPOT_NO_TRACK + 3);
9809 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 4, SPR_TRAMWAY_DEPOT_NO_TRACK + 4);
9810 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 5, SPR_TRAMWAY_DEPOT_NO_TRACK + 5);
9821 static const uint32_t override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
9825 std::vector<int> grf_overrides(num_grfs, -1);
9826 for (
int i = 0; i < num_grfs; i++) {
9828 uint32_t
override = _grf_id_overrides[source->grfid];
9829 if (
override == 0)
continue;
9832 if (dest ==
nullptr)
continue;
9835 assert(grf_overrides[i] >= 0);
9839 for (
int i = 0; i < num_grfs; i++) {
9840 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
9848 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9851 Debug(grf, 3,
"'{}' overrides price base multiplier {} of '{}'", source->filename, p, dest->filename);
9857 for (
int i = num_grfs - 1; i >= 0; i--) {
9858 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9866 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9869 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, source->filename, dest->filename);
9875 for (
int i = 0; i < num_grfs; i++) {
9876 if (grf_overrides[i] < 0)
continue;
9884 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9885 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9887 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, dest->filename, source->filename);
9895 if (file->grf_version >= 8)
continue;
9896 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9897 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9899 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9902 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9909 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9910 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9911 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9913 price_base_multipliers[p] = 0;
9918 Debug(grf, 3,
"'{}' sets global price base multiplier {}", file->
filename, p);
9920 price_base_multipliers[p] = 0;
9922 Debug(grf, 3,
"'{}' sets local price base multiplier {}", file->
filename, p);
9937 _string_to_grf_mapping.clear();
9940 _grf_line_to_action6_sprite_override.clear();
10003 if (file ==
nullptr ||
_gted[e->
index].roadtramtype == 0) {
10012 if (
_gted[e->
index].roadtramtype < list->size())
10014 RoadTypeLabel rtl = (*list)[
_gted[e->
index].roadtramtype];
10043 _grm_sprites.clear();
10101 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
10108 if (stage == GLS_RESERVE) {
10109 static const uint32_t overrides[][2] = {
10110 { 0x44442202, 0x44440111 },
10111 { 0x6D620402, 0x6D620401 },
10112 { 0x4D656f20, 0x4D656F17 },
10114 for (
size_t i = 0; i <
lengthof(overrides); i++) {
10120 uint num_non_static = 0;
10122 _cur.
stage = stage;
10129 Debug(grf, 0,
"NewGRF file is missing '{}'; disabling", c->
filename);
10138 Debug(grf, 0,
"'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
10140 c->
error = {STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED};
10149 if (stage == GLS_RESERVE) {
10151 }
else if (stage == GLS_ACTIVATION) {
10156 Debug(sprite, 2,
"LoadNewGRF: Currently {} sprites are loaded", _cur.
spriteid);