53 #include "table/strings.h"
70 const std::vector<GRFFile *> &GetAllGRFFiles()
119 this->skip_sprites = 0;
121 for (uint i = 0; i < GSF_END; i++) {
122 this->spritesets[i].clear();
125 memset(this->spritegroups, 0,
sizeof(this->spritegroups));
138 assert(feature < GSF_END);
139 for (uint i = 0; i < numsets; i++) {
140 SpriteSet &set = this->spritesets[feature][first_set + i];
141 set.
sprite = first_sprite + i * numents;
154 assert(feature < GSF_END);
155 return !this->spritesets[feature].empty();
167 assert(feature < GSF_END);
168 return this->spritesets[feature].find(set) != this->spritesets[feature].end();
180 return this->spritesets[feature].find(set)->second.sprite;
192 return this->spritesets[feature].find(set)->second.num_sprites;
205 template <VehicleType T>
208 return image_index == 0xFD || IsValidImageIndex<T>(image_index);
220 ByteReader(
byte *data,
byte *end) : data(data), end(end) { }
222 inline byte *ReadBytes(
size_t size)
224 if (data + size >= end) {
235 inline byte ReadByte()
237 if (data < end)
return *(data)++;
243 uint16_t val = ReadByte();
244 return val | (ReadByte() << 8);
247 uint16_t ReadExtendedByte()
249 uint16_t val = ReadByte();
250 return val == 0xFF ? ReadWord() : val;
255 uint32_t val = ReadWord();
256 return val | (ReadWord() << 16);
259 uint32_t ReadVarSize(
byte size)
262 case 1:
return ReadByte();
263 case 2:
return ReadWord();
264 case 4:
return ReadDWord();
271 const char *ReadString()
273 char *
string =
reinterpret_cast<char *
>(data);
274 size_t string_length =
ttd_strnlen(
string, Remaining());
276 if (string_length == Remaining()) {
278 string[string_length - 1] =
'\0';
279 GrfMsg(7,
"String was not terminated with a zero byte.");
289 inline size_t Remaining()
const
294 inline bool HasData(
size_t count = 1)
const
296 return data + count <= end;
304 inline void Skip(
size_t len)
313 typedef void (*SpecialSpriteHandler)(
ByteReader *buf);
327 uint16_t cargo_allowed;
328 uint16_t cargo_disallowed;
329 RailTypeLabel railtypelabel;
330 uint8_t roadtramtype;
345 }
else if (this->refittability ==
UNSET) {
346 this->refittability =
EMPTY;
351 static std::vector<GRFTempEngineData>
_gted;
366 GRFLocation(uint32_t grfid, uint32_t nfoline) : grfid(grfid), nfoline(nfoline) { }
370 return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
375 return this->grfid == other.grfid && this->nfoline == other.nfoline;
379 static std::map<GRFLocation, SpriteID> _grm_sprites;
380 typedef std::map<GRFLocation, std::vector<byte>> GRFLineToSpriteOverride;
381 static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
393 void GrfMsgI(
int severity,
const std::string &msg)
406 if (file->grfid == grfid)
return file;
419 if (file->filename == filename)
return file;
439 if (config !=
nullptr) {
450 if (message == STR_NULL)
return nullptr;
452 config->error = {STR_NEWGRF_ERROR_MSG_FATAL, message};
454 return &config->error.value();
465 typedef std::vector<StringIDMapping> StringIDMappingVector;
466 static StringIDMappingVector _string_to_grf_mapping;
475 *target = STR_UNDEFINED;
476 _string_to_grf_mapping.push_back({_cur.
grffile->grfid, source, target});
489 static const StringID units_volume[] = {
490 STR_ITEMS, STR_PASSENGERS, STR_TONS, STR_BAGS,
491 STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS,
492 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
493 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
494 STR_TONS, STR_TONS, STR_BAGS, STR_LITERS,
495 STR_TONS, STR_LITERS, STR_TONS, STR_ITEMS,
496 STR_BAGS, STR_LITERS, STR_TONS, STR_ITEMS,
497 STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
503 #define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
504 static_assert(stringend - stringid == end - begin); \
505 if (str >= begin && str <= end) return str + (stringid - begin)
508 TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING, STR_CARGO_PLURAL_FIZZY_DRINKS);
509 TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING, STR_CARGO_SINGULAR_FIZZY_DRINK);
510 if (str >= 0x004E && str <= 0x006D)
return units_volume[str - 0x004E];
511 TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING, STR_QUANTITY_FIZZY_DRINKS);
512 TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING, STR_ABBREV_FIZZY_DRINKS);
513 TEXTID_TO_STRINGID(0x00D1, 0x00E0, STR_COLOUR_DARK_BLUE, STR_COLOUR_WHITE);
518 TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, STR_TOWN_BUILDING_NAME_OLD_HOUSES_1);
519 TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1);
520 TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1, STR_TOWN_BUILDING_NAME_PIGGY_BANK_1);
523 TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE, STR_INDUSTRY_NAME_SUGAR_MINE);
524 TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION, STR_NEWS_INDUSTRY_PLANTED);
525 TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL, STR_NEWS_INDUSTRY_CLOSURE_LACK_OF_TREES);
526 TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_FARM);
527 TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_FARM);
530 case 0x4830:
return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
531 case 0x4831:
return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
532 case 0x483B:
return STR_ERROR_CAN_ONLY_BE_POSITIONED;
534 #undef TEXTID_TO_STRINGID
536 if (str == STR_NULL)
return STR_EMPTY;
538 Debug(grf, 0,
"Unknown StringID 0x{:04X} remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
577 static std::map<uint32_t, uint32_t> _grf_id_overrides;
586 _grf_id_overrides[source_grfid] = target_grfid;
587 GrfMsg(5,
"SetNewGRFOverride: Added override of 0x{:X} to 0x{:X}",
BSWAP32(source_grfid),
BSWAP32(target_grfid));
602 uint32_t scope_grfid = INVALID_GRFID;
605 scope_grfid = file->grfid;
606 uint32_t
override = _grf_id_overrides[file->grfid];
608 scope_grfid =
override;
610 if (grf_match ==
nullptr) {
611 GrfMsg(5,
"Tried mapping from GRFID {:x} to {:x} but target is not loaded",
BSWAP32(file->grfid),
BSWAP32(
override));
613 GrfMsg(5,
"Mapping from GRFID {:x} to {:x}",
BSWAP32(file->grfid),
BSWAP32(
override));
618 EngineID engine = _engine_mngr.
GetID(type, internal_id, scope_grfid);
627 EngineID engine = _engine_mngr.
GetID(type, internal_id, INVALID_GRFID);
633 GrfMsg(5,
"Replaced engine at index {} for GRFID {:x}, type {}, index {}", e->
index,
BSWAP32(file->grfid), type, internal_id);
637 if (!static_access) {
639 eid->
grfid = scope_grfid;
645 if (static_access)
return nullptr;
648 GrfMsg(0,
"Can't allocate any more engines");
659 assert(_engine_mngr.size() == e->
index);
660 _engine_mngr.push_back({
675 GrfMsg(5,
"Created new engine at index {} for GRFID {:x}, type {}, index {}", e->
index,
BSWAP32(file->grfid), type, internal_id);
692 uint32_t scope_grfid = INVALID_GRFID;
694 scope_grfid = file->grfid;
695 uint32_t
override = _grf_id_overrides[file->grfid];
696 if (
override != 0) scope_grfid =
override;
699 return _engine_mngr.
GetID(type, internal_id, scope_grfid);
739 grf_sprite->
sprite = buf->ReadWord();
740 grf_sprite->
pal = buf->ReadWord();
745 bool custom_sprite =
HasBit(grf_sprite->
pal, 15) != invert_action1_flag;
749 uint index =
GB(grf_sprite->
sprite, 0, 14);
751 GrfMsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset {}", index);
752 grf_sprite->
sprite = SPR_IMG_QUERY;
753 grf_sprite->
pal = PAL_NONE;
756 if (max_sprite_offset !=
nullptr) *max_sprite_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
761 GrfMsg(1,
"ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite");
762 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
768 uint index =
GB(grf_sprite->
pal, 0, 14);
770 GrfMsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset {} for 'palette'", index);
771 grf_sprite->
pal = PAL_NONE;
774 if (max_palette_offset !=
nullptr) *max_palette_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
779 GrfMsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette");
780 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
809 regs.delta.
parent[0] = buf->ReadByte();
810 regs.delta.
parent[1] = buf->ReadByte();
821 GrfMsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 ({}) exceeding the maximal allowed value {}", regs.
sprite_var10,
TLR_MAX_VAR10);
822 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
830 GrfMsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 ({}) exceeding the maximal allowed value {}", regs.
palette_var10,
TLR_MAX_VAR10);
831 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
850 bool has_flags =
HasBit(num_building_sprites, 6);
851 ClrBit(num_building_sprites, 6);
854 dts->
Allocate(num_building_sprites);
856 std::vector<uint16_t> max_sprite_offset(num_building_sprites + 1, 0);
857 std::vector<uint16_t> max_palette_offset(num_building_sprites + 1, 0);
864 GrfMsg(1,
"ReadSpriteLayout: Spritelayout uses invalid flag 0x{:X} for ground sprite", flags & ~(valid_flags & ~
TLF_NON_GROUND_FLAGS));
865 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
872 for (uint i = 0; i < num_building_sprites; i++) {
875 flags =
ReadSpriteLayoutSprite(buf, has_flags,
false, use_cur_spritesets, feature, &seq->image, max_sprite_offset.data() + i + 1, max_palette_offset.data() + i + 1);
878 if (flags & ~valid_flags) {
879 GrfMsg(1,
"ReadSpriteLayout: Spritelayout uses unknown flag 0x{:X}", flags & ~valid_flags);
880 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
884 seq->
delta_x = buf->ReadByte();
885 seq->delta_y = buf->ReadByte();
887 if (!no_z_position) seq->
delta_z = buf->ReadByte();
890 seq->size_x = buf->ReadByte();
891 seq->size_y = buf->ReadByte();
892 seq->size_z = buf->ReadByte();
900 bool is_consistent =
true;
902 for (uint i = 0; i < num_building_sprites + 1; i++) {
903 if (max_sprite_offset[i] > 0) {
907 is_consistent =
false;
911 if (max_palette_offset[i] > 0) {
915 is_consistent =
false;
924 if (!is_consistent || dts->registers !=
nullptr) {
928 for (uint i = 0; i < num_building_sprites + 1; i++) {
943 CargoTypes result = 0;
961 if (base_pointer == 0) {
962 *index = INVALID_PRICE;
966 static const uint32_t start = 0x4B34;
967 static const uint32_t size = 6;
969 if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) {
970 GrfMsg(1,
"{}: Unsupported running cost base 0x{:04X}, ignoring", error_location, base_pointer);
974 *index = (
Price)((base_pointer - start) / size);
1003 ei->decay_speed = buf->ReadByte();
1020 ei->load_amount = buf->ReadByte();
1042 for (
int i = 0; i < numinfo; i++) {
1051 uint8_t tracktype = buf->ReadByte();
1053 if (tracktype < _cur.grffile->railtype_list.size()) {
1058 switch (tracktype) {
1059 case 0:
_gted[e->
index].railtypelabel = rvi->
engclass >= 2 ? RAILTYPE_LABEL_ELECTRIC : RAILTYPE_LABEL_RAIL;
break;
1060 case 1:
_gted[e->
index].railtypelabel = RAILTYPE_LABEL_MONO;
break;
1061 case 2:
_gted[e->
index].railtypelabel = RAILTYPE_LABEL_MAGLEV;
break;
1063 GrfMsg(1,
"RailVehicleChangeInfo: Invalid track type {} specified, ignoring", tracktype);
1076 uint16_t speed = buf->ReadWord();
1077 if (speed == 0xFFFF) speed = 0;
1084 rvi->
power = buf->ReadWord();
1087 if (rvi->
power != 0) {
1105 uint8_t spriteid = buf->ReadByte();
1106 uint8_t orig_spriteid = spriteid;
1110 if (spriteid < 0xFD) spriteid >>= 1;
1112 if (IsValidNewGRFImageIndex<VEH_TRAIN>(spriteid)) {
1113 rvi->image_index = spriteid;
1115 GrfMsg(1,
"RailVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1116 rvi->image_index = 0;
1122 uint8_t dual = buf->ReadByte();
1127 rvi->railveh_type = rvi->
power == 0 ?
1139 uint8_t ctype = buf->ReadByte();
1141 if (ctype == 0xFF) {
1143 ei->cargo_type = INVALID_CARGO;
1144 }
else if (_cur.
grffile->grf_version >= 8) {
1149 ei->cargo_type = ctype;
1151 ei->cargo_type = INVALID_CARGO;
1152 GrfMsg(2,
"RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1159 SB(rvi->
weight, 0, 8, buf->ReadByte());
1167 GrfMsg(2,
"RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored.");
1179 uint8_t traction = buf->ReadByte();
1182 if (traction <= 0x07) {
1184 }
else if (traction <= 0x27) {
1186 }
else if (traction <= 0x31) {
1188 }
else if (traction <= 0x37) {
1190 }
else if (traction <= 0x41) {
1216 ei->refit_cost = buf->ReadByte();
1220 uint32_t mask = buf->ReadDWord();
1221 _gted[e->
index].UpdateRefittability(mask != 0);
1258 byte weight = buf->ReadByte();
1261 GrfMsg(2,
"RailVehicleChangeInfo: Nonsensical weight of {} tons, ignoring", weight << 8);
1282 _gted[e->
index].cargo_allowed = buf->ReadWord();
1288 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1302 uint8_t count = buf->ReadByte();
1303 _gted[e->
index].UpdateRefittability(prop == 0x2C && count != 0);
1305 CargoTypes &ctt = prop == 0x2C ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1351 for (
int i = 0; i < numinfo; i++) {
1362 _gted[e->
index].roadtramtype = buf->ReadByte() + 1;
1370 rvi->running_cost = buf->ReadByte();
1378 uint8_t spriteid = buf->ReadByte();
1379 uint8_t orig_spriteid = spriteid;
1382 if (spriteid == 0xFF) spriteid = 0xFD;
1384 if (spriteid < 0xFD) spriteid >>= 1;
1386 if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
1387 rvi->image_index = spriteid;
1389 GrfMsg(1,
"RoadVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1390 rvi->image_index = 0;
1396 rvi->capacity = buf->ReadByte();
1401 uint8_t ctype = buf->ReadByte();
1403 if (ctype == 0xFF) {
1405 ei->cargo_type = INVALID_CARGO;
1406 }
else if (_cur.
grffile->grf_version >= 8) {
1411 ei->cargo_type = ctype;
1413 ei->cargo_type = INVALID_CARGO;
1414 GrfMsg(2,
"RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1421 rvi->cost_factor = buf->ReadByte();
1429 rvi->
power = buf->ReadByte();
1433 rvi->
weight = buf->ReadByte();
1437 _gted[e->
index].rv_max_speed = buf->ReadByte();
1441 uint32_t mask = buf->ReadDWord();
1442 _gted[e->
index].UpdateRefittability(mask != 0);
1461 ei->refit_cost = buf->ReadByte();
1474 _gted[e->
index].cargo_allowed = buf->ReadWord();
1480 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1512 uint8_t count = buf->ReadByte();
1513 _gted[e->
index].UpdateRefittability(prop == 0x24 && count != 0);
1515 CargoTypes &ctt = prop == 0x24 ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1557 for (
int i = 0; i < numinfo; i++) {
1566 uint8_t spriteid = buf->ReadByte();
1567 uint8_t orig_spriteid = spriteid;
1570 if (spriteid == 0xFF) spriteid = 0xFD;
1572 if (spriteid < 0xFD) spriteid >>= 1;
1574 if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
1575 svi->image_index = spriteid;
1577 GrfMsg(1,
"ShipVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1578 svi->image_index = 0;
1588 svi->cost_factor = buf->ReadByte();
1597 uint8_t ctype = buf->ReadByte();
1599 if (ctype == 0xFF) {
1601 ei->cargo_type = INVALID_CARGO;
1602 }
else if (_cur.
grffile->grf_version >= 8) {
1607 ei->cargo_type = ctype;
1609 ei->cargo_type = INVALID_CARGO;
1610 GrfMsg(2,
"ShipVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1617 svi->capacity = buf->ReadWord();
1621 svi->running_cost = buf->ReadByte();
1629 uint32_t mask = buf->ReadDWord();
1630 _gted[e->
index].UpdateRefittability(mask != 0);
1641 ei->refit_cost = buf->ReadByte();
1662 _gted[e->
index].cargo_allowed = buf->ReadWord();
1668 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1696 uint8_t count = buf->ReadByte();
1697 _gted[e->
index].UpdateRefittability(prop == 0x1E && count != 0);
1699 CargoTypes &ctt = prop == 0x1E ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1725 svi->
acceleration = std::max<uint8_t>(1, buf->ReadByte());
1749 for (
int i = 0; i < numinfo; i++) {
1758 uint8_t spriteid = buf->ReadByte();
1759 uint8_t orig_spriteid = spriteid;
1762 if (spriteid == 0xFF) spriteid = 0xFD;
1764 if (spriteid < 0xFD) spriteid >>= 1;
1766 if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
1767 avi->image_index = spriteid;
1769 GrfMsg(1,
"AircraftVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1770 avi->image_index = 0;
1776 if (buf->ReadByte() == 0) {
1784 SB(avi->
subtype, 1, 1, (buf->ReadByte() != 0 ? 1 : 0));
1788 avi->cost_factor = buf->ReadByte();
1792 avi->
max_speed = (buf->ReadByte() * 128) / 10;
1796 avi->acceleration = buf->ReadByte();
1800 avi->running_cost = buf->ReadByte();
1816 uint32_t mask = buf->ReadDWord();
1817 _gted[e->
index].UpdateRefittability(mask != 0);
1828 ei->refit_cost = buf->ReadByte();
1841 _gted[e->
index].cargo_allowed = buf->ReadWord();
1847 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1865 uint8_t count = buf->ReadByte();
1866 _gted[e->
index].UpdateRefittability(prop == 0x1D && count != 0);
1868 CargoTypes &ctt = prop == 0x1D ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1915 GrfMsg(1,
"StationChangeInfo: Station {} is invalid, max {}, ignoring", stid + numinfo,
NUM_STATIONS_PER_GRF);
1920 if (_cur.
grffile->stations.size() < stid + numinfo) _cur.
grffile->stations.resize(stid + numinfo);
1922 for (
int i = 0; i < numinfo; i++) {
1926 if (statspec ==
nullptr && prop != 0x08) {
1927 GrfMsg(2,
"StationChangeInfo: Attempt to modify undefined station {}, ignoring", stid + i);
1934 if (statspec ==
nullptr) {
1935 _cur.
grffile->stations[stid + i] = std::make_unique<StationSpec>();
1936 statspec = _cur.
grffile->stations[stid + i].get();
1940 uint32_t classid = buf->ReadDWord();
1941 statspec->
cls_id = StationClass::Allocate(
BSWAP32(classid));
1946 uint16_t tiles = buf->ReadExtendedByte();
1950 for (uint t = 0; t < tiles; t++) {
1954 if (buf->HasData(4) && *(uint32_t*)buf->Data() == 0) {
1957 dts->
Clone(&_station_display_datas_rail[t % 8]);
1965 static std::vector<DrawTileSeqStruct> tmp_layout;
1972 dtss.
delta_x = buf->ReadByte();
1974 dtss.delta_y = buf->ReadByte();
1975 dtss.
delta_z = buf->ReadByte();
1976 dtss.size_x = buf->ReadByte();
1977 dtss.size_y = buf->ReadByte();
1978 dtss.size_z = buf->ReadByte();
1984 dts->
Clone(tmp_layout.data());
1989 GrfMsg(1,
"StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i);
1996 uint16_t srcid = buf->ReadExtendedByte();
1997 const StationSpec *srcstatspec = srcid >= _cur.
grffile->stations.size() ? nullptr : _cur.
grffile->stations[srcid].get();
1999 if (srcstatspec ==
nullptr) {
2000 GrfMsg(1,
"StationChangeInfo: Station {} is not defined, cannot copy sprite layout to {}.", srcid, stid + i);
2007 for (
const auto &it : srcstatspec->
renderdata) {
2027 while (buf->HasData()) {
2028 byte length = buf->ReadByte();
2029 byte number = buf->ReadByte();
2031 if (length == 0 || number == 0)
break;
2033 if (statspec->
layouts.size() < length) statspec->
layouts.resize(length);
2034 if (statspec->
layouts[length - 1].size() < number) statspec->
layouts[length - 1].resize(number);
2036 const byte *layout = buf->ReadBytes(length * number);
2037 statspec->
layouts[length - 1][number - 1].assign(layout, layout + length * number);
2040 for (
auto &tile : statspec->
layouts[length - 1][number - 1]) {
2041 if ((tile & 6) != tile) {
2042 GrfMsg(1,
"StationChangeInfo: Invalid tile {} in layout {}x{}", tile, length, number);
2050 uint16_t srcid = buf->ReadExtendedByte();
2051 const StationSpec *srcstatspec = srcid >= _cur.
grffile->stations.size() ? nullptr : _cur.
grffile->stations[srcid].get();
2053 if (srcstatspec ==
nullptr) {
2054 GrfMsg(1,
"StationChangeInfo: Station {} is not defined, cannot copy tile layout to {}.", srcid, stid + i);
2067 statspec->
pylons = buf->ReadByte();
2071 if (_cur.
grffile->grf_version >= 7) {
2079 statspec->
flags = buf->ReadByte();
2083 statspec->
wires = buf->ReadByte();
2087 statspec->
blocked = buf->ReadByte();
2091 statspec->animation.
frames = buf->ReadByte();
2092 statspec->animation.
status = buf->ReadByte();
2096 statspec->animation.
speed = buf->ReadByte();
2100 statspec->animation.
triggers = buf->ReadWord();
2106 uint16_t tiles = buf->ReadExtendedByte();
2110 for (uint t = 0; t < tiles; t++) {
2112 uint num_building_sprites = buf->ReadByte();
2119 GrfMsg(1,
"StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i);
2161 if (
id + numinfo > CF_END) {
2162 GrfMsg(1,
"CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring",
id + numinfo, CF_END);
2166 for (
int i = 0; i < numinfo; i++) {
2175 cp->
flags = buf->ReadByte();
2200 GrfMsg(1,
"BridgeChangeInfo: Bridge {} is invalid, max {}, ignoring", brid + numinfo,
MAX_BRIDGES);
2204 for (
int i = 0; i < numinfo; i++) {
2210 byte year = buf->ReadByte();
2225 bridge->
price = buf->ReadByte();
2229 bridge->
speed = buf->ReadWord();
2230 if (bridge->
speed == 0) bridge->
speed = UINT16_MAX;
2234 byte tableid = buf->ReadByte();
2235 byte numtables = buf->ReadByte();
2242 for (; numtables-- != 0; tableid++) {
2244 GrfMsg(1,
"BridgeChangeInfo: Table {} >= 7, skipping", tableid);
2245 for (
byte sprite = 0; sprite < 32; sprite++) buf->ReadDWord();
2250 bridge->
sprite_table[tableid] = MallocT<PalSpriteID>(32);
2253 for (
byte sprite = 0; sprite < 32; sprite++) {
2267 bridge->
flags = buf->ReadByte();
2276 if (newone != STR_UNDEFINED) bridge->
material = newone;
2283 if (newone != STR_UNDEFINED) bridge->
transport_name[prop - 0x11] = newone;
2288 bridge->
price = buf->ReadWord();
2345 for (uint j = 0; j < 4; j++) buf->ReadByte();
2349 byte count = buf->ReadByte();
2350 for (
byte j = 0; j < count; j++) buf->ReadByte();
2355 buf->Skip(buf->ReadByte() * 2);
2378 GrfMsg(1,
"TownHouseChangeInfo: Too many houses loaded ({}), max ({}). Ignoring.", hid + numinfo,
NUM_HOUSES_PER_GRF);
2383 if (_cur.
grffile->housespec.size() < hid + numinfo) _cur.
grffile->housespec.resize(hid + numinfo);
2385 for (
int i = 0; i < numinfo; i++) {
2388 if (prop != 0x08 && housespec ==
nullptr) {
2391 if (cir > ret) ret = cir;
2397 byte subs_id = buf->ReadByte();
2398 if (subs_id == 0xFF) {
2405 GrfMsg(2,
"TownHouseChangeInfo: Attempt to use new house {} as substitute house for {}. Ignoring.", subs_id, hid + i);
2410 if (housespec ==
nullptr) {
2412 _cur.
grffile->housespec[hid + i] = std::make_unique<HouseSpec>(*HouseSpec::Get(subs_id));
2413 housespec = _cur.
grffile->housespec[hid + i].get();
2417 housespec->
grf_prop.subst_id = subs_id;
2426 housespec->
building_flags &= ~(BUILDING_IS_CHURCH | BUILDING_IS_STADIUM);
2446 uint16_t years = buf->ReadWord();
2466 int8_t goods = buf->ReadByte();
2503 byte override = buf->ReadByte();
2507 GrfMsg(2,
"TownHouseChangeInfo: Attempt to override new house {} with house id {}. Ignoring.",
override, hid + i);
2511 _house_mngr.
Add(hid + i, _cur.
grffile->grfid,
override);
2520 for (uint j = 0; j < 4; j++) housespec->
random_colour[j] =
static_cast<Colours
>(
GB(buf->ReadByte(), 0, 4));
2542 housespec->
class_id = AllocateHouseClassID(buf->ReadByte(), _cur.
grffile->grfid);
2550 uint32_t cargotypes = buf->ReadDWord();
2553 if (cargotypes == 0xFFFFFFFF)
break;
2555 for (uint j = 0; j < 3; j++) {
2557 uint8_t cargo_part =
GB(cargotypes, 8 * j, 8);
2575 byte count = buf->ReadByte();
2576 for (
byte j = 0; j < count; j++) {
2584 housespec->
min_year = buf->ReadWord();
2588 housespec->
max_year = buf->ReadWord();
2592 uint count = buf->ReadByte();
2645 template <
typename T>
2649 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
2653 translation_table.clear();
2654 for (
int i = 0; i < numinfo; i++) {
2655 translation_table.push_back(T(
BSWAP32(buf->ReadDWord())));
2670 for (
int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
2704 for (
int i = 0; i < numinfo; i++) {
2707 int factor = buf->ReadByte();
2708 uint price = gvid + i;
2710 if (price < PR_END) {
2713 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring", price);
2722 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2731 uint32_t rate = buf->ReadDWord();
2739 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
2746 uint16_t options = buf->ReadWord();
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();
3405 byte num_table = buf->ReadByte();
3406 for (
byte j = 0; j < num_table; j++) {
3407 for (uint k = 0;; k++) {
3408 byte x = buf->ReadByte();
3409 if (x == 0xFE && k == 0) {
3415 byte y = buf->ReadByte();
3416 if (x == 0 && y == 0x80)
break;
3418 byte gfx = buf->ReadByte();
3419 if (gfx == 0xFE) buf->ReadWord();
3426 for (
byte j = 0; j < 3; j++) buf->ReadByte();
3433 buf->Skip(buf->ReadByte());
3437 int num_inputs = buf->ReadByte();
3438 int num_outputs = buf->ReadByte();
3439 buf->Skip(num_inputs * num_outputs * 2);
3457 const size_t size = layout.size();
3458 if (size == 0)
return false;
3460 for (
size_t i = 0; i < size - 1; i++) {
3461 for (
size_t j = i + 1; j < size; j++) {
3462 if (layout[i].ti.x == layout[j].ti.x &&
3463 layout[i].ti.y == layout[j].ti.y) {
3469 bool have_regular_tile =
false;
3470 for (
const auto &tilelayout : layout) {
3472 have_regular_tile =
true;
3477 return have_regular_tile;
3493 GrfMsg(1,
"IndustriesChangeInfo: Too many industries loaded ({}), max ({}). Ignoring.", indid + numinfo,
NUM_INDUSTRYTYPES_PER_GRF);
3498 if (_cur.
grffile->industryspec.size() < indid + numinfo) _cur.
grffile->industryspec.resize(indid + numinfo);
3500 for (
int i = 0; i < numinfo; i++) {
3503 if (prop != 0x08 && indsp ==
nullptr) {
3505 if (cir > ret) ret = cir;
3511 byte subs_id = buf->ReadByte();
3512 if (subs_id == 0xFF) {
3515 _industry_specs[indid + i].
enabled =
false;
3519 GrfMsg(2,
"_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id, indid + i);
3526 if (indsp ==
nullptr) {
3527 _cur.
grffile->industryspec[indid + i] = std::make_unique<IndustrySpec>(_origin_industry_specs[subs_id]);
3528 indsp = _cur.
grffile->industryspec[indid + i].get();
3532 indsp->
grf_prop.subst_id = subs_id;
3542 byte ovrid = buf->ReadByte();
3546 GrfMsg(2,
"IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid, indid + i);
3550 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3555 byte new_num_layouts = buf->ReadByte();
3556 uint32_t definition_size = buf->ReadDWord();
3557 uint32_t bytes_read = 0;
3558 std::vector<IndustryTileLayout> new_layouts;
3561 for (
byte j = 0; j < new_num_layouts; j++) {
3564 for (uint k = 0;; k++) {
3565 if (bytes_read >= definition_size) {
3566 GrfMsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.", indid);
3568 definition_size = UINT32_MAX;
3574 it.ti.
x = buf->ReadByte();
3577 if (it.ti.
x == 0xFE && k == 0) {
3579 IndustryType type = buf->ReadByte();
3580 byte laynbr = buf->ReadByte();
3583 if (type >=
lengthof(_origin_industry_specs)) {
3584 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry {}", indid);
3588 if (laynbr >= _origin_industry_specs[type].layouts.size()) {
3589 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}", indid);
3593 layout = _origin_industry_specs[type].layouts[laynbr];
3597 it.ti.
y = buf->ReadByte();
3600 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
3606 it.gfx = buf->ReadByte();
3609 if (it.gfx == 0xFE) {
3611 int local_tile_id = buf->ReadWord();
3615 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3618 GrfMsg(2,
"IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id, indid);
3624 it.ti.
x = (int8_t)
GB(it.ti.
x, 0, 8);
3625 it.ti.
y = (int8_t)
GB(it.ti.
y, 0, 8);
3634 if (_cur.
grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
3640 GrfMsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring", indid);
3644 new_layouts.push_back(layout);
3674 for (
byte j = 0; j < 2; j++) {
3681 for (
byte j = 0; j < 3; j++) {
3690 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3703 sounds[j] = buf->ReadByte();
3719 for (
byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3745 uint32_t multiples = buf->ReadDWord();
3761 byte aflag = buf->ReadByte();
3771 uint16_t str = buf->ReadWord();
3781 byte num_cargoes = buf->ReadByte();
3782 if (num_cargoes >
lengthof(indsp->produced_cargo)) {
3787 for (uint i = 0; i <
lengthof(indsp->produced_cargo); i++) {
3788 if (i < num_cargoes) {
3790 indsp->produced_cargo[i] = cargo;
3792 indsp->produced_cargo[i] = INVALID_CARGO;
3800 byte num_cargoes = buf->ReadByte();
3807 if (i < num_cargoes) {
3819 byte num_cargoes = buf->ReadByte();
3820 if (num_cargoes >
lengthof(indsp->production_rate)) {
3825 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
3826 if (i < num_cargoes) {
3827 indsp->production_rate[i] = buf->ReadByte();
3829 indsp->production_rate[i] = 0;
3836 byte num_inputs = buf->ReadByte();
3837 byte num_outputs = buf->ReadByte();
3844 for (uint j = 0; j <
lengthof(indsp->produced_cargo); j++) {
3846 if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
3870 for (
int i = 0; i < as->
num_table; i++) {
3875 }
while ((++it)->ti.x != -0x80);
3876 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3879 as->
table = table_list;
3901 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3906 if (_cur.
grffile->airportspec.size() < airport + numinfo) _cur.
grffile->airportspec.resize(airport + numinfo);
3908 for (
int i = 0; i < numinfo; i++) {
3911 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
3912 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring", airport + i);
3918 byte subs_id = buf->ReadByte();
3919 if (subs_id == 0xFF) {
3926 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id, airport + i);
3933 if (as ==
nullptr) {
3935 as = _cur.
grffile->airportspec[airport + i].get();
3942 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3954 uint32_t defsize = buf->ReadDWord();
3960 for (
byte j = 0; j < as->
num_table; j++) {
3962 for (
int k = 0;; k++) {
3963 att[k].
ti.
x = buf->ReadByte();
3964 att[k].
ti.
y = buf->ReadByte();
3966 if (att[k].ti.x == 0 && att[k].
ti.
y == 0x80) {
3969 att[k].
ti.
x = -0x80;
3978 att[k].
gfx = buf->ReadByte();
3980 if (att[k].gfx == 0xFE) {
3982 int local_tile_id = buf->ReadWord();
3985 uint16_t tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3988 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id, airport + i);
3991 att[k].
gfx = tempid;
3993 }
else if (att[k].gfx == 0xFF) {
3994 att[k].
ti.
x = (int8_t)
GB(att[k].ti.x, 0, 8);
3995 att[k].
ti.
y = (int8_t)
GB(att[k].ti.y, 0, 8);
4006 tile_table[j] = CallocT<AirportTileTable>(size);
4007 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
4010 for (
int j = 0; j < old_num_table; j++) {
4016 as->
table = tile_table;
4019 for (
int i = 0; i < as->
num_table; i++) {
4020 free(tile_table[i]);
4122 GrfMsg(1,
"ObjectChangeInfo: Too many objects loaded ({}), max ({}). Ignoring.",
id + numinfo,
NUM_OBJECTS_PER_GRF);
4127 if (_cur.
grffile->objectspec.size() <
id + numinfo) _cur.
grffile->objectspec.resize(
id + numinfo);
4129 for (
int i = 0; i < numinfo; i++) {
4132 if (prop != 0x08 && spec ==
nullptr) {
4135 if (cir > ret) ret = cir;
4142 if (spec ==
nullptr) {
4143 _cur.
grffile->objectspec[
id + i] = std::make_unique<ObjectSpec>();
4144 spec = _cur.
grffile->objectspec[
id + i].get();
4150 uint32_t classid = buf->ReadDWord();
4166 spec->
climate = buf->ReadByte();
4170 spec->
size = buf->ReadByte();
4171 if (
GB(spec->
size, 0, 4) == 0 ||
GB(spec->
size, 4, 4) == 0) {
4172 GrfMsg(0,
"ObjectChangeInfo: Invalid object size requested (0x{:X}) for object id {}. Ignoring.", spec->
size,
id + i);
4217 spec->
height = buf->ReadByte();
4221 spec->
views = buf->ReadByte();
4223 GrfMsg(2,
"ObjectChangeInfo: Invalid number of views ({}) for object id {}. Ignoring.", spec->
views,
id + i);
4256 GrfMsg(1,
"RailTypeChangeInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4260 for (
int i = 0; i < numinfo; i++) {
4273 uint16_t str = buf->ReadWord();
4275 if (_cur.
grffile->grf_version < 8) {
4305 int n = buf->ReadByte();
4306 for (
int j = 0; j != n; j++) {
4307 RailTypeLabel label = buf->ReadDWord();
4367 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4386 GrfMsg(1,
"RailTypeReserveInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4390 for (
int i = 0; i < numinfo; i++) {
4394 RailTypeLabel rtl = buf->ReadDWord();
4403 _cur.
grffile->railtype_map[
id + i] = rt;
4421 int n = buf->ReadByte();
4422 for (
int j = 0; j != n; j++) {
4427 GrfMsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set",
id + i);
4434 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4475 GrfMsg(1,
"RoadTypeChangeInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4479 for (
int i = 0; i < numinfo; i++) {
4492 uint16_t str = buf->ReadWord();
4519 int n = buf->ReadByte();
4520 for (
int j = 0; j != n; j++) {
4521 RoadTypeLabel label = buf->ReadDWord();
4526 if (GetRoadTramType(resolved_rt) == rtt) {
4529 GrfMsg(1,
"RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt);
4574 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4605 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4609 for (
int i = 0; i < numinfo; i++) {
4612 RoadTypeLabel rtl = buf->ReadDWord();
4619 }
else if (GetRoadTramType(rt) != rtt) {
4620 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid type (road/tram), ignoring",
id + numinfo);
4624 type_map[
id + i] = rt;
4641 int n = buf->ReadByte();
4642 for (
int j = 0; j != n; j++) {
4647 GrfMsg(1,
"RoadTypeReserveInfo: Ignoring property 1D for road type {} because no label was set",
id + i);
4653 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4677 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_ROAD);
4682 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_TRAM);
4690 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", airtid + numinfo,
NUM_AIRPORTTILES_PER_GRF);
4695 if (_cur.
grffile->airtspec.size() < airtid + numinfo) _cur.
grffile->airtspec.resize(airtid + numinfo);
4697 for (
int i = 0; i < numinfo; i++) {
4700 if (prop != 0x08 && tsp ==
nullptr) {
4701 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.", airtid + i);
4707 byte subs_id = buf->ReadByte();
4710 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id, airtid + i);
4715 if (tsp ==
nullptr) {
4717 tsp = _cur.
grffile->airtspec[airtid + i].get();
4732 byte override = buf->ReadByte();
4736 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.",
override, airtid + i);
4740 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4815 GrfMsg(1,
"RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring",
id + numinfo,
NUM_ROADSTOPS_PER_GRF);
4819 if (_cur.
grffile->roadstops.size() <
id + numinfo) _cur.
grffile->roadstops.resize(
id + numinfo);
4821 for (
int i = 0; i < numinfo; i++) {
4824 if (rs ==
nullptr && prop != 0x08) {
4825 GrfMsg(1,
"RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring",
id + i);
4827 if (cir > ret) ret = cir;
4833 if (rs ==
nullptr) {
4834 _cur.
grffile->roadstops[
id + i] = std::make_unique<RoadStopSpec>();
4835 rs = _cur.
grffile->roadstops[
id + i].get();
4838 uint32_t classid = buf->ReadDWord();
4865 rs->animation.
frames = buf->ReadByte();
4866 rs->animation.
status = buf->ReadByte();
4870 rs->animation.
speed = buf->ReadByte();
4874 rs->animation.
triggers = buf->ReadWord();
4878 rs->callback_mask = buf->ReadByte();
4882 rs->flags = (uint8_t)buf->ReadDWord();
4899 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property)
4902 default: NOT_REACHED();
4912 GrfMsg(1,
"{}: Ignoring property 0x{:02X} of feature 0x{:02X} (not implemented)", caller, property, feature);
4916 GrfMsg(0,
"{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature);
4929 static void FeatureChangeInfo(
ByteReader *buf)
4942 static const VCI_Handler handler[] = {
4960 AirportTilesChangeInfo,
4965 static_assert(GSF_END ==
lengthof(handler));
4967 uint8_t feature = buf->ReadByte();
4968 uint8_t numprops = buf->ReadByte();
4969 uint numinfo = buf->ReadByte();
4970 uint engine = buf->ReadExtendedByte();
4972 if (feature >= GSF_END) {
4973 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4977 GrfMsg(6,
"FeatureChangeInfo: Feature 0x{:02X}, {} properties, to apply to {}+{}",
4978 feature, numprops, engine, numinfo);
4980 if (handler[feature] ==
nullptr) {
4981 if (feature != GSF_CARGOES) GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4988 while (numprops-- && buf->HasData()) {
4989 uint8_t prop = buf->ReadByte();
4992 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
4999 uint8_t feature = buf->ReadByte();
5000 uint8_t numprops = buf->ReadByte();
5001 uint numinfo = buf->ReadByte();
5002 buf->ReadExtendedByte();
5004 if (feature == GSF_BRIDGES && numprops == 1) {
5005 uint8_t prop = buf->ReadByte();
5008 if (prop == 0x0D)
return;
5009 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
5010 uint8_t prop = buf->ReadByte();
5013 bool is_safe =
true;
5014 for (uint i = 0; i < numinfo; i++) {
5015 uint32_t s = buf->ReadDWord();
5023 if (is_safe)
return;
5034 static void ReserveChangeInfo(
ByteReader *buf)
5036 uint8_t feature = buf->ReadByte();
5038 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES && feature != GSF_ROADTYPES && feature != GSF_TRAMTYPES)
return;
5040 uint8_t numprops = buf->ReadByte();
5041 uint8_t numinfo = buf->ReadByte();
5042 uint8_t index = buf->ReadExtendedByte();
5044 while (numprops-- && buf->HasData()) {
5045 uint8_t prop = buf->ReadByte();
5049 default: NOT_REACHED();
5055 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
5059 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
5063 cir = RoadTypeReserveInfo(index, numinfo, prop, buf);
5067 cir = TramTypeReserveInfo(index, numinfo, prop, buf);
5071 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
5092 uint8_t feature = buf->ReadByte();
5093 uint16_t num_sets = buf->ReadByte();
5094 uint16_t first_set = 0;
5096 if (num_sets == 0 && buf->HasData(3)) {
5099 first_set = buf->ReadExtendedByte();
5100 num_sets = buf->ReadExtendedByte();
5102 uint16_t num_ents = buf->ReadExtendedByte();
5104 if (feature >= GSF_END) {
5106 GrfMsg(1,
"NewSpriteSet: Unsupported feature 0x{:02X}, skipping {} sprites", feature, _cur.
skip_sprites);
5112 GrfMsg(7,
"New sprite set at {} of feature 0x{:02X}, consisting of {} sets with {} views each (total {})",
5113 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
5116 for (
int i = 0; i < num_sets * num_ents; i++) {
5126 uint16_t num_sets = buf->ReadByte();
5128 if (num_sets == 0 && buf->HasData(3)) {
5131 buf->ReadExtendedByte();
5132 num_sets = buf->ReadExtendedByte();
5134 uint16_t num_ents = buf->ReadExtendedByte();
5138 GrfMsg(3,
"SkipAct1: Skipping {} sprites", _cur.
skip_sprites);
5143 static const SpriteGroup *GetGroupFromGroupID(
byte setid,
byte type, uint16_t groupid)
5145 if (
HasBit(groupid, 15)) {
5150 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5151 GrfMsg(1,
"GetGroupFromGroupID(0x{:02X}:0x{:02X}): Groupid 0x{:04X} does not exist, leaving empty", setid, type, groupid);
5155 return _cur.spritegroups[groupid];
5168 if (
HasBit(spriteid, 15)) {
5174 GrfMsg(1,
"CreateGroupFromGroupID(0x{:02X}:0x{:02X}): Sprite set {} invalid", setid, type, spriteid);
5179 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
5182 assert(spriteset_start + num_sprites <= _cur.
spriteid);
5203 uint8_t feature = buf->ReadByte();
5204 if (feature >= GSF_END) {
5205 GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5209 uint8_t setid = buf->ReadByte();
5210 uint8_t type = buf->ReadByte();
5234 switch (
GB(type, 2, 2)) {
5235 default: NOT_REACHED();
5236 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
5237 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
5238 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
5248 adjust.variable = buf->ReadByte();
5249 if (adjust.variable == 0x7E) {
5251 adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
5256 varadjust = buf->ReadByte();
5257 adjust.shift_num =
GB(varadjust, 0, 5);
5258 adjust.type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
5259 adjust.and_mask = buf->ReadVarSize(varsize);
5261 if (adjust.type != DSGA_TYPE_NONE) {
5262 adjust.add_val = buf->ReadVarSize(varsize);
5263 adjust.divmod_val = buf->ReadVarSize(varsize);
5266 adjust.divmod_val = 0;
5270 }
while (
HasBit(varadjust, 5));
5272 std::vector<DeterministicSpriteGroupRange> ranges;
5273 ranges.resize(buf->ReadByte());
5274 for (uint i = 0; i < ranges.size(); i++) {
5275 ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5276 ranges[i].low = buf->ReadVarSize(varsize);
5277 ranges[i].high = buf->ReadVarSize(varsize);
5280 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5281 group->error_group = ranges.empty() ? group->default_group : ranges[0].group;
5283 group->calculated_result = ranges.empty();
5286 std::vector<uint32_t> bounds;
5287 for (uint i = 0; i < ranges.size(); i++) {
5288 bounds.push_back(ranges[i].low);
5289 if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1);
5291 std::sort(bounds.begin(), bounds.end());
5292 bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
5294 std::vector<const SpriteGroup *> target;
5295 for (uint j = 0; j < bounds.size(); ++j) {
5296 uint32_t v = bounds[j];
5298 for (uint i = 0; i < ranges.size(); i++) {
5299 if (ranges[i].low <= v && v <= ranges[i].high) {
5300 t = ranges[i].group;
5304 target.push_back(t);
5306 assert(target.size() == bounds.size());
5308 for (uint j = 0; j < bounds.size(); ) {
5309 if (target[j] != group->default_group) {
5311 r.group = target[j];
5313 while (j < bounds.size() && target[j] == r.group) {
5316 r.high = j < bounds.size() ? bounds[j] - 1 : UINT32_MAX;
5338 group->count = buf->ReadByte();
5341 uint8_t triggers = buf->ReadByte();
5342 group->triggers =
GB(triggers, 0, 7);
5343 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
5346 byte num_groups = buf->ReadByte();
5348 GrfMsg(1,
"NewSpriteGroup: Random Action 2 nrand should be power of 2");
5351 for (uint i = 0; i < num_groups; i++) {
5352 group->
groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
5363 case GSF_ROADVEHICLES:
5374 byte num_loaded = type;
5375 byte num_loading = buf->ReadByte();
5378 GrfMsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
5382 GrfMsg(6,
"NewSpriteGroup: New SpriteGroup 0x{:02X}, {} loaded, {} loading",
5383 setid, num_loaded, num_loading);
5385 if (num_loaded + num_loading == 0) {
5386 GrfMsg(1,
"NewSpriteGroup: no result, skipping invalid RealSpriteGroup");
5390 if (num_loaded + num_loading == 1) {
5392 uint16_t spriteid = buf->ReadWord();
5394 GrfMsg(8,
"NewSpriteGroup: one result, skipping RealSpriteGroup = subset {}", spriteid);
5398 std::vector<uint16_t> loaded;
5399 std::vector<uint16_t> loading;
5401 for (uint i = 0; i < num_loaded; i++) {
5402 loaded.push_back(buf->ReadWord());
5403 GrfMsg(8,
"NewSpriteGroup: + rg->loaded[{}] = subset {}", i, loaded[i]);
5406 for (uint i = 0; i < num_loading; i++) {
5407 loading.push_back(buf->ReadWord());
5408 GrfMsg(8,
"NewSpriteGroup: + rg->loading[{}] = subset {}", i, loading[i]);
5411 if (std::adjacent_find(loaded.begin(), loaded.end(), std::not_equal_to<>()) == loaded.end() &&
5412 std::adjacent_find(loading.begin(), loading.end(), std::not_equal_to<>()) == loading.end() &&
5413 loaded[0] == loading[0])
5417 GrfMsg(8,
"NewSpriteGroup: same result, skipping RealSpriteGroup = subset {}", loaded[0]);
5426 for (uint16_t spriteid : loaded) {
5428 group->
loaded.push_back(t);
5431 for (uint16_t spriteid : loading) {
5440 case GSF_AIRPORTTILES:
5442 case GSF_INDUSTRYTILES:
5443 case GSF_ROADSTOPS: {
5444 byte num_building_sprites = std::max((uint8_t)1, type);
5452 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
5456 case GSF_INDUSTRIES: {
5458 GrfMsg(1,
"NewSpriteGroup: Unsupported industry production version {}, skipping", type);
5469 for (uint i = 0; i < 3; i++) {
5473 for (uint i = 0; i < 2; i++) {
5476 group->again = buf->ReadByte();
5477 }
else if (type == 1) {
5479 for (uint i = 0; i < 3; i++) {
5483 for (uint i = 0; i < 2; i++) {
5486 group->again = buf->ReadByte();
5487 }
else if (type == 2) {
5491 error->
data =
"too many inputs (max 16)";
5494 for (uint i = 0; i < group->
num_input; i++) {
5495 byte rawcargo = buf->ReadByte();
5504 error->
data =
"duplicate input cargo";
5513 error->
data =
"too many outputs (max 16)";
5516 for (uint i = 0; i < group->
num_output; i++) {
5517 byte rawcargo = buf->ReadByte();
5524 error->
data =
"duplicate output cargo";
5530 group->again = buf->ReadByte();
5538 default: GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5543 _cur.spritegroups[setid] = act_group;
5546 static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
5555 GrfMsg(1,
"TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
5556 return INVALID_CARGO;
5560 if (cs->bitnum == ctype) {
5561 GrfMsg(6,
"TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index());
5566 GrfMsg(5,
"TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype);
5567 return INVALID_CARGO;
5572 GrfMsg(1,
"TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (
unsigned int)_cur.
grffile->
cargo_list.size() - 1);
5573 return INVALID_CARGO;
5579 GrfMsg(5,
"TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
5580 return INVALID_CARGO;
5583 CargoID cid = GetCargoIDByLabel(cl);
5585 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));
5586 return INVALID_CARGO;
5589 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);
5594 static bool IsValidGroupID(uint16_t groupid,
const char *
function)
5596 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5597 GrfMsg(1,
"{}: Spritegroup 0x{:04X} out of range or empty, skipping.",
function, groupid);
5604 static void VehicleMapSpriteGroup(
ByteReader *buf,
byte feature, uint8_t idcount)
5607 static uint last_engines_count;
5608 bool wagover =
false;
5611 if (
HasBit(idcount, 7)) {
5614 idcount =
GB(idcount, 0, 7);
5616 if (last_engines_count == 0) {
5617 GrfMsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
5621 GrfMsg(6,
"VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons",
5622 last_engines_count, idcount);
5624 if (last_engines_count != idcount) {
5625 last_engines =
ReallocT(last_engines, idcount);
5626 last_engines_count = idcount;
5630 std::vector<EngineID> engines;
5631 for (uint i = 0; i < idcount; i++) {
5637 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
5641 engines.push_back(e->
index);
5642 if (!wagover) last_engines[i] = engines[i];
5645 uint8_t cidcount = buf->ReadByte();
5646 for (uint c = 0; c < cidcount; c++) {
5647 uint8_t ctype = buf->ReadByte();
5648 uint16_t groupid = buf->ReadWord();
5649 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
5651 GrfMsg(8,
"VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
5653 CargoID cid = TranslateCargo(feature, ctype);
5656 for (uint i = 0; i < idcount; i++) {
5659 GrfMsg(7,
"VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
5662 SetWagonOverrideSprites(engine, cid, _cur.spritegroups[groupid], last_engines, last_engines_count);
5664 SetCustomEngineSprites(engine, cid, _cur.spritegroups[groupid]);
5669 uint16_t groupid = buf->ReadWord();
5670 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
5672 GrfMsg(8,
"-- Default group id 0x{:04X}", groupid);
5674 for (uint i = 0; i < idcount; i++) {
5687 static void CanalMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5689 std::vector<uint16_t> cfs;
5690 cfs.reserve(idcount);
5691 for (uint i = 0; i < idcount; i++) {
5692 cfs.push_back(buf->ReadExtendedByte());
5695 uint8_t cidcount = buf->ReadByte();
5696 buf->Skip(cidcount * 3);
5698 uint16_t groupid = buf->ReadWord();
5699 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
5701 for (
auto &cf : cfs) {
5703 GrfMsg(1,
"CanalMapSpriteGroup: Canal subset {} out of range, skipping", cf);
5713 static void StationMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5715 if (_cur.
grffile->stations.empty()) {
5716 GrfMsg(1,
"StationMapSpriteGroup: No stations defined, skipping");
5720 std::vector<uint16_t> stations;
5721 stations.reserve(idcount);
5722 for (uint i = 0; i < idcount; i++) {
5723 stations.push_back(buf->ReadExtendedByte());
5726 uint8_t cidcount = buf->ReadByte();
5727 for (uint c = 0; c < cidcount; c++) {
5728 uint8_t ctype = buf->ReadByte();
5729 uint16_t groupid = buf->ReadWord();
5730 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5732 ctype = TranslateCargo(GSF_STATIONS, ctype);
5735 for (
auto &station : stations) {
5738 if (statspec ==
nullptr) {
5739 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5747 uint16_t groupid = buf->ReadWord();
5748 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5750 for (
auto &station : stations) {
5753 if (statspec ==
nullptr) {
5754 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5759 GrfMsg(1,
"StationMapSpriteGroup: Station {} mapped multiple times, skipping", station);
5766 StationClass::Assign(statspec);
5771 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5773 if (_cur.
grffile->housespec.empty()) {
5774 GrfMsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5778 std::vector<uint16_t> houses;
5779 houses.reserve(idcount);
5780 for (uint i = 0; i < idcount; i++) {
5781 houses.push_back(buf->ReadExtendedByte());
5785 uint8_t cidcount = buf->ReadByte();
5786 buf->Skip(cidcount * 3);
5788 uint16_t groupid = buf->ReadWord();
5789 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5791 for (
auto &house : houses) {
5794 if (hs ==
nullptr) {
5795 GrfMsg(1,
"TownHouseMapSpriteGroup: House {} undefined, skipping.", house);
5803 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5805 if (_cur.
grffile->industryspec.empty()) {
5806 GrfMsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5810 std::vector<uint16_t> industries;
5811 industries.reserve(idcount);
5812 for (uint i = 0; i < idcount; i++) {
5813 industries.push_back(buf->ReadExtendedByte());
5817 uint8_t cidcount = buf->ReadByte();
5818 buf->Skip(cidcount * 3);
5820 uint16_t groupid = buf->ReadWord();
5821 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5823 for (
auto &industry : industries) {
5826 if (indsp ==
nullptr) {
5827 GrfMsg(1,
"IndustryMapSpriteGroup: Industry {} undefined, skipping", industry);
5835 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5837 if (_cur.
grffile->indtspec.empty()) {
5838 GrfMsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5842 std::vector<uint16_t> indtiles;
5843 indtiles.reserve(idcount);
5844 for (uint i = 0; i < idcount; i++) {
5845 indtiles.push_back(buf->ReadExtendedByte());
5849 uint8_t cidcount = buf->ReadByte();
5850 buf->Skip(cidcount * 3);
5852 uint16_t groupid = buf->ReadWord();
5853 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5855 for (
auto &indtile : indtiles) {
5858 if (indtsp ==
nullptr) {
5859 GrfMsg(1,
"IndustrytileMapSpriteGroup: Industry tile {} undefined, skipping", indtile);
5867 static void CargoMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5869 std::vector<uint16_t> cargoes;
5870 cargoes.reserve(idcount);
5871 for (uint i = 0; i < idcount; i++) {
5872 cargoes.push_back(buf->ReadExtendedByte());
5876 uint8_t cidcount = buf->ReadByte();
5877 buf->Skip(cidcount * 3);
5879 uint16_t groupid = buf->ReadWord();
5880 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5882 for (
auto &cid : cargoes) {
5884 GrfMsg(1,
"CargoMapSpriteGroup: Cargo ID {} out of range, skipping", cid);
5890 cs->group = _cur.spritegroups[groupid];
5894 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5896 if (_cur.
grffile->objectspec.empty()) {
5897 GrfMsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5901 std::vector<uint16_t> objects;
5902 objects.reserve(idcount);
5903 for (uint i = 0; i < idcount; i++) {
5904 objects.push_back(buf->ReadExtendedByte());
5907 uint8_t cidcount = buf->ReadByte();
5908 for (uint c = 0; c < cidcount; c++) {
5909 uint8_t ctype = buf->ReadByte();
5910 uint16_t groupid = buf->ReadWord();
5911 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5914 if (ctype != 0xFF) {
5915 GrfMsg(1,
"ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype);
5919 for (
auto &
object : objects) {
5922 if (spec ==
nullptr) {
5923 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5931 uint16_t groupid = buf->ReadWord();
5932 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5934 for (
auto &
object : objects) {
5937 if (spec ==
nullptr) {
5938 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5943 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} mapped multiple times, skipping",
object);
5953 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5955 std::vector<uint8_t> railtypes;
5956 railtypes.reserve(idcount);
5957 for (uint i = 0; i < idcount; i++) {
5958 uint16_t
id = buf->ReadExtendedByte();
5959 railtypes.push_back(id < RAILTYPE_END ? _cur.grffile->railtype_map[
id] :
INVALID_RAILTYPE);
5962 uint8_t cidcount = buf->ReadByte();
5963 for (uint c = 0; c < cidcount; c++) {
5964 uint8_t ctype = buf->ReadByte();
5965 uint16_t groupid = buf->ReadWord();
5966 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5968 if (ctype >= RTSG_END)
continue;
5971 for (
auto &railtype : railtypes) {
5976 rti->
group[ctype] = _cur.spritegroups[groupid];
5985 static void RoadTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount, RoadTramType rtt)
5989 std::vector<uint8_t> roadtypes;
5990 roadtypes.reserve(idcount);
5991 for (uint i = 0; i < idcount; i++) {
5992 uint16_t
id = buf->ReadExtendedByte();
5996 uint8_t cidcount = buf->ReadByte();
5997 for (uint c = 0; c < cidcount; c++) {
5998 uint8_t ctype = buf->ReadByte();
5999 uint16_t groupid = buf->ReadWord();
6000 if (!IsValidGroupID(groupid,
"RoadTypeMapSpriteGroup"))
continue;
6002 if (ctype >= ROTSG_END)
continue;
6005 for (
auto &roadtype : roadtypes) {
6010 rti->
group[ctype] = _cur.spritegroups[groupid];
6019 static void AirportMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6021 if (_cur.
grffile->airportspec.empty()) {
6022 GrfMsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
6026 std::vector<uint16_t> airports;
6027 airports.reserve(idcount);
6028 for (uint i = 0; i < idcount; i++) {
6029 airports.push_back(buf->ReadExtendedByte());
6033 uint8_t cidcount = buf->ReadByte();
6034 buf->Skip(cidcount * 3);
6036 uint16_t groupid = buf->ReadWord();
6037 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
6039 for (
auto &airport : airports) {
6042 if (as ==
nullptr) {
6043 GrfMsg(1,
"AirportMapSpriteGroup: Airport {} undefined, skipping", airport);
6051 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6053 if (_cur.
grffile->airtspec.empty()) {
6054 GrfMsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
6058 std::vector<uint16_t> airptiles;
6059 airptiles.reserve(idcount);
6060 for (uint i = 0; i < idcount; i++) {
6061 airptiles.push_back(buf->ReadExtendedByte());
6065 uint8_t cidcount = buf->ReadByte();
6066 buf->Skip(cidcount * 3);
6068 uint16_t groupid = buf->ReadWord();
6069 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
6071 for (
auto &airptile : airptiles) {
6074 if (airtsp ==
nullptr) {
6075 GrfMsg(1,
"AirportTileMapSpriteGroup: Airport tile {} undefined, skipping", airptile);
6083 static void RoadStopMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6085 if (_cur.
grffile->roadstops.empty()) {
6086 GrfMsg(1,
"RoadStopMapSpriteGroup: No roadstops defined, skipping");
6090 std::vector<uint16_t> roadstops;
6091 roadstops.reserve(idcount);
6092 for (uint i = 0; i < idcount; i++) {
6093 roadstops.push_back(buf->ReadExtendedByte());
6096 uint8_t cidcount = buf->ReadByte();
6097 for (uint c = 0; c < cidcount; c++) {
6098 uint8_t ctype = buf->ReadByte();
6099 uint16_t groupid = buf->ReadWord();
6100 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
continue;
6102 ctype = TranslateCargo(GSF_ROADSTOPS, ctype);
6105 for (
auto &roadstop : roadstops) {
6108 if (roadstopspec ==
nullptr) {
6109 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping", roadstop);
6117 uint16_t groupid = buf->ReadWord();
6118 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
return;
6120 for (
auto &roadstop : roadstops) {
6123 if (roadstopspec ==
nullptr) {
6124 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping.", roadstop);
6129 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} mapped multiple times, skipping", roadstop);
6136 RoadStopClass::Assign(roadstopspec);
6141 static void FeatureMapSpriteGroup(
ByteReader *buf)
6157 uint8_t feature = buf->ReadByte();
6158 uint8_t idcount = buf->ReadByte();
6160 if (feature >= GSF_END) {
6161 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6169 uint16_t groupid = buf->ReadWord();
6170 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
6172 GrfMsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature 0x{:02X}", feature);
6181 GrfMsg(6,
"FeatureMapSpriteGroup: Feature 0x{:02X}, {} ids", feature, idcount);
6185 case GSF_ROADVEHICLES:
6188 VehicleMapSpriteGroup(buf, feature, idcount);
6192 CanalMapSpriteGroup(buf, idcount);
6196 StationMapSpriteGroup(buf, idcount);
6200 TownHouseMapSpriteGroup(buf, idcount);
6203 case GSF_INDUSTRIES:
6204 IndustryMapSpriteGroup(buf, idcount);
6207 case GSF_INDUSTRYTILES:
6208 IndustrytileMapSpriteGroup(buf, idcount);
6212 CargoMapSpriteGroup(buf, idcount);
6216 AirportMapSpriteGroup(buf, idcount);
6220 ObjectMapSpriteGroup(buf, idcount);
6224 RailTypeMapSpriteGroup(buf, idcount);
6228 RoadTypeMapSpriteGroup(buf, idcount, RTT_ROAD);
6232 RoadTypeMapSpriteGroup(buf, idcount, RTT_TRAM);
6235 case GSF_AIRPORTTILES:
6236 AirportTileMapSpriteGroup(buf, idcount);
6240 RoadStopMapSpriteGroup(buf, idcount);
6244 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6268 bool new_scheme = _cur.
grffile->grf_version >= 7;
6270 uint8_t feature = buf->ReadByte();
6271 if (feature >= GSF_END && feature != 0x48) {
6272 GrfMsg(1,
"FeatureNewName: Unsupported feature 0x{:02X}, skipping", feature);
6276 uint8_t lang = buf->ReadByte();
6277 uint8_t num = buf->ReadByte();
6278 bool generic =
HasBit(lang, 7);
6281 id = buf->ReadWord();
6282 }
else if (feature <= GSF_AIRCRAFT) {
6283 id = buf->ReadExtendedByte();
6285 id = buf->ReadByte();
6290 uint16_t endid =
id + num;
6292 GrfMsg(6,
"FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
6293 id, endid, feature, lang);
6295 for (;
id < endid && buf->HasData();
id++) {
6296 const char *name = buf->ReadString();
6297 GrfMsg(8,
"FeatureNewName: 0x{:04X} <- {}",
id, name);
6301 case GSF_ROADVEHICLES:
6306 if (e ==
nullptr)
break;
6320 switch (
GB(
id, 8, 8)) {
6322 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6323 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6331 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6332 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6339 if (
GB(
id, 0, 8) >= _cur.
grffile->airtspec.size() || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
6340 GrfMsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring",
GB(
id, 0, 8));
6347 if (
GB(
id, 0, 8) >= _cur.
grffile->housespec.size() || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
6348 GrfMsg(1,
"FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.",
GB(
id, 0, 8));
6350 _cur.
grffile->housespec[
GB(
id, 0, 8)]->building_name =
AddGRFString(_cur.
grffile->grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6355 GrfMsg(7,
"FeatureNewName: Unsupported ID (0x{:04X})",
id);
6374 if (offset >= max_sprites) {
6375 GrfMsg(1,
"GraphicsNew: {} sprite offset must be less than {}, skipping", name, max_sprites);
6376 uint orig_num = num;
6381 if (offset + num > max_sprites) {
6382 GrfMsg(4,
"GraphicsNew: {} sprite overflow, truncating...", name);
6383 uint orig_num = num;
6384 num = std::max(max_sprites - offset, 0);
6385 return orig_num - num;
6414 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
6416 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
6446 uint8_t type = buf->ReadByte();
6447 uint16_t num = buf->ReadExtendedByte();
6448 uint16_t offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
6454 GrfMsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
6471 GrfMsg(2,
"GraphicsNew: Custom graphics (type 0x{:02X}) sprite block of length {} (unimplemented, ignoring)", type, num);
6482 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
6489 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) count must be at least {}. Only {} were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
6499 GrfMsg(2,
"GraphicsNew: Replacing sprites {} to {} of {} (type 0x{:02X}) at SpriteID 0x{:04X}", offset, offset + num - 1, action5_type->
name, type, replace);
6511 bool dup_oneway_sprites = ((type == 0x09) && (offset + num <= SPR_ONEWAY_SLOPE_N_OFFSET));
6513 for (; num > 0; num--) {
6515 int load_index = (replace == 0 ? _cur.
spriteid++ : replace++);
6517 if (dup_oneway_sprites) {
6518 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
6519 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_S_OFFSET);
6535 GrfMsg(3,
"SkipAct5: Skipping {} sprites", _cur.
skip_sprites);
6588 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
6618 *value = _game_mode;
6652 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
6661 *value = _openttd_newgrf_version;
6676 default:
return false;
6680 static uint32_t GetParamVal(
byte param, uint32_t *cond_val)
6699 if (cond_val ==
nullptr) {
6703 uint32_t index = *cond_val / 0x20;
6719 GrfMsg(1,
"Unsupported in-game variable 0x{:02X}", param);
6740 size_t pos = file.
GetPos();
6746 GrfMsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
6749 file.
SeekTo(pos, SEEK_SET);
6755 std::vector<byte> &preload_sprite = _grf_line_to_action6_sprite_override[location];
6758 if (preload_sprite.empty()) {
6759 preload_sprite.resize(num);
6760 file.
ReadBlock(preload_sprite.data(), num);
6764 file.
SeekTo(pos, SEEK_SET);
6775 param_num = buf->ReadByte();
6776 if (param_num == 0xFF)
break;
6780 param_size = buf->ReadByte();
6784 add_value =
HasBit(param_size, 7);
6785 param_size =
GB(param_size, 0, 7);
6788 offset = buf->ReadExtendedByte();
6792 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
6793 GrfMsg(2,
"CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4));
6797 GrfMsg(8,
"CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset);
6800 for (i = 0; i < param_size && offset + i < num; i++) {
6801 uint32_t value = GetParamVal(param_num + i / 4,
nullptr);
6804 if (i % 4 == 0) carry =
false;
6807 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
6808 preload_sprite[offset + i] =
GB(new_value, 0, 8);
6810 carry = new_value >= 256;
6812 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6844 uint32_t cond_val = 0;
6848 uint8_t param = buf->ReadByte();
6849 uint8_t paramsize = buf->ReadByte();
6850 uint8_t condtype = buf->ReadByte();
6857 switch (paramsize) {
6858 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6859 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6860 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6861 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6865 if (param < 0x80 && _cur.grffile->param_end <= param) {
6866 GrfMsg(7,
"SkipIf: Param {} undefined, skipping test", param);
6870 GrfMsg(7,
"SkipIf: Test condtype {}, param 0x{:02X}, condval 0x{:08X}", condtype, param, cond_val);
6875 if (condtype >= 0x0B) {
6906 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6908 }
else if (param == 0x88) {
6918 if (condtype != 10 && c ==
nullptr) {
6919 GrfMsg(7,
"SkipIf: GRFID 0x{:08X} unknown, skipping test",
BSWAP32(cond_val));
6946 default: GrfMsg(1,
"SkipIf: Unsupported GRF condition type {:02X}. Ignoring", condtype);
return;
6950 uint32_t param_val = GetParamVal(param, &cond_val);
6952 case 0x00: result = !!(param_val & (1 << cond_val));
6954 case 0x01: result = !(param_val & (1 << cond_val));
6956 case 0x02: result = (param_val & mask) == cond_val;
6958 case 0x03: result = (param_val & mask) != cond_val;
6960 case 0x04: result = (param_val & mask) < cond_val;
6962 case 0x05: result = (param_val & mask) > cond_val;
6964 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6969 GrfMsg(2,
"SkipIf: Not skipping sprites, test was false");
6973 uint8_t numsprites = buf->ReadByte();
6981 if (label.label != numsprites)
continue;
6984 if (choice ==
nullptr) choice = &label;
6986 if (label.nfo_line > _cur.
nfo_line) {
6992 if (choice !=
nullptr) {
6993 GrfMsg(2,
"SkipIf: Jumping to label 0x{:X} at line {}, test was true", choice->label, choice->nfo_line);
6999 GrfMsg(2,
"SkipIf: Skipping {} sprites, test was true", numsprites);
7018 uint8_t grf_version = buf->ReadByte();
7019 uint32_t grfid = buf->ReadDWord();
7020 const char *name = buf->ReadString();
7024 if (grf_version < 2 || grf_version > 8) {
7026 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);
7034 if (buf->HasData()) {
7035 const char *info = buf->ReadString();
7053 uint8_t version = buf->ReadByte();
7054 uint32_t grfid = buf->ReadDWord();
7055 const char *name = buf->ReadString();
7058 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
7062 if (_cur.
grffile->grfid != grfid) {
7063 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));
7067 _cur.
grffile->grf_version = version;
7085 uint8_t num_sets = buf->ReadByte();
7087 for (uint i = 0; i < num_sets; i++) {
7088 uint8_t num_sprites = buf->ReadByte();
7089 uint16_t first_sprite = buf->ReadWord();
7091 GrfMsg(2,
"SpriteReplace: [Set {}] Changing {} sprites, beginning with {}",
7092 i, num_sprites, first_sprite
7095 for (uint j = 0; j < num_sprites; j++) {
7096 int load_index = first_sprite + j;
7102 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
7112 uint8_t num_sets = buf->ReadByte();
7114 for (uint i = 0; i < num_sets; i++) {
7121 GrfMsg(3,
"SkipActA: Skipping {} sprites", _cur.
skip_sprites);
7143 STR_NEWGRF_ERROR_VERSION_NUMBER,
7144 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
7145 STR_NEWGRF_ERROR_UNSET_SWITCH,
7146 STR_NEWGRF_ERROR_INVALID_PARAMETER,
7147 STR_NEWGRF_ERROR_LOAD_BEFORE,
7148 STR_NEWGRF_ERROR_LOAD_AFTER,
7149 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
7153 STR_NEWGRF_ERROR_MSG_INFO,
7154 STR_NEWGRF_ERROR_MSG_WARNING,
7155 STR_NEWGRF_ERROR_MSG_ERROR,
7156 STR_NEWGRF_ERROR_MSG_FATAL
7159 byte severity = buf->ReadByte();
7160 byte lang = buf->ReadByte();
7161 byte message_id = buf->ReadByte();
7164 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
7168 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
7169 GrfMsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage {}", _cur.
stage);
7174 if (severity >=
lengthof(sevstr)) {
7175 GrfMsg(7,
"GRFLoadError: Invalid severity id {}. Setting to 2 (non-fatal error).", severity);
7177 }
else if (severity == 3) {
7186 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
7187 GrfMsg(7,
"GRFLoadError: Invalid message id.");
7191 if (buf->Remaining() <= 1) {
7192 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7202 if (message_id == 0xFF) {
7204 if (buf->HasData()) {
7205 const char *message = buf->ReadString();
7209 GrfMsg(7,
"GRFLoadError: No custom message supplied.");
7213 error->
message = msgstr[message_id];
7216 if (buf->HasData()) {
7217 const char *data = buf->ReadString();
7221 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7222 error->
data.clear();
7226 for (uint i = 0; i < error->
param_value.size() && buf->HasData(); i++) {
7227 uint param_number = buf->ReadByte();
7239 if (!buf->HasData())
return;
7241 const char *text = buf->ReadString();
7242 GrfMsg(2,
"GRFComment: {}", text);
7248 uint8_t target = buf->ReadByte();
7251 if (target < 0x80 || target == 0x9E)
return;
7265 static uint32_t GetPatchVariable(uint8_t param)
7275 case 0x0F:
return 0;
7291 case 0x11:
return SPR_2CCMAP_BASE;
7308 byte max_edge = std::max(log_X, log_Y);
7310 if (log_X == log_Y) {
7313 if (max_edge == log_Y)
SetBit(map_bits, 1);
7316 return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
7317 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
7326 return SPR_SLOPES_BASE;
7337 GrfMsg(2,
"ParamSet: Unknown Patch variable 0x{:02X}.", param);
7343 static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint8_t op, uint8_t target,
const char *type)
7356 for (uint i = start; i < num_ids; i++) {
7360 if (op == 2 || op == 3)
break;
7365 if (size == count)
break;
7368 if (size == count) {
7370 if (op == 0 || op == 3) {
7371 GrfMsg(2,
"ParamSet: GRM: Reserving {} {} at {}", count, type, start);
7372 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
7378 if (op != 4 && op != 5) {
7380 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type);
7385 GrfMsg(1,
"ParamSet: GRM: Unable to allocate {} {}", count, type);
7415 uint8_t target = buf->ReadByte();
7416 uint8_t oper = buf->ReadByte();
7417 uint32_t src1 = buf->ReadByte();
7418 uint32_t src2 = buf->ReadByte();
7421 if (buf->Remaining() >= 4) data = buf->ReadDWord();
7430 if (target < 0x80 && target < _cur.grffile->param_end) {
7431 GrfMsg(7,
"ParamSet: Param {} already defined, skipping", target);
7435 oper =
GB(oper, 0, 7);
7439 if (
GB(data, 0, 8) == 0xFF) {
7440 if (data == 0x0000FFFF) {
7442 src1 = GetPatchVariable(src1);
7446 uint8_t feature =
GB(data, 8, 8);
7447 uint16_t count =
GB(data, 16, 16);
7449 if (_cur.
stage == GLS_RESERVE) {
7450 if (feature == 0x08) {
7454 if (_cur.
spriteid + count >= 16384) {
7455 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count);
7461 GrfMsg(4,
"ParamSet: GRM: Allocated {} sprites at {}", count, _cur.
spriteid);
7468 }
else if (_cur.
stage == GLS_ACTIVATION) {
7497 GrfMsg(4,
"ParamSet: GRM: Using pre-allocated sprites at {}", src1);
7505 GrfMsg(1,
"ParamSet: GRM: Unsupported operation {} for general sprites", op);
7516 default: GrfMsg(1,
"ParamSet: GRM: Unsupported feature 0x{:X}", feature);
return;
7533 }
else if (src1 == 0xFE) {
7545 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
7546 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
7568 res = (int32_t)src1 * (int32_t)src2;
7572 if ((int32_t)src2 < 0) {
7573 res = src1 >> -(int32_t)src2;
7575 res = src1 << (src2 & 0x1F);
7580 if ((int32_t)src2 < 0) {
7581 res = (int32_t)src1 >> -(int32_t)src2;
7583 res = (int32_t)src1 << (src2 & 0x1F);
7607 res = (int32_t)src1 / (int32_t)src2;
7623 res = (int32_t)src1 % (int32_t)src2;
7627 default: GrfMsg(0,
"ParamSet: Unknown operation {}, skipping", oper);
return;
7656 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7667 uint32_t safe_bits = 0;
7668 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
7677 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7681 if (target < 0x80) {
7682 _cur.
grffile->param[target] = res;
7686 GrfMsg(7,
"ParamSet: Skipping unknown target 0x{:02X}", target);
7700 uint8_t num = buf->ReadByte();
7702 for (uint i = 0; i < num; i++) {
7703 uint32_t grfid = buf->ReadDWord();
7725 uint8_t num = buf->ReadByte();
7727 for (uint i = 0; i < num; i++) {
7728 uint32_t grfid = buf->ReadDWord();
7732 if (file !=
nullptr && file != _cur.
grfconfig) {
7733 GrfMsg(2,
"GRFInhibit: Deactivating file '{}'", file->
filename);
7750 uint32_t grfid = _cur.
grffile->grfid;
7754 byte id = buf->ReadByte();
7755 GrfMsg(6,
"FeatureTownName: definition 0x{:02X}",
id & 0x7F);
7760 bool new_scheme = _cur.
grffile->grf_version >= 7;
7762 byte lang = buf->ReadByte();
7768 const char *name = buf->ReadString();
7771 GrfMsg(6,
"FeatureTownName: lang 0x{:X} -> '{}'", lang, lang_name);
7773 style =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
7775 lang = buf->ReadByte();
7776 }
while (lang != 0);
7777 townname->
styles.emplace_back(style,
id);
7780 uint8_t parts = buf->ReadByte();
7781 GrfMsg(6,
"FeatureTownName: {} parts", parts);
7784 for (uint partnum = 0; partnum < parts; partnum++) {
7786 uint8_t texts = buf->ReadByte();
7787 partlist.
bitstart = buf->ReadByte();
7788 partlist.
bitcount = buf->ReadByte();
7790 GrfMsg(6,
"FeatureTownName: part {} contains {} texts and will use GB(seed, {}, {})", partnum, texts, partlist.
bitstart, partlist.
bitcount);
7792 partlist.
parts.reserve(texts);
7793 for (uint textnum = 0; textnum < texts; textnum++) {
7795 part.
prob = buf->ReadByte();
7798 byte ref_id = buf->ReadByte();
7800 GrfMsg(0,
"FeatureTownName: definition 0x{:02X} doesn't exist, deactivating", ref_id);
7801 DelGRFTownName(grfid);
7806 GrfMsg(6,
"FeatureTownName: part {}, text {}, uses intermediate definition 0x{:02X} (with probability {})", partnum, textnum, ref_id, part.
prob & 0x7F);
7808 const char *text = buf->ReadString();
7810 GrfMsg(6,
"FeatureTownName: part {}, text {}, '{}' (with probability {})", partnum, textnum, part.
text, part.
prob);
7814 GrfMsg(6,
"FeatureTownName: part {}, total probability {}", partnum, partlist.
maxprob);
7826 byte nfo_label = buf->ReadByte();
7830 GrfMsg(2,
"DefineGotoLabel: GOTO target with label 0x{:02X}", nfo_label);
7844 if (file ==
nullptr || file->sound_offset == 0) {
7845 GrfMsg(1,
"ImportGRFSound: Source file not available");
7849 if (sound_id >= file->num_sounds) {
7850 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
7854 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid);
7856 *sound = *GetSound(file->sound_offset + sound_id);
7859 sound->volume = 128;
7860 sound->priority = 0;
7871 sound->volume = 0x80;
7872 sound->priority = 0;
7874 if (offs != SIZE_MAX) {
7876 sound->file = _cur.
file;
7877 sound->file_offset = offs;
7889 uint16_t num = buf->ReadWord();
7890 if (num == 0)
return;
7893 if (_cur.
grffile->sound_offset == 0) {
7894 _cur.
grffile->sound_offset = GetNumSounds();
7895 _cur.
grffile->num_sounds = num;
7898 sound = GetSound(_cur.
grffile->sound_offset);
7903 for (
int i = 0; i < num; i++) {
7908 bool invalid = i >= _cur.
grffile->num_sounds;
7910 size_t offs = file.
GetPos();
7915 if (grf_container_version >= 2 && type == 0xFD) {
7918 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7920 }
else if (len != 4) {
7921 GrfMsg(1,
"GRFSound: Invalid sprite section import");
7931 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7938 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7946 if (_cur.
stage == GLS_INIT) {
7947 if (grf_container_version >= 2) {
7948 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7957 if (_cur.
stage == GLS_ACTIVATION) {
7960 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
7968 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
7984 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur.
skip_sprites);
7997 uint8_t num_def = buf->ReadByte();
7999 for (uint i = 0; i < num_def; i++) {
8001 uint8_t num_char = buf->ReadByte();
8002 uint16_t base_char = buf->ReadWord();
8004 if (size >= FS_END) {
8005 GrfMsg(1,
"LoadFontGlyph: Size {} is not supported, ignoring", size);
8008 GrfMsg(7,
"LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
8010 for (uint c = 0; c < num_char; c++) {
8028 uint8_t num_def = buf->ReadByte();
8030 for (uint i = 0; i < num_def; i++) {
8041 GrfMsg(3,
"SkipAct12: Skipping {} sprites", _cur.
skip_sprites);
8054 uint32_t grfid = buf->ReadDWord();
8057 GrfMsg(7,
"TranslateGRFStrings: GRFID 0x{:08X} unknown, skipping action 13",
BSWAP32(grfid));
8066 error->
data =
GetString(STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE);
8076 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
8077 byte num_strings = buf->ReadByte();
8078 uint16_t first_id = buf->ReadWord();
8080 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
8081 GrfMsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x{:04X}, number: 0x{:02X})", first_id, num_strings);
8085 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
8086 const char *
string = buf->ReadString();
8089 GrfMsg(7,
"TranslateGRFString: Ignoring empty string.");
8093 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
8122 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got {}, ignoring this field", len);
8134 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got {}, ignoring this field", len);
8137 char data = buf->ReadByte();
8145 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'PALS', ignoring this field", data);
8160 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got {}, ignoring this field", len);
8163 char data = buf->ReadByte();
8169 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'BLTR', ignoring this field", data);
8182 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got {}, ignoring this field", len);
8195 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got {}, ignoring this field", len);
8200 GrfMsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
8231 GrfMsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got {}, ignoring this field", len);
8238 GrfMsg(3,
"StaticGRFInfo: unknown parameter type {}, ignoring this field", type);
8248 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
8250 }
else if (len != 8) {
8251 GrfMsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got {}, ignoring this field", len);
8254 uint32_t min_value = buf->ReadDWord();
8255 uint32_t max_value = buf->ReadDWord();
8256 if (min_value <= max_value) {
8260 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field");
8269 if (len < 1 || len > 3) {
8270 GrfMsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got {}, ignoring this field", len);
8273 byte param_nr = buf->ReadByte();
8275 GrfMsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param {}, ignoring this field", param_nr);
8291 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got {}, ignoring this field", len);
8327 this->handler.data = handler;
8339 this->handler.text = handler;
8351 this->handler.call_handler =
true;
8352 this->handler.u.branch = handler;
8364 this->handler.call_handler =
false;
8365 this->handler.u.subtags =
subtags;
8394 byte type = buf->ReadByte();
8396 uint32_t
id = buf->ReadDWord();
8398 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
8400 type = buf->ReadByte();
8404 byte langid = buf->ReadByte();
8405 const char *name_string = buf->ReadString();
8416 type = buf->ReadByte();
8441 byte type = buf->ReadByte();
8443 uint32_t
id = buf->ReadDWord();
8445 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
8447 type = buf->ReadByte();
8460 type = buf->ReadByte();
8497 byte new_type = buf->ReadByte();
8498 while (new_type != 0) {
8501 new_type = buf->ReadByte();
8512 uint16_t size = buf->ReadWord();
8536 while ((tag = &subtags[i++])->type != 0) {
8539 default: NOT_REACHED();
8542 byte langid = buf->ReadByte();
8543 return tag->handler.
text(langid, buf->ReadString());
8547 size_t len = buf->ReadWord();
8548 if (buf->Remaining() < len)
return false;
8549 return tag->handler.
data(len, buf);
8554 return tag->handler.u.branch(buf);
8560 GrfMsg(2,
"StaticGRFInfo: unknown type/id combination found, type={:c}, id={:x}", type,
id);
8572 byte type = buf->ReadByte();
8574 uint32_t
id = buf->ReadDWord();
8575 if (!
HandleNode(type,
id, buf, subtags))
return false;
8576 type = buf->ReadByte();
8697 file->stations.clear();
8705 file->housespec.clear();
8713 for (
auto &as : file->airportspec) {
8714 if (as !=
nullptr) {
8716 for (
int j = 0; j < as->
num_table; j++) {
8725 file->airportspec.clear();
8726 file->airtspec.clear();
8734 file->industryspec.clear();
8735 file->indtspec.clear();
8743 file->objectspec.clear();
8747 static void ResetCustomRoadStops()
8750 file->roadstops.clear();
8779 CleanUpGRFTownNames();
8823 ObjectClass::Reset();
8828 StationClass::Reset();
8832 AirportClass::Reset();
8838 RoadStopClass::Reset();
8839 ResetCustomRoadStops();
8865 _grf_id_overrides.clear();
8867 InitializeSoundPool();
8894 if (!cs->IsValid())
continue;
8914 if (newfile !=
nullptr) {
8920 newfile =
new GRFFile(config);
8938 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8943 std::fill(std::begin(this->railtype_map), std::end(this->railtype_map),
INVALID_RAILTYPE);
8950 std::fill(std::begin(this->roadtype_map), std::end(this->roadtype_map),
INVALID_ROADTYPE);
8954 std::fill(std::begin(this->tramtype_map), std::end(this->tramtype_map),
INVALID_ROADTYPE);
8959 this->param = config->
param;
8976 CargoID cid = GetCargoIDByLabel(label);
8977 if (cid != INVALID_CARGO)
return label;
8989 if (std::holds_alternative<CargoLabel>(label))
return std::get<CargoLabel>(label);
8990 if (std::holds_alternative<MixedCargoType>(label)) {
8991 switch (std::get<MixedCargoType>(label)) {
8995 default: NOT_REACHED();
9006 CargoTypes original_known_cargoes = 0;
9014 bool only_defaultcargo;
9022 if (
_gted[engine].defaultcargo_grf ==
nullptr) {
9025 static constexpr
byte T = 1 << LT_TEMPERATE;
9026 static constexpr
byte A = 1 << LT_ARCTIC;
9027 static constexpr
byte S = 1 << LT_TROPIC;
9028 static constexpr
byte Y = 1 << LT_TOYLAND;
9029 static const struct DefaultRefitMasks {
9032 CargoTypes cargo_allowed;
9033 CargoTypes cargo_disallowed;
9034 } _default_refit_masks[] = {
9036 {T | A | S , CT_MAIL,
CC_MAIL, 0},
9039 {T | A , CT_COAL,
CC_BULK, 0},
9040 { S , CT_COPPER_ORE,
CC_BULK, 0},
9056 switch (label.base()) {
9060 _gted[engine].cargo_disallowed = 0;
9065 _gted[engine].cargo_disallowed = 0;
9084 _gted[engine].cargo_disallowed = 0;
9088 for (
const auto &drm : _default_refit_masks) {
9090 if (drm.cargo_label != label)
continue;
9092 _gted[engine].cargo_allowed = drm.cargo_allowed;
9093 _gted[engine].cargo_disallowed = drm.cargo_disallowed;
9098 _gted[engine].ctt_exclude_mask = original_known_cargoes;
9101 _gted[engine].UpdateRefittability(
_gted[engine].cargo_allowed != 0);
9108 CargoTypes mask = 0;
9109 CargoTypes not_mask = 0;
9110 CargoTypes xor_mask = ei->refit_mask;
9116 if (
_gted[engine].cargo_allowed != 0) {
9119 if (
_gted[engine].cargo_allowed & cs->classes)
SetBit(mask, cs->Index());
9120 if (
_gted[engine].cargo_disallowed & cs->classes)
SetBit(not_mask, cs->Index());
9124 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
9127 ei->refit_mask |=
_gted[engine].ctt_include_mask;
9128 ei->refit_mask &= ~
_gted[engine].ctt_exclude_mask;
9137 ei->cargo_type = INVALID_CARGO;
9145 if (file ==
nullptr) file = e->
GetGRF();
9146 if (file !=
nullptr && file->grf_version >= 8 && !file->
cargo_list.empty()) {
9148 byte best_local_slot = UINT8_MAX;
9150 byte local_slot = file->
cargo_map[cargo_type];
9151 if (local_slot < best_local_slot) {
9152 best_local_slot = local_slot;
9153 ei->cargo_type = cargo_type;
9175 for (uint i = 0; i < CF_END; i++) {
9187 if (e->
GetGRF() ==
nullptr) {
9190 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
9223 default: NOT_REACHED();
9235 if (parent != e->
index)
continue;
9240 GrfMsg(1,
"FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->
index].internal_id, e->
GetGRF()->filename);
9256 switch (cs.label.base()) {
9258 case CT_MAIL.base(): cs.town_production_effect =
TPE_MAIL;
break;
9259 default: cs.town_production_effect =
TPE_NONE;
break;
9262 if (!cs.IsValid()) {
9263 cs.name = cs.name_single = cs.units_volume = STR_NEWGRF_INVALID_CARGO;
9264 cs.quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
9265 cs.abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
9289 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
9299 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);
9307 Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->
grf_prop.
local_id);
9314 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);
9333 if (hs ==
nullptr || !hs->
enabled)
continue;
9338 if (min_year == 0)
return;
9342 if (hs ==
nullptr || !hs->
enabled)
continue;
9366 if (file->housespec.empty())
continue;
9368 size_t num_houses = file->housespec.size();
9369 for (
size_t i = 0; i < num_houses; i++) {
9370 HouseSpec *hs = file->housespec[i].get();
9372 if (hs ==
nullptr)
continue;
9374 const HouseSpec *next1 = (i + 1 < num_houses ? file->housespec[i + 1].get() :
nullptr);
9375 const HouseSpec *next2 = (i + 2 < num_houses ? file->housespec[i + 2].get() :
nullptr);
9376 const HouseSpec *next3 = (i + 3 < num_houses ? file->housespec[i + 3].get() :
nullptr);
9435 for (
const auto &indsp : file->industryspec) {
9436 if (indsp ==
nullptr || !indsp->
enabled)
continue;
9443 if (strid != STR_UNDEFINED) indsp->
name = strid;
9446 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
9461 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
9467 for (
const auto &indtsp : file->indtspec) {
9468 if (indtsp !=
nullptr) {
9469 _industile_mngr.SetEntitySpec(indtsp.get());
9474 for (
auto &indsp : _industry_specs) {
9481 indsp.
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
9485 for (uint i = 0; i <
lengthof(indsp.produced_cargo); ++i) {
9493 for (
auto &indtsp : _industry_tile_specs) {
9509 for (
auto &objectspec : file->objectspec) {
9510 if (objectspec !=
nullptr && objectspec->grf_prop.grffile !=
nullptr && objectspec->IsEnabled()) {
9527 for (
auto &as : file->airportspec) {
9528 if (as !=
nullptr && as->
enabled) {
9529 _airport_mngr.SetEntitySpec(as.get());
9533 for (
auto &ats : file->airtspec) {
9534 if (ats !=
nullptr && ats->enabled) {
9535 _airporttile_mngr.SetEntitySpec(ats.get());
9547 static void DecodeSpecialSprite(
byte *buf, uint num, GrfLoadingStage stage)
9561 static const SpecialSpriteHandler handlers[][GLS_END] = {
9562 {
nullptr, SafeChangeInfo,
nullptr,
nullptr, ReserveChangeInfo, FeatureChangeInfo, },
9563 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
9564 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, NewSpriteGroup, },
9565 {
nullptr,
GRFUnsafe,
nullptr,
nullptr,
nullptr, FeatureMapSpriteGroup, },
9566 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, FeatureNewName, },
9567 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
9568 {
nullptr,
nullptr,
nullptr, CfgApply, CfgApply, CfgApply, },
9569 {
nullptr,
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, },
9570 { ScanInfo,
nullptr,
nullptr, GRFInfo, GRFInfo, GRFInfo, },
9571 {
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, SkipIf, },
9572 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
9573 {
nullptr,
nullptr,
nullptr, GRFLoadError, GRFLoadError, GRFLoadError, },
9574 {
nullptr,
nullptr,
nullptr, GRFComment,
nullptr, GRFComment, },
9576 {
nullptr, SafeGRFInhibit,
nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
9579 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
9582 {
StaticGRFInfo,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
9587 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
9588 if (it == _grf_line_to_action6_sprite_override.end()) {
9594 buf = _grf_line_to_action6_sprite_override[location].data();
9595 GrfMsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
9605 byte action = bufp->ReadByte();
9607 if (action == 0xFF) {
9608 GrfMsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
9609 }
else if (action == 0xFE) {
9610 GrfMsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
9611 }
else if (action >=
lengthof(handlers)) {
9612 GrfMsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x{:02X}", action);
9613 }
else if (handlers[action][stage] ==
nullptr) {
9614 GrfMsg(7,
"DecodeSpecialSprite: Skipping action 0x{:02X} in stage {}", action, stage);
9616 GrfMsg(7,
"DecodeSpecialSprite: Handling action 0x{:02X} in stage {}", action, stage);
9617 handlers[action][stage](bufp);
9620 GrfMsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
9636 Debug(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '{}'", config->
filename);
9639 if (grf_container_version == 0) {
9640 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9644 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
9650 if (grf_container_version >= 2) file.
ReadDword();
9653 if (grf_container_version >= 2) {
9655 byte compression = file.
ReadByte();
9656 if (compression != 0) {
9657 Debug(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
9666 if (num == 4 && file.
ReadByte() == 0xFF) {
9669 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9677 while ((num = (grf_container_version >= 2 ? file.
ReadDword() : file.
ReadWord())) != 0) {
9683 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
9694 GrfMsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
9695 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
9699 if (grf_container_version >= 2 && type == 0xFD) {
9722 const std::string &filename = config->
filename;
9733 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
9735 if (_cur.
grffile ==
nullptr) UserError(
"File '{}' lost in cache.\n", filename);
9742 SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
9796 DupSprite(SPR_ROAD_DEPOT + 0, SPR_TRAMWAY_DEPOT_NO_TRACK + 0);
9797 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 1, SPR_TRAMWAY_DEPOT_NO_TRACK + 1);
9798 DupSprite(SPR_ROAD_DEPOT + 2, SPR_TRAMWAY_DEPOT_NO_TRACK + 2);
9799 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 3, SPR_TRAMWAY_DEPOT_NO_TRACK + 3);
9800 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 4, SPR_TRAMWAY_DEPOT_NO_TRACK + 4);
9801 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 5, SPR_TRAMWAY_DEPOT_NO_TRACK + 5);
9812 static const uint32_t override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
9816 std::vector<int> grf_overrides(num_grfs, -1);
9817 for (
int i = 0; i < num_grfs; i++) {
9819 uint32_t
override = _grf_id_overrides[source->grfid];
9820 if (
override == 0)
continue;
9823 if (dest ==
nullptr)
continue;
9826 assert(grf_overrides[i] >= 0);
9830 for (
int i = 0; i < num_grfs; i++) {
9831 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
9839 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9842 Debug(grf, 3,
"'{}' overrides price base multiplier {} of '{}'", source->filename, p, dest->filename);
9848 for (
int i = num_grfs - 1; i >= 0; i--) {
9849 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9857 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9860 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, source->filename, dest->filename);
9866 for (
int i = 0; i < num_grfs; i++) {
9867 if (grf_overrides[i] < 0)
continue;
9875 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9876 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9878 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, dest->filename, source->filename);
9886 if (file->grf_version >= 8)
continue;
9887 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9888 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9890 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9893 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9900 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9901 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9902 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9904 price_base_multipliers[p] = 0;
9909 Debug(grf, 3,
"'{}' sets global price base multiplier {}", file->
filename, p);
9911 price_base_multipliers[p] = 0;
9913 Debug(grf, 3,
"'{}' sets local price base multiplier {}", file->
filename, p);
9928 _string_to_grf_mapping.clear();
9931 _grf_line_to_action6_sprite_override.clear();
9994 if (file ==
nullptr ||
_gted[e->
index].roadtramtype == 0) {
10003 if (
_gted[e->
index].roadtramtype < list->size())
10005 RoadTypeLabel rtl = (*list)[
_gted[e->
index].roadtramtype];
10034 _grm_sprites.clear();
10092 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
10099 if (stage == GLS_RESERVE) {
10100 static const uint32_t overrides[][2] = {
10101 { 0x44442202, 0x44440111 },
10102 { 0x6D620402, 0x6D620401 },
10103 { 0x4D656f20, 0x4D656F17 },
10105 for (
size_t i = 0; i <
lengthof(overrides); i++) {
10111 uint num_non_static = 0;
10113 _cur.
stage = stage;
10120 Debug(grf, 0,
"NewGRF file is missing '{}'; disabling", c->
filename);
10129 Debug(grf, 0,
"'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
10131 c->
error = {STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED};
10140 if (stage == GLS_RESERVE) {
10142 }
else if (stage == GLS_ACTIVATION) {
10147 Debug(sprite, 2,
"LoadNewGRF: Currently {} sprites are loaded", _cur.
spriteid);