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();
2644 template <
typename T>
2648 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
2652 translation_table.clear();
2653 for (
int i = 0; i < numinfo; i++) {
2654 translation_table.push_back(T(
BSWAP32(buf->ReadDWord())));
2669 for (
int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
2703 for (
int i = 0; i < numinfo; i++) {
2706 int factor = buf->ReadByte();
2707 uint price = gvid + i;
2709 if (price < PR_END) {
2712 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring", price);
2721 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2730 uint32_t rate = buf->ReadDWord();
2738 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
2745 uint16_t options = buf->ReadWord();
2754 GrfMsg(1,
"GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
2766 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2778 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2790 GrfMsg(1,
"GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
2797 GrfMsg(1,
"GlobalVarChangeInfo: The snowline can only be set once ({})", numinfo);
2799 GrfMsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf->Remaining());
2805 table[i][j] = buf->ReadByte();
2806 if (_cur.
grffile->grf_version >= 8) {
2809 if (table[i][j] >= 128) {
2831 uint curidx = gvid + i;
2833 if (lang ==
nullptr) {
2834 GrfMsg(1,
"GlobalVarChangeInfo: Language {} is not known, ignoring", curidx);
2839 while (buf->ReadByte() != 0) {
2849 uint plural_form = buf->ReadByte();
2850 if (plural_form >= LANGUAGE_MAX_PLURAL) {
2851 GrfMsg(1,
"GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form);
2858 byte newgrf_id = buf->ReadByte();
2859 while (newgrf_id != 0) {
2860 const char *name = buf->ReadString();
2875 GrfMsg(1,
"GlobalVarChangeInfo: Gender name {} is not known, ignoring", name);
2882 GrfMsg(1,
"GlobalVarChangeInfo: Case name {} is not known, ignoring", name);
2887 newgrf_id = buf->ReadByte();
2923 for (
int i = 0; i < numinfo; i++) {
2947 uint32_t s = buf->ReadDWord();
2948 uint32_t t = buf->ReadDWord();
2955 while (buf->ReadByte() != 0) {
2983 GrfMsg(2,
"CargoChangeInfo: Cargo type {} out of range (max {})", cid + numinfo,
NUM_CARGO - 1);
2987 for (
int i = 0; i < numinfo; i++) {
2992 cs->
bitnum = buf->ReadByte();
3031 cs->
sprite = buf->ReadWord();
3035 cs->
weight = buf->ReadByte();
3039 cs->transit_periods[0] = buf->ReadByte();
3043 cs->transit_periods[1] = buf->ReadByte();
3051 cs->rating_colour = buf->ReadByte();
3055 cs->legend_colour = buf->ReadByte();
3063 cs->
classes = buf->ReadWord();
3072 uint8_t substitute_type = buf->ReadByte();
3074 switch (substitute_type) {
3081 GrfMsg(1,
"CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type);
3097 cs->
multiplier = std::max<uint16_t>(1u, buf->ReadWord());
3101 uint8_t substitute_type = buf->ReadByte();
3103 switch (substitute_type) {
3107 GrfMsg(1,
"CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type);
3140 if (_cur.
grffile->sound_offset == 0) {
3141 GrfMsg(1,
"SoundEffectChangeInfo: No effects defined, skipping");
3146 GrfMsg(1,
"SoundEffectChangeInfo: Attempting to change undefined sound effect ({}), max ({}). Ignoring.", sid + numinfo,
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
3150 for (
int i = 0; i < numinfo; i++) {
3155 sound->volume = buf->ReadByte();
3159 sound->priority = buf->ReadByte();
3163 SoundID orig_sound = buf->ReadByte();
3166 GrfMsg(1,
"SoundEffectChangeInfo: Original sound {} not defined (max {})", orig_sound,
ORIGINAL_SAMPLE_COUNT);
3168 SoundEntry *old_sound = GetSound(orig_sound);
3171 *old_sound = *sound;
3213 buf->Skip(buf->ReadByte() * 2);
3236 GrfMsg(1,
"IndustryTilesChangeInfo: Too many industry tiles loaded ({}), max ({}). Ignoring.", indtid + numinfo,
NUM_INDUSTRYTILES_PER_GRF);
3241 if (_cur.
grffile->indtspec.size() < indtid + numinfo) _cur.
grffile->indtspec.resize(indtid + numinfo);
3243 for (
int i = 0; i < numinfo; i++) {
3246 if (prop != 0x08 && tsp ==
nullptr) {
3248 if (cir > ret) ret = cir;
3254 byte subs_id = buf->ReadByte();
3257 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to use new industry tile {} as substitute industry tile for {}. Ignoring.", subs_id, indtid + i);
3262 if (tsp ==
nullptr) {
3263 _cur.
grffile->indtspec[indtid + i] = std::make_unique<IndustryTileSpec>(_industry_tile_specs[subs_id]);
3264 tsp = _cur.
grffile->indtspec[indtid + i].get();
3283 byte ovrid = buf->ReadByte();
3287 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to override new industry tile {} with industry tile id {}. Ignoring.", ovrid, indtid + i);
3291 _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
3298 uint16_t acctp = buf->ReadWord();
3330 byte num_cargoes = buf->ReadByte();
3331 if (num_cargoes > std::size(tsp->
acceptance)) {
3336 for (uint i = 0; i < std::size(tsp->
acceptance); i++) {
3337 if (i < num_cargoes) {
3340 tsp->
acceptance[i] = (int8_t)buf->ReadByte();
3404 byte num_table = buf->ReadByte();
3405 for (
byte j = 0; j < num_table; j++) {
3406 for (uint k = 0;; k++) {
3407 byte x = buf->ReadByte();
3408 if (x == 0xFE && k == 0) {
3414 byte y = buf->ReadByte();
3415 if (x == 0 && y == 0x80)
break;
3417 byte gfx = buf->ReadByte();
3418 if (gfx == 0xFE) buf->ReadWord();
3425 for (
byte j = 0; j < 3; j++) buf->ReadByte();
3432 buf->Skip(buf->ReadByte());
3436 int num_inputs = buf->ReadByte();
3437 int num_outputs = buf->ReadByte();
3438 buf->Skip(num_inputs * num_outputs * 2);
3456 const size_t size = layout.size();
3457 if (size == 0)
return false;
3459 for (
size_t i = 0; i < size - 1; i++) {
3460 for (
size_t j = i + 1; j < size; j++) {
3461 if (layout[i].ti.x == layout[j].ti.x &&
3462 layout[i].ti.y == layout[j].ti.y) {
3468 bool have_regular_tile =
false;
3469 for (
const auto &tilelayout : layout) {
3471 have_regular_tile =
true;
3476 return have_regular_tile;
3492 GrfMsg(1,
"IndustriesChangeInfo: Too many industries loaded ({}), max ({}). Ignoring.", indid + numinfo,
NUM_INDUSTRYTYPES_PER_GRF);
3497 if (_cur.
grffile->industryspec.size() < indid + numinfo) _cur.
grffile->industryspec.resize(indid + numinfo);
3499 for (
int i = 0; i < numinfo; i++) {
3502 if (prop != 0x08 && indsp ==
nullptr) {
3504 if (cir > ret) ret = cir;
3510 byte subs_id = buf->ReadByte();
3511 if (subs_id == 0xFF) {
3514 _industry_specs[indid + i].
enabled =
false;
3518 GrfMsg(2,
"_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id, indid + i);
3525 if (indsp ==
nullptr) {
3526 _cur.
grffile->industryspec[indid + i] = std::make_unique<IndustrySpec>(_origin_industry_specs[subs_id]);
3527 indsp = _cur.
grffile->industryspec[indid + i].get();
3531 indsp->
grf_prop.subst_id = subs_id;
3541 byte ovrid = buf->ReadByte();
3545 GrfMsg(2,
"IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid, indid + i);
3549 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3554 byte new_num_layouts = buf->ReadByte();
3555 uint32_t definition_size = buf->ReadDWord();
3556 uint32_t bytes_read = 0;
3557 std::vector<IndustryTileLayout> new_layouts;
3560 for (
byte j = 0; j < new_num_layouts; j++) {
3563 for (uint k = 0;; k++) {
3564 if (bytes_read >= definition_size) {
3565 GrfMsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.", indid);
3567 definition_size = UINT32_MAX;
3573 it.ti.
x = buf->ReadByte();
3576 if (it.ti.
x == 0xFE && k == 0) {
3578 IndustryType type = buf->ReadByte();
3579 byte laynbr = buf->ReadByte();
3582 if (type >=
lengthof(_origin_industry_specs)) {
3583 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry {}", indid);
3587 if (laynbr >= _origin_industry_specs[type].layouts.size()) {
3588 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}", indid);
3592 layout = _origin_industry_specs[type].layouts[laynbr];
3596 it.ti.
y = buf->ReadByte();
3599 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
3605 it.gfx = buf->ReadByte();
3608 if (it.gfx == 0xFE) {
3610 int local_tile_id = buf->ReadWord();
3614 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3617 GrfMsg(2,
"IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id, indid);
3623 it.ti.
x = (int8_t)
GB(it.ti.
x, 0, 8);
3624 it.ti.
y = (int8_t)
GB(it.ti.
y, 0, 8);
3633 if (_cur.
grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
3639 GrfMsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring", indid);
3643 new_layouts.push_back(layout);
3673 for (
byte j = 0; j < 2; j++) {
3680 for (
byte j = 0; j < 3; j++) {
3689 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3702 sounds[j] = buf->ReadByte();
3718 for (
byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3744 uint32_t multiples = buf->ReadDWord();
3760 byte aflag = buf->ReadByte();
3770 uint16_t str = buf->ReadWord();
3780 byte num_cargoes = buf->ReadByte();
3781 if (num_cargoes >
lengthof(indsp->produced_cargo)) {
3786 for (uint i = 0; i <
lengthof(indsp->produced_cargo); i++) {
3787 if (i < num_cargoes) {
3789 indsp->produced_cargo[i] = cargo;
3791 indsp->produced_cargo[i] = INVALID_CARGO;
3798 byte num_cargoes = buf->ReadByte();
3805 if (i < num_cargoes) {
3816 byte num_cargoes = buf->ReadByte();
3817 if (num_cargoes >
lengthof(indsp->production_rate)) {
3822 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
3823 if (i < num_cargoes) {
3824 indsp->production_rate[i] = buf->ReadByte();
3826 indsp->production_rate[i] = 0;
3833 byte num_inputs = buf->ReadByte();
3834 byte num_outputs = buf->ReadByte();
3841 for (uint j = 0; j <
lengthof(indsp->produced_cargo); j++) {
3843 if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
3867 for (
int i = 0; i < as->
num_table; i++) {
3872 }
while ((++it)->ti.x != -0x80);
3873 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3876 as->
table = table_list;
3898 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3903 if (_cur.
grffile->airportspec.size() < airport + numinfo) _cur.
grffile->airportspec.resize(airport + numinfo);
3905 for (
int i = 0; i < numinfo; i++) {
3908 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
3909 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring", airport + i);
3915 byte subs_id = buf->ReadByte();
3916 if (subs_id == 0xFF) {
3923 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id, airport + i);
3930 if (as ==
nullptr) {
3932 as = _cur.
grffile->airportspec[airport + i].get();
3939 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3951 uint32_t defsize = buf->ReadDWord();
3957 for (
byte j = 0; j < as->
num_table; j++) {
3959 for (
int k = 0;; k++) {
3960 att[k].
ti.
x = buf->ReadByte();
3961 att[k].
ti.
y = buf->ReadByte();
3963 if (att[k].ti.x == 0 && att[k].
ti.
y == 0x80) {
3966 att[k].
ti.
x = -0x80;
3975 att[k].
gfx = buf->ReadByte();
3977 if (att[k].gfx == 0xFE) {
3979 int local_tile_id = buf->ReadWord();
3982 uint16_t tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3985 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id, airport + i);
3988 att[k].
gfx = tempid;
3990 }
else if (att[k].gfx == 0xFF) {
3991 att[k].
ti.
x = (int8_t)
GB(att[k].ti.x, 0, 8);
3992 att[k].
ti.
y = (int8_t)
GB(att[k].ti.y, 0, 8);
4003 tile_table[j] = CallocT<AirportTileTable>(size);
4004 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
4007 for (
int j = 0; j < old_num_table; j++) {
4013 as->
table = tile_table;
4016 for (
int i = 0; i < as->
num_table; i++) {
4017 free(tile_table[i]);
4119 GrfMsg(1,
"ObjectChangeInfo: Too many objects loaded ({}), max ({}). Ignoring.",
id + numinfo,
NUM_OBJECTS_PER_GRF);
4124 if (_cur.
grffile->objectspec.size() <
id + numinfo) _cur.
grffile->objectspec.resize(
id + numinfo);
4126 for (
int i = 0; i < numinfo; i++) {
4129 if (prop != 0x08 && spec ==
nullptr) {
4132 if (cir > ret) ret = cir;
4139 if (spec ==
nullptr) {
4140 _cur.
grffile->objectspec[
id + i] = std::make_unique<ObjectSpec>();
4141 spec = _cur.
grffile->objectspec[
id + i].get();
4147 uint32_t classid = buf->ReadDWord();
4163 spec->
climate = buf->ReadByte();
4167 spec->
size = buf->ReadByte();
4168 if (
GB(spec->
size, 0, 4) == 0 ||
GB(spec->
size, 4, 4) == 0) {
4169 GrfMsg(0,
"ObjectChangeInfo: Invalid object size requested (0x{:X}) for object id {}. Ignoring.", spec->
size,
id + i);
4214 spec->
height = buf->ReadByte();
4218 spec->
views = buf->ReadByte();
4220 GrfMsg(2,
"ObjectChangeInfo: Invalid number of views ({}) for object id {}. Ignoring.", spec->
views,
id + i);
4253 GrfMsg(1,
"RailTypeChangeInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4257 for (
int i = 0; i < numinfo; i++) {
4270 uint16_t str = buf->ReadWord();
4272 if (_cur.
grffile->grf_version < 8) {
4302 int n = buf->ReadByte();
4303 for (
int j = 0; j != n; j++) {
4304 RailTypeLabel label = buf->ReadDWord();
4364 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4383 GrfMsg(1,
"RailTypeReserveInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4387 for (
int i = 0; i < numinfo; i++) {
4391 RailTypeLabel rtl = buf->ReadDWord();
4400 _cur.
grffile->railtype_map[
id + i] = rt;
4418 int n = buf->ReadByte();
4419 for (
int j = 0; j != n; j++) {
4424 GrfMsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set",
id + i);
4431 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4472 GrfMsg(1,
"RoadTypeChangeInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4476 for (
int i = 0; i < numinfo; i++) {
4489 uint16_t str = buf->ReadWord();
4516 int n = buf->ReadByte();
4517 for (
int j = 0; j != n; j++) {
4518 RoadTypeLabel label = buf->ReadDWord();
4523 if (GetRoadTramType(resolved_rt) == rtt) {
4526 GrfMsg(1,
"RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt);
4571 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4602 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4606 for (
int i = 0; i < numinfo; i++) {
4609 RoadTypeLabel rtl = buf->ReadDWord();
4616 }
else if (GetRoadTramType(rt) != rtt) {
4617 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid type (road/tram), ignoring",
id + numinfo);
4621 type_map[
id + i] = rt;
4638 int n = buf->ReadByte();
4639 for (
int j = 0; j != n; j++) {
4644 GrfMsg(1,
"RoadTypeReserveInfo: Ignoring property 1D for road type {} because no label was set",
id + i);
4650 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4674 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_ROAD);
4679 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_TRAM);
4687 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", airtid + numinfo,
NUM_AIRPORTTILES_PER_GRF);
4692 if (_cur.
grffile->airtspec.size() < airtid + numinfo) _cur.
grffile->airtspec.resize(airtid + numinfo);
4694 for (
int i = 0; i < numinfo; i++) {
4697 if (prop != 0x08 && tsp ==
nullptr) {
4698 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.", airtid + i);
4704 byte subs_id = buf->ReadByte();
4707 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id, airtid + i);
4712 if (tsp ==
nullptr) {
4714 tsp = _cur.
grffile->airtspec[airtid + i].get();
4729 byte override = buf->ReadByte();
4733 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.",
override, airtid + i);
4737 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4812 GrfMsg(1,
"RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring",
id + numinfo,
NUM_ROADSTOPS_PER_GRF);
4816 if (_cur.
grffile->roadstops.size() <
id + numinfo) _cur.
grffile->roadstops.resize(
id + numinfo);
4818 for (
int i = 0; i < numinfo; i++) {
4821 if (rs ==
nullptr && prop != 0x08) {
4822 GrfMsg(1,
"RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring",
id + i);
4824 if (cir > ret) ret = cir;
4830 if (rs ==
nullptr) {
4831 _cur.
grffile->roadstops[
id + i] = std::make_unique<RoadStopSpec>();
4832 rs = _cur.
grffile->roadstops[
id + i].get();
4835 uint32_t classid = buf->ReadDWord();
4862 rs->animation.
frames = buf->ReadByte();
4863 rs->animation.
status = buf->ReadByte();
4867 rs->animation.
speed = buf->ReadByte();
4871 rs->animation.
triggers = buf->ReadWord();
4875 rs->callback_mask = buf->ReadByte();
4879 rs->flags = (uint8_t)buf->ReadDWord();
4896 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property)
4899 default: NOT_REACHED();
4909 GrfMsg(1,
"{}: Ignoring property 0x{:02X} of feature 0x{:02X} (not implemented)", caller, property, feature);
4913 GrfMsg(0,
"{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature);
4926 static void FeatureChangeInfo(
ByteReader *buf)
4939 static const VCI_Handler handler[] = {
4957 AirportTilesChangeInfo,
4962 static_assert(GSF_END ==
lengthof(handler));
4964 uint8_t feature = buf->ReadByte();
4965 uint8_t numprops = buf->ReadByte();
4966 uint numinfo = buf->ReadByte();
4967 uint engine = buf->ReadExtendedByte();
4969 if (feature >= GSF_END) {
4970 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4974 GrfMsg(6,
"FeatureChangeInfo: Feature 0x{:02X}, {} properties, to apply to {}+{}",
4975 feature, numprops, engine, numinfo);
4977 if (handler[feature] ==
nullptr) {
4978 if (feature != GSF_CARGOES) GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4985 while (numprops-- && buf->HasData()) {
4986 uint8_t prop = buf->ReadByte();
4989 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
4996 uint8_t feature = buf->ReadByte();
4997 uint8_t numprops = buf->ReadByte();
4998 uint numinfo = buf->ReadByte();
4999 buf->ReadExtendedByte();
5001 if (feature == GSF_BRIDGES && numprops == 1) {
5002 uint8_t prop = buf->ReadByte();
5005 if (prop == 0x0D)
return;
5006 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
5007 uint8_t prop = buf->ReadByte();
5010 bool is_safe =
true;
5011 for (uint i = 0; i < numinfo; i++) {
5012 uint32_t s = buf->ReadDWord();
5020 if (is_safe)
return;
5031 static void ReserveChangeInfo(
ByteReader *buf)
5033 uint8_t feature = buf->ReadByte();
5035 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES && feature != GSF_ROADTYPES && feature != GSF_TRAMTYPES)
return;
5037 uint8_t numprops = buf->ReadByte();
5038 uint8_t numinfo = buf->ReadByte();
5039 uint8_t index = buf->ReadExtendedByte();
5041 while (numprops-- && buf->HasData()) {
5042 uint8_t prop = buf->ReadByte();
5046 default: NOT_REACHED();
5052 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
5056 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
5060 cir = RoadTypeReserveInfo(index, numinfo, prop, buf);
5064 cir = TramTypeReserveInfo(index, numinfo, prop, buf);
5068 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
5089 uint8_t feature = buf->ReadByte();
5090 uint16_t num_sets = buf->ReadByte();
5091 uint16_t first_set = 0;
5093 if (num_sets == 0 && buf->HasData(3)) {
5096 first_set = buf->ReadExtendedByte();
5097 num_sets = buf->ReadExtendedByte();
5099 uint16_t num_ents = buf->ReadExtendedByte();
5101 if (feature >= GSF_END) {
5103 GrfMsg(1,
"NewSpriteSet: Unsupported feature 0x{:02X}, skipping {} sprites", feature, _cur.
skip_sprites);
5109 GrfMsg(7,
"New sprite set at {} of feature 0x{:02X}, consisting of {} sets with {} views each (total {})",
5110 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
5113 for (
int i = 0; i < num_sets * num_ents; i++) {
5123 uint16_t num_sets = buf->ReadByte();
5125 if (num_sets == 0 && buf->HasData(3)) {
5128 buf->ReadExtendedByte();
5129 num_sets = buf->ReadExtendedByte();
5131 uint16_t num_ents = buf->ReadExtendedByte();
5135 GrfMsg(3,
"SkipAct1: Skipping {} sprites", _cur.
skip_sprites);
5140 static const SpriteGroup *GetGroupFromGroupID(
byte setid,
byte type, uint16_t groupid)
5142 if (
HasBit(groupid, 15)) {
5147 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5148 GrfMsg(1,
"GetGroupFromGroupID(0x{:02X}:0x{:02X}): Groupid 0x{:04X} does not exist, leaving empty", setid, type, groupid);
5152 return _cur.spritegroups[groupid];
5165 if (
HasBit(spriteid, 15)) {
5171 GrfMsg(1,
"CreateGroupFromGroupID(0x{:02X}:0x{:02X}): Sprite set {} invalid", setid, type, spriteid);
5176 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
5179 assert(spriteset_start + num_sprites <= _cur.
spriteid);
5200 uint8_t feature = buf->ReadByte();
5201 if (feature >= GSF_END) {
5202 GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5206 uint8_t setid = buf->ReadByte();
5207 uint8_t type = buf->ReadByte();
5231 switch (
GB(type, 2, 2)) {
5232 default: NOT_REACHED();
5233 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
5234 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
5235 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
5245 adjust.variable = buf->ReadByte();
5246 if (adjust.variable == 0x7E) {
5248 adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
5253 varadjust = buf->ReadByte();
5254 adjust.shift_num =
GB(varadjust, 0, 5);
5255 adjust.type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
5256 adjust.and_mask = buf->ReadVarSize(varsize);
5258 if (adjust.type != DSGA_TYPE_NONE) {
5259 adjust.add_val = buf->ReadVarSize(varsize);
5260 adjust.divmod_val = buf->ReadVarSize(varsize);
5263 adjust.divmod_val = 0;
5267 }
while (
HasBit(varadjust, 5));
5269 std::vector<DeterministicSpriteGroupRange> ranges;
5270 ranges.resize(buf->ReadByte());
5271 for (uint i = 0; i < ranges.size(); i++) {
5272 ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5273 ranges[i].low = buf->ReadVarSize(varsize);
5274 ranges[i].high = buf->ReadVarSize(varsize);
5277 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5278 group->error_group = ranges.empty() ? group->default_group : ranges[0].group;
5280 group->calculated_result = ranges.empty();
5283 std::vector<uint32_t> bounds;
5284 for (uint i = 0; i < ranges.size(); i++) {
5285 bounds.push_back(ranges[i].low);
5286 if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1);
5288 std::sort(bounds.begin(), bounds.end());
5289 bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
5291 std::vector<const SpriteGroup *> target;
5292 for (uint j = 0; j < bounds.size(); ++j) {
5293 uint32_t v = bounds[j];
5295 for (uint i = 0; i < ranges.size(); i++) {
5296 if (ranges[i].low <= v && v <= ranges[i].high) {
5297 t = ranges[i].group;
5301 target.push_back(t);
5303 assert(target.size() == bounds.size());
5305 for (uint j = 0; j < bounds.size(); ) {
5306 if (target[j] != group->default_group) {
5308 r.group = target[j];
5310 while (j < bounds.size() && target[j] == r.group) {
5313 r.high = j < bounds.size() ? bounds[j] - 1 : UINT32_MAX;
5335 group->count = buf->ReadByte();
5338 uint8_t triggers = buf->ReadByte();
5339 group->triggers =
GB(triggers, 0, 7);
5340 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
5343 byte num_groups = buf->ReadByte();
5345 GrfMsg(1,
"NewSpriteGroup: Random Action 2 nrand should be power of 2");
5348 for (uint i = 0; i < num_groups; i++) {
5349 group->
groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
5360 case GSF_ROADVEHICLES:
5371 byte num_loaded = type;
5372 byte num_loading = buf->ReadByte();
5375 GrfMsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
5379 GrfMsg(6,
"NewSpriteGroup: New SpriteGroup 0x{:02X}, {} loaded, {} loading",
5380 setid, num_loaded, num_loading);
5382 if (num_loaded + num_loading == 0) {
5383 GrfMsg(1,
"NewSpriteGroup: no result, skipping invalid RealSpriteGroup");
5387 if (num_loaded + num_loading == 1) {
5389 uint16_t spriteid = buf->ReadWord();
5391 GrfMsg(8,
"NewSpriteGroup: one result, skipping RealSpriteGroup = subset {}", spriteid);
5395 std::vector<uint16_t> loaded;
5396 std::vector<uint16_t> loading;
5398 for (uint i = 0; i < num_loaded; i++) {
5399 loaded.push_back(buf->ReadWord());
5400 GrfMsg(8,
"NewSpriteGroup: + rg->loaded[{}] = subset {}", i, loaded[i]);
5403 for (uint i = 0; i < num_loading; i++) {
5404 loading.push_back(buf->ReadWord());
5405 GrfMsg(8,
"NewSpriteGroup: + rg->loading[{}] = subset {}", i, loading[i]);
5408 if (std::adjacent_find(loaded.begin(), loaded.end(), std::not_equal_to<>()) == loaded.end() &&
5409 std::adjacent_find(loading.begin(), loading.end(), std::not_equal_to<>()) == loading.end() &&
5410 loaded[0] == loading[0])
5414 GrfMsg(8,
"NewSpriteGroup: same result, skipping RealSpriteGroup = subset {}", loaded[0]);
5423 for (uint16_t spriteid : loaded) {
5425 group->
loaded.push_back(t);
5428 for (uint16_t spriteid : loading) {
5437 case GSF_AIRPORTTILES:
5439 case GSF_INDUSTRYTILES:
5440 case GSF_ROADSTOPS: {
5441 byte num_building_sprites = std::max((uint8_t)1, type);
5449 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
5453 case GSF_INDUSTRIES: {
5455 GrfMsg(1,
"NewSpriteGroup: Unsupported industry production version {}, skipping", type);
5466 for (uint i = 0; i < 3; i++) {
5470 for (uint i = 0; i < 2; i++) {
5473 group->again = buf->ReadByte();
5474 }
else if (type == 1) {
5476 for (uint i = 0; i < 3; i++) {
5480 for (uint i = 0; i < 2; i++) {
5483 group->again = buf->ReadByte();
5484 }
else if (type == 2) {
5488 error->
data =
"too many inputs (max 16)";
5491 for (uint i = 0; i < group->
num_input; i++) {
5492 byte rawcargo = buf->ReadByte();
5501 error->
data =
"duplicate input cargo";
5510 error->
data =
"too many outputs (max 16)";
5513 for (uint i = 0; i < group->
num_output; i++) {
5514 byte rawcargo = buf->ReadByte();
5521 error->
data =
"duplicate output cargo";
5527 group->again = buf->ReadByte();
5535 default: GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5540 _cur.spritegroups[setid] = act_group;
5543 static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
5552 GrfMsg(1,
"TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
5553 return INVALID_CARGO;
5557 if (cs->bitnum == ctype) {
5558 GrfMsg(6,
"TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index());
5563 GrfMsg(5,
"TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype);
5564 return INVALID_CARGO;
5569 GrfMsg(1,
"TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (
unsigned int)_cur.
grffile->
cargo_list.size() - 1);
5570 return INVALID_CARGO;
5576 GrfMsg(5,
"TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
5577 return INVALID_CARGO;
5580 CargoID cid = GetCargoIDByLabel(cl);
5582 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));
5583 return INVALID_CARGO;
5586 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);
5591 static bool IsValidGroupID(uint16_t groupid,
const char *
function)
5593 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5594 GrfMsg(1,
"{}: Spritegroup 0x{:04X} out of range or empty, skipping.",
function, groupid);
5601 static void VehicleMapSpriteGroup(
ByteReader *buf,
byte feature, uint8_t idcount)
5604 static uint last_engines_count;
5605 bool wagover =
false;
5608 if (
HasBit(idcount, 7)) {
5611 idcount =
GB(idcount, 0, 7);
5613 if (last_engines_count == 0) {
5614 GrfMsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
5618 GrfMsg(6,
"VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons",
5619 last_engines_count, idcount);
5621 if (last_engines_count != idcount) {
5622 last_engines =
ReallocT(last_engines, idcount);
5623 last_engines_count = idcount;
5627 std::vector<EngineID> engines;
5628 for (uint i = 0; i < idcount; i++) {
5634 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
5638 engines.push_back(e->
index);
5639 if (!wagover) last_engines[i] = engines[i];
5642 uint8_t cidcount = buf->ReadByte();
5643 for (uint c = 0; c < cidcount; c++) {
5644 uint8_t ctype = buf->ReadByte();
5645 uint16_t groupid = buf->ReadWord();
5646 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
5648 GrfMsg(8,
"VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
5650 CargoID cid = TranslateCargo(feature, ctype);
5653 for (uint i = 0; i < idcount; i++) {
5656 GrfMsg(7,
"VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
5659 SetWagonOverrideSprites(engine, cid, _cur.spritegroups[groupid], last_engines, last_engines_count);
5661 SetCustomEngineSprites(engine, cid, _cur.spritegroups[groupid]);
5666 uint16_t groupid = buf->ReadWord();
5667 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
5669 GrfMsg(8,
"-- Default group id 0x{:04X}", groupid);
5671 for (uint i = 0; i < idcount; i++) {
5684 static void CanalMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5686 std::vector<uint16_t> cfs;
5687 cfs.reserve(idcount);
5688 for (uint i = 0; i < idcount; i++) {
5689 cfs.push_back(buf->ReadExtendedByte());
5692 uint8_t cidcount = buf->ReadByte();
5693 buf->Skip(cidcount * 3);
5695 uint16_t groupid = buf->ReadWord();
5696 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
5698 for (
auto &cf : cfs) {
5700 GrfMsg(1,
"CanalMapSpriteGroup: Canal subset {} out of range, skipping", cf);
5710 static void StationMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5712 if (_cur.
grffile->stations.empty()) {
5713 GrfMsg(1,
"StationMapSpriteGroup: No stations defined, skipping");
5717 std::vector<uint16_t> stations;
5718 stations.reserve(idcount);
5719 for (uint i = 0; i < idcount; i++) {
5720 stations.push_back(buf->ReadExtendedByte());
5723 uint8_t cidcount = buf->ReadByte();
5724 for (uint c = 0; c < cidcount; c++) {
5725 uint8_t ctype = buf->ReadByte();
5726 uint16_t groupid = buf->ReadWord();
5727 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5729 ctype = TranslateCargo(GSF_STATIONS, ctype);
5732 for (
auto &station : stations) {
5735 if (statspec ==
nullptr) {
5736 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5744 uint16_t groupid = buf->ReadWord();
5745 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5747 for (
auto &station : stations) {
5750 if (statspec ==
nullptr) {
5751 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5756 GrfMsg(1,
"StationMapSpriteGroup: Station {} mapped multiple times, skipping", station);
5763 StationClass::Assign(statspec);
5768 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5770 if (_cur.
grffile->housespec.empty()) {
5771 GrfMsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5775 std::vector<uint16_t> houses;
5776 houses.reserve(idcount);
5777 for (uint i = 0; i < idcount; i++) {
5778 houses.push_back(buf->ReadExtendedByte());
5782 uint8_t cidcount = buf->ReadByte();
5783 buf->Skip(cidcount * 3);
5785 uint16_t groupid = buf->ReadWord();
5786 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5788 for (
auto &house : houses) {
5791 if (hs ==
nullptr) {
5792 GrfMsg(1,
"TownHouseMapSpriteGroup: House {} undefined, skipping.", house);
5800 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5802 if (_cur.
grffile->industryspec.empty()) {
5803 GrfMsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5807 std::vector<uint16_t> industries;
5808 industries.reserve(idcount);
5809 for (uint i = 0; i < idcount; i++) {
5810 industries.push_back(buf->ReadExtendedByte());
5814 uint8_t cidcount = buf->ReadByte();
5815 buf->Skip(cidcount * 3);
5817 uint16_t groupid = buf->ReadWord();
5818 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5820 for (
auto &industry : industries) {
5823 if (indsp ==
nullptr) {
5824 GrfMsg(1,
"IndustryMapSpriteGroup: Industry {} undefined, skipping", industry);
5832 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5834 if (_cur.
grffile->indtspec.empty()) {
5835 GrfMsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5839 std::vector<uint16_t> indtiles;
5840 indtiles.reserve(idcount);
5841 for (uint i = 0; i < idcount; i++) {
5842 indtiles.push_back(buf->ReadExtendedByte());
5846 uint8_t cidcount = buf->ReadByte();
5847 buf->Skip(cidcount * 3);
5849 uint16_t groupid = buf->ReadWord();
5850 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5852 for (
auto &indtile : indtiles) {
5855 if (indtsp ==
nullptr) {
5856 GrfMsg(1,
"IndustrytileMapSpriteGroup: Industry tile {} undefined, skipping", indtile);
5864 static void CargoMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5866 std::vector<uint16_t> cargoes;
5867 cargoes.reserve(idcount);
5868 for (uint i = 0; i < idcount; i++) {
5869 cargoes.push_back(buf->ReadExtendedByte());
5873 uint8_t cidcount = buf->ReadByte();
5874 buf->Skip(cidcount * 3);
5876 uint16_t groupid = buf->ReadWord();
5877 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5879 for (
auto &cid : cargoes) {
5881 GrfMsg(1,
"CargoMapSpriteGroup: Cargo ID {} out of range, skipping", cid);
5887 cs->group = _cur.spritegroups[groupid];
5891 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5893 if (_cur.
grffile->objectspec.empty()) {
5894 GrfMsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5898 std::vector<uint16_t> objects;
5899 objects.reserve(idcount);
5900 for (uint i = 0; i < idcount; i++) {
5901 objects.push_back(buf->ReadExtendedByte());
5904 uint8_t cidcount = buf->ReadByte();
5905 for (uint c = 0; c < cidcount; c++) {
5906 uint8_t ctype = buf->ReadByte();
5907 uint16_t groupid = buf->ReadWord();
5908 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5911 if (ctype != 0xFF) {
5912 GrfMsg(1,
"ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype);
5916 for (
auto &
object : objects) {
5919 if (spec ==
nullptr) {
5920 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5928 uint16_t groupid = buf->ReadWord();
5929 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5931 for (
auto &
object : objects) {
5934 if (spec ==
nullptr) {
5935 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5940 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} mapped multiple times, skipping",
object);
5950 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5952 std::vector<uint8_t> railtypes;
5953 railtypes.reserve(idcount);
5954 for (uint i = 0; i < idcount; i++) {
5955 uint16_t
id = buf->ReadExtendedByte();
5956 railtypes.push_back(id < RAILTYPE_END ? _cur.grffile->railtype_map[
id] :
INVALID_RAILTYPE);
5959 uint8_t cidcount = buf->ReadByte();
5960 for (uint c = 0; c < cidcount; c++) {
5961 uint8_t ctype = buf->ReadByte();
5962 uint16_t groupid = buf->ReadWord();
5963 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5965 if (ctype >= RTSG_END)
continue;
5968 for (
auto &railtype : railtypes) {
5973 rti->
group[ctype] = _cur.spritegroups[groupid];
5982 static void RoadTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount, RoadTramType rtt)
5986 std::vector<uint8_t> roadtypes;
5987 roadtypes.reserve(idcount);
5988 for (uint i = 0; i < idcount; i++) {
5989 uint16_t
id = buf->ReadExtendedByte();
5993 uint8_t cidcount = buf->ReadByte();
5994 for (uint c = 0; c < cidcount; c++) {
5995 uint8_t ctype = buf->ReadByte();
5996 uint16_t groupid = buf->ReadWord();
5997 if (!IsValidGroupID(groupid,
"RoadTypeMapSpriteGroup"))
continue;
5999 if (ctype >= ROTSG_END)
continue;
6002 for (
auto &roadtype : roadtypes) {
6007 rti->
group[ctype] = _cur.spritegroups[groupid];
6016 static void AirportMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6018 if (_cur.
grffile->airportspec.empty()) {
6019 GrfMsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
6023 std::vector<uint16_t> airports;
6024 airports.reserve(idcount);
6025 for (uint i = 0; i < idcount; i++) {
6026 airports.push_back(buf->ReadExtendedByte());
6030 uint8_t cidcount = buf->ReadByte();
6031 buf->Skip(cidcount * 3);
6033 uint16_t groupid = buf->ReadWord();
6034 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
6036 for (
auto &airport : airports) {
6039 if (as ==
nullptr) {
6040 GrfMsg(1,
"AirportMapSpriteGroup: Airport {} undefined, skipping", airport);
6048 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6050 if (_cur.
grffile->airtspec.empty()) {
6051 GrfMsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
6055 std::vector<uint16_t> airptiles;
6056 airptiles.reserve(idcount);
6057 for (uint i = 0; i < idcount; i++) {
6058 airptiles.push_back(buf->ReadExtendedByte());
6062 uint8_t cidcount = buf->ReadByte();
6063 buf->Skip(cidcount * 3);
6065 uint16_t groupid = buf->ReadWord();
6066 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
6068 for (
auto &airptile : airptiles) {
6071 if (airtsp ==
nullptr) {
6072 GrfMsg(1,
"AirportTileMapSpriteGroup: Airport tile {} undefined, skipping", airptile);
6080 static void RoadStopMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6082 if (_cur.
grffile->roadstops.empty()) {
6083 GrfMsg(1,
"RoadStopMapSpriteGroup: No roadstops defined, skipping");
6087 std::vector<uint16_t> roadstops;
6088 roadstops.reserve(idcount);
6089 for (uint i = 0; i < idcount; i++) {
6090 roadstops.push_back(buf->ReadExtendedByte());
6093 uint8_t cidcount = buf->ReadByte();
6094 for (uint c = 0; c < cidcount; c++) {
6095 uint8_t ctype = buf->ReadByte();
6096 uint16_t groupid = buf->ReadWord();
6097 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
continue;
6099 ctype = TranslateCargo(GSF_ROADSTOPS, ctype);
6102 for (
auto &roadstop : roadstops) {
6105 if (roadstopspec ==
nullptr) {
6106 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping", roadstop);
6114 uint16_t groupid = buf->ReadWord();
6115 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
return;
6117 for (
auto &roadstop : roadstops) {
6120 if (roadstopspec ==
nullptr) {
6121 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping.", roadstop);
6126 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} mapped multiple times, skipping", roadstop);
6133 RoadStopClass::Assign(roadstopspec);
6138 static void FeatureMapSpriteGroup(
ByteReader *buf)
6154 uint8_t feature = buf->ReadByte();
6155 uint8_t idcount = buf->ReadByte();
6157 if (feature >= GSF_END) {
6158 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6166 uint16_t groupid = buf->ReadWord();
6167 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
6169 GrfMsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature 0x{:02X}", feature);
6178 GrfMsg(6,
"FeatureMapSpriteGroup: Feature 0x{:02X}, {} ids", feature, idcount);
6182 case GSF_ROADVEHICLES:
6185 VehicleMapSpriteGroup(buf, feature, idcount);
6189 CanalMapSpriteGroup(buf, idcount);
6193 StationMapSpriteGroup(buf, idcount);
6197 TownHouseMapSpriteGroup(buf, idcount);
6200 case GSF_INDUSTRIES:
6201 IndustryMapSpriteGroup(buf, idcount);
6204 case GSF_INDUSTRYTILES:
6205 IndustrytileMapSpriteGroup(buf, idcount);
6209 CargoMapSpriteGroup(buf, idcount);
6213 AirportMapSpriteGroup(buf, idcount);
6217 ObjectMapSpriteGroup(buf, idcount);
6221 RailTypeMapSpriteGroup(buf, idcount);
6225 RoadTypeMapSpriteGroup(buf, idcount, RTT_ROAD);
6229 RoadTypeMapSpriteGroup(buf, idcount, RTT_TRAM);
6232 case GSF_AIRPORTTILES:
6233 AirportTileMapSpriteGroup(buf, idcount);
6237 RoadStopMapSpriteGroup(buf, idcount);
6241 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6265 bool new_scheme = _cur.
grffile->grf_version >= 7;
6267 uint8_t feature = buf->ReadByte();
6268 if (feature >= GSF_END && feature != 0x48) {
6269 GrfMsg(1,
"FeatureNewName: Unsupported feature 0x{:02X}, skipping", feature);
6273 uint8_t lang = buf->ReadByte();
6274 uint8_t num = buf->ReadByte();
6275 bool generic =
HasBit(lang, 7);
6278 id = buf->ReadWord();
6279 }
else if (feature <= GSF_AIRCRAFT) {
6280 id = buf->ReadExtendedByte();
6282 id = buf->ReadByte();
6287 uint16_t endid =
id + num;
6289 GrfMsg(6,
"FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
6290 id, endid, feature, lang);
6292 for (;
id < endid && buf->HasData();
id++) {
6293 const char *name = buf->ReadString();
6294 GrfMsg(8,
"FeatureNewName: 0x{:04X} <- {}",
id, name);
6298 case GSF_ROADVEHICLES:
6303 if (e ==
nullptr)
break;
6317 switch (
GB(
id, 8, 8)) {
6319 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6320 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6328 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6329 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6336 if (
GB(
id, 0, 8) >= _cur.
grffile->airtspec.size() || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
6337 GrfMsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring",
GB(
id, 0, 8));
6344 if (
GB(
id, 0, 8) >= _cur.
grffile->housespec.size() || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
6345 GrfMsg(1,
"FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.",
GB(
id, 0, 8));
6347 _cur.
grffile->housespec[
GB(
id, 0, 8)]->building_name =
AddGRFString(_cur.
grffile->grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6352 GrfMsg(7,
"FeatureNewName: Unsupported ID (0x{:04X})",
id);
6371 if (offset >= max_sprites) {
6372 GrfMsg(1,
"GraphicsNew: {} sprite offset must be less than {}, skipping", name, max_sprites);
6373 uint orig_num = num;
6378 if (offset + num > max_sprites) {
6379 GrfMsg(4,
"GraphicsNew: {} sprite overflow, truncating...", name);
6380 uint orig_num = num;
6381 num = std::max(max_sprites - offset, 0);
6382 return orig_num - num;
6411 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
6413 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
6443 uint8_t type = buf->ReadByte();
6444 uint16_t num = buf->ReadExtendedByte();
6445 uint16_t offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
6451 GrfMsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
6468 GrfMsg(2,
"GraphicsNew: Custom graphics (type 0x{:02X}) sprite block of length {} (unimplemented, ignoring)", type, num);
6479 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
6486 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) count must be at least {}. Only {} were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
6496 GrfMsg(2,
"GraphicsNew: Replacing sprites {} to {} of {} (type 0x{:02X}) at SpriteID 0x{:04X}", offset, offset + num - 1, action5_type->
name, type, replace);
6508 bool dup_oneway_sprites = ((type == 0x09) && (offset + num <= SPR_ONEWAY_SLOPE_N_OFFSET));
6510 for (; num > 0; num--) {
6512 int load_index = (replace == 0 ? _cur.
spriteid++ : replace++);
6514 if (dup_oneway_sprites) {
6515 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
6516 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_S_OFFSET);
6532 GrfMsg(3,
"SkipAct5: Skipping {} sprites", _cur.
skip_sprites);
6585 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
6615 *value = _game_mode;
6649 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
6658 *value = _openttd_newgrf_version;
6673 default:
return false;
6677 static uint32_t GetParamVal(
byte param, uint32_t *cond_val)
6696 if (cond_val ==
nullptr) {
6700 uint32_t index = *cond_val / 0x20;
6716 GrfMsg(1,
"Unsupported in-game variable 0x{:02X}", param);
6737 size_t pos = file.
GetPos();
6743 GrfMsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
6746 file.
SeekTo(pos, SEEK_SET);
6752 std::vector<byte> &preload_sprite = _grf_line_to_action6_sprite_override[location];
6755 if (preload_sprite.empty()) {
6756 preload_sprite.resize(num);
6757 file.
ReadBlock(preload_sprite.data(), num);
6761 file.
SeekTo(pos, SEEK_SET);
6772 param_num = buf->ReadByte();
6773 if (param_num == 0xFF)
break;
6777 param_size = buf->ReadByte();
6781 add_value =
HasBit(param_size, 7);
6782 param_size =
GB(param_size, 0, 7);
6785 offset = buf->ReadExtendedByte();
6789 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
6790 GrfMsg(2,
"CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4));
6794 GrfMsg(8,
"CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset);
6797 for (i = 0; i < param_size && offset + i < num; i++) {
6798 uint32_t value = GetParamVal(param_num + i / 4,
nullptr);
6801 if (i % 4 == 0) carry =
false;
6804 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
6805 preload_sprite[offset + i] =
GB(new_value, 0, 8);
6807 carry = new_value >= 256;
6809 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6841 uint32_t cond_val = 0;
6845 uint8_t param = buf->ReadByte();
6846 uint8_t paramsize = buf->ReadByte();
6847 uint8_t condtype = buf->ReadByte();
6854 switch (paramsize) {
6855 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6856 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6857 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6858 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6862 if (param < 0x80 && _cur.grffile->param_end <= param) {
6863 GrfMsg(7,
"SkipIf: Param {} undefined, skipping test", param);
6867 GrfMsg(7,
"SkipIf: Test condtype {}, param 0x{:02X}, condval 0x{:08X}", condtype, param, cond_val);
6872 if (condtype >= 0x0B) {
6903 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6905 }
else if (param == 0x88) {
6915 if (condtype != 10 && c ==
nullptr) {
6916 GrfMsg(7,
"SkipIf: GRFID 0x{:08X} unknown, skipping test",
BSWAP32(cond_val));
6943 default: GrfMsg(1,
"SkipIf: Unsupported GRF condition type {:02X}. Ignoring", condtype);
return;
6947 uint32_t param_val = GetParamVal(param, &cond_val);
6949 case 0x00: result = !!(param_val & (1 << cond_val));
6951 case 0x01: result = !(param_val & (1 << cond_val));
6953 case 0x02: result = (param_val & mask) == cond_val;
6955 case 0x03: result = (param_val & mask) != cond_val;
6957 case 0x04: result = (param_val & mask) < cond_val;
6959 case 0x05: result = (param_val & mask) > cond_val;
6961 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6966 GrfMsg(2,
"SkipIf: Not skipping sprites, test was false");
6970 uint8_t numsprites = buf->ReadByte();
6978 if (label.label != numsprites)
continue;
6981 if (choice ==
nullptr) choice = &label;
6983 if (label.nfo_line > _cur.
nfo_line) {
6989 if (choice !=
nullptr) {
6990 GrfMsg(2,
"SkipIf: Jumping to label 0x{:X} at line {}, test was true", choice->label, choice->nfo_line);
6996 GrfMsg(2,
"SkipIf: Skipping {} sprites, test was true", numsprites);
7015 uint8_t grf_version = buf->ReadByte();
7016 uint32_t grfid = buf->ReadDWord();
7017 const char *name = buf->ReadString();
7021 if (grf_version < 2 || grf_version > 8) {
7023 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);
7031 if (buf->HasData()) {
7032 const char *info = buf->ReadString();
7050 uint8_t version = buf->ReadByte();
7051 uint32_t grfid = buf->ReadDWord();
7052 const char *name = buf->ReadString();
7055 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
7059 if (_cur.
grffile->grfid != grfid) {
7060 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));
7064 _cur.
grffile->grf_version = version;
7082 uint8_t num_sets = buf->ReadByte();
7084 for (uint i = 0; i < num_sets; i++) {
7085 uint8_t num_sprites = buf->ReadByte();
7086 uint16_t first_sprite = buf->ReadWord();
7088 GrfMsg(2,
"SpriteReplace: [Set {}] Changing {} sprites, beginning with {}",
7089 i, num_sprites, first_sprite
7092 for (uint j = 0; j < num_sprites; j++) {
7093 int load_index = first_sprite + j;
7099 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
7109 uint8_t num_sets = buf->ReadByte();
7111 for (uint i = 0; i < num_sets; i++) {
7118 GrfMsg(3,
"SkipActA: Skipping {} sprites", _cur.
skip_sprites);
7140 STR_NEWGRF_ERROR_VERSION_NUMBER,
7141 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
7142 STR_NEWGRF_ERROR_UNSET_SWITCH,
7143 STR_NEWGRF_ERROR_INVALID_PARAMETER,
7144 STR_NEWGRF_ERROR_LOAD_BEFORE,
7145 STR_NEWGRF_ERROR_LOAD_AFTER,
7146 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
7150 STR_NEWGRF_ERROR_MSG_INFO,
7151 STR_NEWGRF_ERROR_MSG_WARNING,
7152 STR_NEWGRF_ERROR_MSG_ERROR,
7153 STR_NEWGRF_ERROR_MSG_FATAL
7156 byte severity = buf->ReadByte();
7157 byte lang = buf->ReadByte();
7158 byte message_id = buf->ReadByte();
7161 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
7165 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
7166 GrfMsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage {}", _cur.
stage);
7171 if (severity >=
lengthof(sevstr)) {
7172 GrfMsg(7,
"GRFLoadError: Invalid severity id {}. Setting to 2 (non-fatal error).", severity);
7174 }
else if (severity == 3) {
7183 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
7184 GrfMsg(7,
"GRFLoadError: Invalid message id.");
7188 if (buf->Remaining() <= 1) {
7189 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7199 if (message_id == 0xFF) {
7201 if (buf->HasData()) {
7202 const char *message = buf->ReadString();
7206 GrfMsg(7,
"GRFLoadError: No custom message supplied.");
7210 error->
message = msgstr[message_id];
7213 if (buf->HasData()) {
7214 const char *data = buf->ReadString();
7218 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7219 error->
data.clear();
7223 for (uint i = 0; i < error->
param_value.size() && buf->HasData(); i++) {
7224 uint param_number = buf->ReadByte();
7236 if (!buf->HasData())
return;
7238 const char *text = buf->ReadString();
7239 GrfMsg(2,
"GRFComment: {}", text);
7245 uint8_t target = buf->ReadByte();
7248 if (target < 0x80 || target == 0x9E)
return;
7262 static uint32_t GetPatchVariable(uint8_t param)
7272 case 0x0F:
return 0;
7288 case 0x11:
return SPR_2CCMAP_BASE;
7305 byte max_edge = std::max(log_X, log_Y);
7307 if (log_X == log_Y) {
7310 if (max_edge == log_Y)
SetBit(map_bits, 1);
7313 return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
7314 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
7323 return SPR_SLOPES_BASE;
7334 GrfMsg(2,
"ParamSet: Unknown Patch variable 0x{:02X}.", param);
7340 static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint8_t op, uint8_t target,
const char *type)
7353 for (uint i = start; i < num_ids; i++) {
7357 if (op == 2 || op == 3)
break;
7362 if (size == count)
break;
7365 if (size == count) {
7367 if (op == 0 || op == 3) {
7368 GrfMsg(2,
"ParamSet: GRM: Reserving {} {} at {}", count, type, start);
7369 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
7375 if (op != 4 && op != 5) {
7377 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type);
7382 GrfMsg(1,
"ParamSet: GRM: Unable to allocate {} {}", count, type);
7412 uint8_t target = buf->ReadByte();
7413 uint8_t oper = buf->ReadByte();
7414 uint32_t src1 = buf->ReadByte();
7415 uint32_t src2 = buf->ReadByte();
7418 if (buf->Remaining() >= 4) data = buf->ReadDWord();
7427 if (target < 0x80 && target < _cur.grffile->param_end) {
7428 GrfMsg(7,
"ParamSet: Param {} already defined, skipping", target);
7432 oper =
GB(oper, 0, 7);
7436 if (
GB(data, 0, 8) == 0xFF) {
7437 if (data == 0x0000FFFF) {
7439 src1 = GetPatchVariable(src1);
7443 uint8_t feature =
GB(data, 8, 8);
7444 uint16_t count =
GB(data, 16, 16);
7446 if (_cur.
stage == GLS_RESERVE) {
7447 if (feature == 0x08) {
7451 if (_cur.
spriteid + count >= 16384) {
7452 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count);
7458 GrfMsg(4,
"ParamSet: GRM: Allocated {} sprites at {}", count, _cur.
spriteid);
7465 }
else if (_cur.
stage == GLS_ACTIVATION) {
7494 GrfMsg(4,
"ParamSet: GRM: Using pre-allocated sprites at {}", src1);
7502 GrfMsg(1,
"ParamSet: GRM: Unsupported operation {} for general sprites", op);
7513 default: GrfMsg(1,
"ParamSet: GRM: Unsupported feature 0x{:X}", feature);
return;
7530 }
else if (src1 == 0xFE) {
7542 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
7543 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
7565 res = (int32_t)src1 * (int32_t)src2;
7569 if ((int32_t)src2 < 0) {
7570 res = src1 >> -(int32_t)src2;
7572 res = src1 << (src2 & 0x1F);
7577 if ((int32_t)src2 < 0) {
7578 res = (int32_t)src1 >> -(int32_t)src2;
7580 res = (int32_t)src1 << (src2 & 0x1F);
7604 res = (int32_t)src1 / (int32_t)src2;
7620 res = (int32_t)src1 % (int32_t)src2;
7624 default: GrfMsg(0,
"ParamSet: Unknown operation {}, skipping", oper);
return;
7653 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7664 uint32_t safe_bits = 0;
7665 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
7674 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7678 if (target < 0x80) {
7679 _cur.
grffile->param[target] = res;
7683 GrfMsg(7,
"ParamSet: Skipping unknown target 0x{:02X}", target);
7697 uint8_t num = buf->ReadByte();
7699 for (uint i = 0; i < num; i++) {
7700 uint32_t grfid = buf->ReadDWord();
7722 uint8_t num = buf->ReadByte();
7724 for (uint i = 0; i < num; i++) {
7725 uint32_t grfid = buf->ReadDWord();
7729 if (file !=
nullptr && file != _cur.
grfconfig) {
7730 GrfMsg(2,
"GRFInhibit: Deactivating file '{}'", file->
filename);
7747 uint32_t grfid = _cur.
grffile->grfid;
7751 byte id = buf->ReadByte();
7752 GrfMsg(6,
"FeatureTownName: definition 0x{:02X}",
id & 0x7F);
7757 bool new_scheme = _cur.
grffile->grf_version >= 7;
7759 byte lang = buf->ReadByte();
7765 const char *name = buf->ReadString();
7768 GrfMsg(6,
"FeatureTownName: lang 0x{:X} -> '{}'", lang, lang_name);
7770 style =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
7772 lang = buf->ReadByte();
7773 }
while (lang != 0);
7774 townname->
styles.emplace_back(style,
id);
7777 uint8_t parts = buf->ReadByte();
7778 GrfMsg(6,
"FeatureTownName: {} parts", parts);
7781 for (uint partnum = 0; partnum < parts; partnum++) {
7783 uint8_t texts = buf->ReadByte();
7784 partlist.
bitstart = buf->ReadByte();
7785 partlist.
bitcount = buf->ReadByte();
7787 GrfMsg(6,
"FeatureTownName: part {} contains {} texts and will use GB(seed, {}, {})", partnum, texts, partlist.
bitstart, partlist.
bitcount);
7789 partlist.
parts.reserve(texts);
7790 for (uint textnum = 0; textnum < texts; textnum++) {
7792 part.
prob = buf->ReadByte();
7795 byte ref_id = buf->ReadByte();
7797 GrfMsg(0,
"FeatureTownName: definition 0x{:02X} doesn't exist, deactivating", ref_id);
7798 DelGRFTownName(grfid);
7803 GrfMsg(6,
"FeatureTownName: part {}, text {}, uses intermediate definition 0x{:02X} (with probability {})", partnum, textnum, ref_id, part.
prob & 0x7F);
7805 const char *text = buf->ReadString();
7807 GrfMsg(6,
"FeatureTownName: part {}, text {}, '{}' (with probability {})", partnum, textnum, part.
text, part.
prob);
7811 GrfMsg(6,
"FeatureTownName: part {}, total probability {}", partnum, partlist.
maxprob);
7823 byte nfo_label = buf->ReadByte();
7827 GrfMsg(2,
"DefineGotoLabel: GOTO target with label 0x{:02X}", nfo_label);
7841 if (file ==
nullptr || file->sound_offset == 0) {
7842 GrfMsg(1,
"ImportGRFSound: Source file not available");
7846 if (sound_id >= file->num_sounds) {
7847 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
7851 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid);
7853 *sound = *GetSound(file->sound_offset + sound_id);
7856 sound->volume = 128;
7857 sound->priority = 0;
7868 sound->volume = 0x80;
7869 sound->priority = 0;
7871 if (offs != SIZE_MAX) {
7873 sound->file = _cur.
file;
7874 sound->file_offset = offs;
7886 uint16_t num = buf->ReadWord();
7887 if (num == 0)
return;
7890 if (_cur.
grffile->sound_offset == 0) {
7891 _cur.
grffile->sound_offset = GetNumSounds();
7892 _cur.
grffile->num_sounds = num;
7895 sound = GetSound(_cur.
grffile->sound_offset);
7900 for (
int i = 0; i < num; i++) {
7905 bool invalid = i >= _cur.
grffile->num_sounds;
7907 size_t offs = file.
GetPos();
7912 if (grf_container_version >= 2 && type == 0xFD) {
7915 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7917 }
else if (len != 4) {
7918 GrfMsg(1,
"GRFSound: Invalid sprite section import");
7928 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7935 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7943 if (_cur.
stage == GLS_INIT) {
7944 if (grf_container_version >= 2) {
7945 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7954 if (_cur.
stage == GLS_ACTIVATION) {
7957 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
7965 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
7981 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur.
skip_sprites);
7994 uint8_t num_def = buf->ReadByte();
7996 for (uint i = 0; i < num_def; i++) {
7998 uint8_t num_char = buf->ReadByte();
7999 uint16_t base_char = buf->ReadWord();
8001 if (size >= FS_END) {
8002 GrfMsg(1,
"LoadFontGlyph: Size {} is not supported, ignoring", size);
8005 GrfMsg(7,
"LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
8007 for (uint c = 0; c < num_char; c++) {
8025 uint8_t num_def = buf->ReadByte();
8027 for (uint i = 0; i < num_def; i++) {
8038 GrfMsg(3,
"SkipAct12: Skipping {} sprites", _cur.
skip_sprites);
8051 uint32_t grfid = buf->ReadDWord();
8054 GrfMsg(7,
"TranslateGRFStrings: GRFID 0x{:08X} unknown, skipping action 13",
BSWAP32(grfid));
8063 error->
data =
GetString(STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE);
8073 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
8074 byte num_strings = buf->ReadByte();
8075 uint16_t first_id = buf->ReadWord();
8077 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
8078 GrfMsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x{:04X}, number: 0x{:02X})", first_id, num_strings);
8082 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
8083 const char *
string = buf->ReadString();
8086 GrfMsg(7,
"TranslateGRFString: Ignoring empty string.");
8090 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
8119 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got {}, ignoring this field", len);
8131 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got {}, ignoring this field", len);
8134 char data = buf->ReadByte();
8142 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'PALS', ignoring this field", data);
8157 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got {}, ignoring this field", len);
8160 char data = buf->ReadByte();
8166 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'BLTR', ignoring this field", data);
8179 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got {}, ignoring this field", len);
8192 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got {}, ignoring this field", len);
8197 GrfMsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
8228 GrfMsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got {}, ignoring this field", len);
8235 GrfMsg(3,
"StaticGRFInfo: unknown parameter type {}, ignoring this field", type);
8245 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
8247 }
else if (len != 8) {
8248 GrfMsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got {}, ignoring this field", len);
8251 uint32_t min_value = buf->ReadDWord();
8252 uint32_t max_value = buf->ReadDWord();
8253 if (min_value <= max_value) {
8257 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field");
8266 if (len < 1 || len > 3) {
8267 GrfMsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got {}, ignoring this field", len);
8270 byte param_nr = buf->ReadByte();
8272 GrfMsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param {}, ignoring this field", param_nr);
8288 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got {}, ignoring this field", len);
8324 this->handler.data = handler;
8336 this->handler.text = handler;
8348 this->handler.call_handler =
true;
8349 this->handler.u.branch = handler;
8361 this->handler.call_handler =
false;
8362 this->handler.u.subtags =
subtags;
8391 byte type = buf->ReadByte();
8393 uint32_t
id = buf->ReadDWord();
8395 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
8397 type = buf->ReadByte();
8401 byte langid = buf->ReadByte();
8402 const char *name_string = buf->ReadString();
8413 type = buf->ReadByte();
8438 byte type = buf->ReadByte();
8440 uint32_t
id = buf->ReadDWord();
8442 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
8444 type = buf->ReadByte();
8457 type = buf->ReadByte();
8494 byte new_type = buf->ReadByte();
8495 while (new_type != 0) {
8498 new_type = buf->ReadByte();
8509 uint16_t size = buf->ReadWord();
8533 while ((tag = &subtags[i++])->type != 0) {
8536 default: NOT_REACHED();
8539 byte langid = buf->ReadByte();
8540 return tag->handler.
text(langid, buf->ReadString());
8544 size_t len = buf->ReadWord();
8545 if (buf->Remaining() < len)
return false;
8546 return tag->handler.
data(len, buf);
8551 return tag->handler.u.branch(buf);
8557 GrfMsg(2,
"StaticGRFInfo: unknown type/id combination found, type={:c}, id={:x}", type,
id);
8569 byte type = buf->ReadByte();
8571 uint32_t
id = buf->ReadDWord();
8572 if (!
HandleNode(type,
id, buf, subtags))
return false;
8573 type = buf->ReadByte();
8694 file->stations.clear();
8702 file->housespec.clear();
8710 for (
auto &as : file->airportspec) {
8711 if (as !=
nullptr) {
8713 for (
int j = 0; j < as->
num_table; j++) {
8722 file->airportspec.clear();
8723 file->airtspec.clear();
8731 file->industryspec.clear();
8732 file->indtspec.clear();
8740 file->objectspec.clear();
8744 static void ResetCustomRoadStops()
8747 file->roadstops.clear();
8776 CleanUpGRFTownNames();
8820 ObjectClass::Reset();
8825 StationClass::Reset();
8829 AirportClass::Reset();
8835 RoadStopClass::Reset();
8836 ResetCustomRoadStops();
8862 _grf_id_overrides.clear();
8864 InitializeSoundPool();
8891 if (!cs->IsValid())
continue;
8911 if (newfile !=
nullptr) {
8917 newfile =
new GRFFile(config);
8935 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8940 std::fill(std::begin(this->railtype_map), std::end(this->railtype_map),
INVALID_RAILTYPE);
8947 std::fill(std::begin(this->roadtype_map), std::end(this->roadtype_map),
INVALID_ROADTYPE);
8951 std::fill(std::begin(this->tramtype_map), std::end(this->tramtype_map),
INVALID_ROADTYPE);
8956 this->param = config->
param;
8973 CargoID cid = GetCargoIDByLabel(label);
8974 if (cid != INVALID_CARGO)
return label;
8986 if (std::holds_alternative<CargoLabel>(label))
return std::get<CargoLabel>(label);
8987 if (std::holds_alternative<MixedCargoType>(label)) {
8988 switch (std::get<MixedCargoType>(label)) {
8992 default: NOT_REACHED();
9003 CargoTypes original_known_cargoes = 0;
9011 bool only_defaultcargo;
9019 if (
_gted[engine].defaultcargo_grf ==
nullptr) {
9022 static constexpr
byte T = 1 << LT_TEMPERATE;
9023 static constexpr
byte A = 1 << LT_ARCTIC;
9024 static constexpr
byte S = 1 << LT_TROPIC;
9025 static constexpr
byte Y = 1 << LT_TOYLAND;
9026 static const struct DefaultRefitMasks {
9029 CargoTypes cargo_allowed;
9030 CargoTypes cargo_disallowed;
9031 } _default_refit_masks[] = {
9033 {T | A | S , CT_MAIL,
CC_MAIL, 0},
9036 {T | A , CT_COAL,
CC_BULK, 0},
9037 { S , CT_COPPER_ORE,
CC_BULK, 0},
9053 switch (label.base()) {
9057 _gted[engine].cargo_disallowed = 0;
9062 _gted[engine].cargo_disallowed = 0;
9081 _gted[engine].cargo_disallowed = 0;
9085 for (
const auto &drm : _default_refit_masks) {
9087 if (drm.cargo_label != label)
continue;
9089 _gted[engine].cargo_allowed = drm.cargo_allowed;
9090 _gted[engine].cargo_disallowed = drm.cargo_disallowed;
9095 _gted[engine].ctt_exclude_mask = original_known_cargoes;
9098 _gted[engine].UpdateRefittability(
_gted[engine].cargo_allowed != 0);
9105 CargoTypes mask = 0;
9106 CargoTypes not_mask = 0;
9107 CargoTypes xor_mask = ei->refit_mask;
9113 if (
_gted[engine].cargo_allowed != 0) {
9116 if (
_gted[engine].cargo_allowed & cs->classes)
SetBit(mask, cs->Index());
9117 if (
_gted[engine].cargo_disallowed & cs->classes)
SetBit(not_mask, cs->Index());
9121 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
9124 ei->refit_mask |=
_gted[engine].ctt_include_mask;
9125 ei->refit_mask &= ~
_gted[engine].ctt_exclude_mask;
9134 ei->cargo_type = INVALID_CARGO;
9142 if (file ==
nullptr) file = e->
GetGRF();
9143 if (file !=
nullptr && file->grf_version >= 8 && !file->
cargo_list.empty()) {
9145 byte best_local_slot = UINT8_MAX;
9147 byte local_slot = file->
cargo_map[cargo_type];
9148 if (local_slot < best_local_slot) {
9149 best_local_slot = local_slot;
9150 ei->cargo_type = cargo_type;
9172 for (uint i = 0; i < CF_END; i++) {
9184 if (e->
GetGRF() ==
nullptr) {
9187 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
9220 default: NOT_REACHED();
9232 if (parent != e->
index)
continue;
9237 GrfMsg(1,
"FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->
index].internal_id, e->
GetGRF()->filename);
9253 switch (cs.label.base()) {
9255 case CT_MAIL.base(): cs.town_production_effect =
TPE_MAIL;
break;
9256 default: cs.town_production_effect =
TPE_NONE;
break;
9259 if (!cs.IsValid()) {
9260 cs.name = cs.name_single = cs.units_volume = STR_NEWGRF_INVALID_CARGO;
9261 cs.quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
9262 cs.abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
9286 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
9296 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);
9304 Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->
grf_prop.
local_id);
9311 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);
9330 if (hs ==
nullptr || !hs->
enabled)
continue;
9335 if (min_year == 0)
return;
9339 if (hs ==
nullptr || !hs->
enabled)
continue;
9363 if (file->housespec.empty())
continue;
9365 size_t num_houses = file->housespec.size();
9366 for (
size_t i = 0; i < num_houses; i++) {
9367 HouseSpec *hs = file->housespec[i].get();
9369 if (hs ==
nullptr)
continue;
9371 const HouseSpec *next1 = (i + 1 < num_houses ? file->housespec[i + 1].get() :
nullptr);
9372 const HouseSpec *next2 = (i + 2 < num_houses ? file->housespec[i + 2].get() :
nullptr);
9373 const HouseSpec *next3 = (i + 3 < num_houses ? file->housespec[i + 3].get() :
nullptr);
9432 for (
const auto &indsp : file->industryspec) {
9433 if (indsp ==
nullptr || !indsp->
enabled)
continue;
9440 if (strid != STR_UNDEFINED) indsp->
name = strid;
9443 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
9458 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
9464 for (
const auto &indtsp : file->indtspec) {
9465 if (indtsp !=
nullptr) {
9466 _industile_mngr.SetEntitySpec(indtsp.get());
9471 for (
auto &indsp : _industry_specs) {
9478 indsp.
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
9482 for (uint i = 0; i <
lengthof(indsp.produced_cargo); ++i) {
9490 for (
auto &indtsp : _industry_tile_specs) {
9506 for (
auto &objectspec : file->objectspec) {
9507 if (objectspec !=
nullptr && objectspec->grf_prop.grffile !=
nullptr && objectspec->IsEnabled()) {
9524 for (
auto &as : file->airportspec) {
9525 if (as !=
nullptr && as->
enabled) {
9526 _airport_mngr.SetEntitySpec(as.get());
9530 for (
auto &ats : file->airtspec) {
9531 if (ats !=
nullptr && ats->enabled) {
9532 _airporttile_mngr.SetEntitySpec(ats.get());
9544 static void DecodeSpecialSprite(
byte *buf, uint num, GrfLoadingStage stage)
9558 static const SpecialSpriteHandler handlers[][GLS_END] = {
9559 {
nullptr, SafeChangeInfo,
nullptr,
nullptr, ReserveChangeInfo, FeatureChangeInfo, },
9560 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
9561 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, NewSpriteGroup, },
9562 {
nullptr,
GRFUnsafe,
nullptr,
nullptr,
nullptr, FeatureMapSpriteGroup, },
9563 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, FeatureNewName, },
9564 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
9565 {
nullptr,
nullptr,
nullptr, CfgApply, CfgApply, CfgApply, },
9566 {
nullptr,
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, },
9567 { ScanInfo,
nullptr,
nullptr, GRFInfo, GRFInfo, GRFInfo, },
9568 {
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, SkipIf, },
9569 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
9570 {
nullptr,
nullptr,
nullptr, GRFLoadError, GRFLoadError, GRFLoadError, },
9571 {
nullptr,
nullptr,
nullptr, GRFComment,
nullptr, GRFComment, },
9573 {
nullptr, SafeGRFInhibit,
nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
9576 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
9579 {
StaticGRFInfo,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
9584 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
9585 if (it == _grf_line_to_action6_sprite_override.end()) {
9591 buf = _grf_line_to_action6_sprite_override[location].data();
9592 GrfMsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
9602 byte action = bufp->ReadByte();
9604 if (action == 0xFF) {
9605 GrfMsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
9606 }
else if (action == 0xFE) {
9607 GrfMsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
9608 }
else if (action >=
lengthof(handlers)) {
9609 GrfMsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x{:02X}", action);
9610 }
else if (handlers[action][stage] ==
nullptr) {
9611 GrfMsg(7,
"DecodeSpecialSprite: Skipping action 0x{:02X} in stage {}", action, stage);
9613 GrfMsg(7,
"DecodeSpecialSprite: Handling action 0x{:02X} in stage {}", action, stage);
9614 handlers[action][stage](bufp);
9617 GrfMsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
9633 Debug(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '{}'", config->
filename);
9636 if (grf_container_version == 0) {
9637 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9641 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
9647 if (grf_container_version >= 2) file.
ReadDword();
9650 if (grf_container_version >= 2) {
9652 byte compression = file.
ReadByte();
9653 if (compression != 0) {
9654 Debug(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
9663 if (num == 4 && file.
ReadByte() == 0xFF) {
9666 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9674 while ((num = (grf_container_version >= 2 ? file.
ReadDword() : file.
ReadWord())) != 0) {
9680 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
9691 GrfMsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
9692 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
9696 if (grf_container_version >= 2 && type == 0xFD) {
9719 const std::string &filename = config->
filename;
9730 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
9732 if (_cur.
grffile ==
nullptr) UserError(
"File '{}' lost in cache.\n", filename);
9739 SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
9793 DupSprite(SPR_ROAD_DEPOT + 0, SPR_TRAMWAY_DEPOT_NO_TRACK + 0);
9794 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 1, SPR_TRAMWAY_DEPOT_NO_TRACK + 1);
9795 DupSprite(SPR_ROAD_DEPOT + 2, SPR_TRAMWAY_DEPOT_NO_TRACK + 2);
9796 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 3, SPR_TRAMWAY_DEPOT_NO_TRACK + 3);
9797 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 4, SPR_TRAMWAY_DEPOT_NO_TRACK + 4);
9798 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 5, SPR_TRAMWAY_DEPOT_NO_TRACK + 5);
9809 static const uint32_t override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
9813 std::vector<int> grf_overrides(num_grfs, -1);
9814 for (
int i = 0; i < num_grfs; i++) {
9816 uint32_t
override = _grf_id_overrides[source->grfid];
9817 if (
override == 0)
continue;
9820 if (dest ==
nullptr)
continue;
9823 assert(grf_overrides[i] >= 0);
9827 for (
int i = 0; i < num_grfs; i++) {
9828 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
9836 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9839 Debug(grf, 3,
"'{}' overrides price base multiplier {} of '{}'", source->filename, p, dest->filename);
9845 for (
int i = num_grfs - 1; i >= 0; i--) {
9846 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9854 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9857 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, source->filename, dest->filename);
9863 for (
int i = 0; i < num_grfs; i++) {
9864 if (grf_overrides[i] < 0)
continue;
9872 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9873 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9875 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, dest->filename, source->filename);
9883 if (file->grf_version >= 8)
continue;
9884 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9885 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9887 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9890 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9897 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9898 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9899 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9901 price_base_multipliers[p] = 0;
9906 Debug(grf, 3,
"'{}' sets global price base multiplier {}", file->
filename, p);
9908 price_base_multipliers[p] = 0;
9910 Debug(grf, 3,
"'{}' sets local price base multiplier {}", file->
filename, p);
9925 _string_to_grf_mapping.clear();
9928 _grf_line_to_action6_sprite_override.clear();
9991 if (file ==
nullptr ||
_gted[e->
index].roadtramtype == 0) {
10000 if (
_gted[e->
index].roadtramtype < list->size())
10002 RoadTypeLabel rtl = (*list)[
_gted[e->
index].roadtramtype];
10031 _grm_sprites.clear();
10089 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
10096 if (stage == GLS_RESERVE) {
10097 static const uint32_t overrides[][2] = {
10098 { 0x44442202, 0x44440111 },
10099 { 0x6D620402, 0x6D620401 },
10100 { 0x4D656f20, 0x4D656F17 },
10102 for (
size_t i = 0; i <
lengthof(overrides); i++) {
10108 uint num_non_static = 0;
10110 _cur.
stage = stage;
10117 Debug(grf, 0,
"NewGRF file is missing '{}'; disabling", c->
filename);
10126 Debug(grf, 0,
"'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
10128 c->
error = {STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED};
10137 if (stage == GLS_RESERVE) {
10139 }
else if (stage == GLS_ACTIVATION) {
10144 Debug(sprite, 2,
"LoadNewGRF: Currently {} sprites are loaded", _cur.
spriteid);