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);
1158 SB(rvi->
weight, 0, 8, buf->ReadByte());
1166 GrfMsg(2,
"RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored.");
1178 uint8_t traction = buf->ReadByte();
1181 if (traction <= 0x07) {
1183 }
else if (traction <= 0x27) {
1185 }
else if (traction <= 0x31) {
1187 }
else if (traction <= 0x37) {
1189 }
else if (traction <= 0x41) {
1215 ei->refit_cost = buf->ReadByte();
1219 uint32_t mask = buf->ReadDWord();
1220 _gted[e->
index].UpdateRefittability(mask != 0);
1257 byte weight = buf->ReadByte();
1260 GrfMsg(2,
"RailVehicleChangeInfo: Nonsensical weight of {} tons, ignoring", weight << 8);
1281 _gted[e->
index].cargo_allowed = buf->ReadWord();
1287 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1301 uint8_t count = buf->ReadByte();
1302 _gted[e->
index].UpdateRefittability(prop == 0x2C && count != 0);
1304 CargoTypes &ctt = prop == 0x2C ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1350 for (
int i = 0; i < numinfo; i++) {
1361 _gted[e->
index].roadtramtype = buf->ReadByte() + 1;
1369 rvi->running_cost = buf->ReadByte();
1377 uint8_t spriteid = buf->ReadByte();
1378 uint8_t orig_spriteid = spriteid;
1381 if (spriteid == 0xFF) spriteid = 0xFD;
1383 if (spriteid < 0xFD) spriteid >>= 1;
1385 if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
1386 rvi->image_index = spriteid;
1388 GrfMsg(1,
"RoadVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1389 rvi->image_index = 0;
1395 rvi->capacity = buf->ReadByte();
1400 uint8_t ctype = buf->ReadByte();
1402 if (ctype == 0xFF) {
1404 ei->cargo_type = INVALID_CARGO;
1405 }
else if (_cur.
grffile->grf_version >= 8) {
1410 ei->cargo_type = ctype;
1412 ei->cargo_type = INVALID_CARGO;
1413 GrfMsg(2,
"RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1419 rvi->cost_factor = buf->ReadByte();
1427 rvi->
power = buf->ReadByte();
1431 rvi->
weight = buf->ReadByte();
1435 _gted[e->
index].rv_max_speed = buf->ReadByte();
1439 uint32_t mask = buf->ReadDWord();
1440 _gted[e->
index].UpdateRefittability(mask != 0);
1459 ei->refit_cost = buf->ReadByte();
1472 _gted[e->
index].cargo_allowed = buf->ReadWord();
1478 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1510 uint8_t count = buf->ReadByte();
1511 _gted[e->
index].UpdateRefittability(prop == 0x24 && count != 0);
1513 CargoTypes &ctt = prop == 0x24 ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1555 for (
int i = 0; i < numinfo; i++) {
1564 uint8_t spriteid = buf->ReadByte();
1565 uint8_t orig_spriteid = spriteid;
1568 if (spriteid == 0xFF) spriteid = 0xFD;
1570 if (spriteid < 0xFD) spriteid >>= 1;
1572 if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
1573 svi->image_index = spriteid;
1575 GrfMsg(1,
"ShipVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1576 svi->image_index = 0;
1586 svi->cost_factor = buf->ReadByte();
1595 uint8_t ctype = buf->ReadByte();
1597 if (ctype == 0xFF) {
1599 ei->cargo_type = INVALID_CARGO;
1600 }
else if (_cur.
grffile->grf_version >= 8) {
1605 ei->cargo_type = ctype;
1607 ei->cargo_type = INVALID_CARGO;
1608 GrfMsg(2,
"ShipVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype);
1614 svi->capacity = buf->ReadWord();
1618 svi->running_cost = buf->ReadByte();
1626 uint32_t mask = buf->ReadDWord();
1627 _gted[e->
index].UpdateRefittability(mask != 0);
1638 ei->refit_cost = buf->ReadByte();
1659 _gted[e->
index].cargo_allowed = buf->ReadWord();
1665 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1693 uint8_t count = buf->ReadByte();
1694 _gted[e->
index].UpdateRefittability(prop == 0x1E && count != 0);
1696 CargoTypes &ctt = prop == 0x1E ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1722 svi->
acceleration = std::max<uint8_t>(1, buf->ReadByte());
1746 for (
int i = 0; i < numinfo; i++) {
1755 uint8_t spriteid = buf->ReadByte();
1756 uint8_t orig_spriteid = spriteid;
1759 if (spriteid == 0xFF) spriteid = 0xFD;
1761 if (spriteid < 0xFD) spriteid >>= 1;
1763 if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
1764 avi->image_index = spriteid;
1766 GrfMsg(1,
"AircraftVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid);
1767 avi->image_index = 0;
1773 if (buf->ReadByte() == 0) {
1781 SB(avi->
subtype, 1, 1, (buf->ReadByte() != 0 ? 1 : 0));
1785 avi->cost_factor = buf->ReadByte();
1789 avi->
max_speed = (buf->ReadByte() * 128) / 10;
1793 avi->acceleration = buf->ReadByte();
1797 avi->running_cost = buf->ReadByte();
1813 uint32_t mask = buf->ReadDWord();
1814 _gted[e->
index].UpdateRefittability(mask != 0);
1825 ei->refit_cost = buf->ReadByte();
1838 _gted[e->
index].cargo_allowed = buf->ReadWord();
1844 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1862 uint8_t count = buf->ReadByte();
1863 _gted[e->
index].UpdateRefittability(prop == 0x1D && count != 0);
1865 CargoTypes &ctt = prop == 0x1D ?
_gted[e->
index].ctt_include_mask :
_gted[e->
index].ctt_exclude_mask;
1912 GrfMsg(1,
"StationChangeInfo: Station {} is invalid, max {}, ignoring", stid + numinfo,
NUM_STATIONS_PER_GRF);
1917 if (_cur.
grffile->stations.size() < stid + numinfo) _cur.
grffile->stations.resize(stid + numinfo);
1919 for (
int i = 0; i < numinfo; i++) {
1923 if (statspec ==
nullptr && prop != 0x08) {
1924 GrfMsg(2,
"StationChangeInfo: Attempt to modify undefined station {}, ignoring", stid + i);
1931 if (statspec ==
nullptr) {
1932 _cur.
grffile->stations[stid + i] = std::make_unique<StationSpec>();
1933 statspec = _cur.
grffile->stations[stid + i].get();
1937 uint32_t classid = buf->ReadDWord();
1938 statspec->
cls_id = StationClass::Allocate(
BSWAP32(classid));
1943 uint16_t tiles = buf->ReadExtendedByte();
1947 for (uint t = 0; t < tiles; t++) {
1951 if (buf->HasData(4) && *(uint32_t*)buf->Data() == 0) {
1954 dts->
Clone(&_station_display_datas_rail[t % 8]);
1962 static std::vector<DrawTileSeqStruct> tmp_layout;
1969 dtss.
delta_x = buf->ReadByte();
1971 dtss.delta_y = buf->ReadByte();
1972 dtss.
delta_z = buf->ReadByte();
1973 dtss.size_x = buf->ReadByte();
1974 dtss.size_y = buf->ReadByte();
1975 dtss.size_z = buf->ReadByte();
1981 dts->
Clone(tmp_layout.data());
1986 GrfMsg(1,
"StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i);
1993 uint16_t srcid = buf->ReadExtendedByte();
1994 const StationSpec *srcstatspec = srcid >= _cur.
grffile->stations.size() ? nullptr : _cur.
grffile->stations[srcid].get();
1996 if (srcstatspec ==
nullptr) {
1997 GrfMsg(1,
"StationChangeInfo: Station {} is not defined, cannot copy sprite layout to {}.", srcid, stid + i);
2004 for (
const auto &it : srcstatspec->
renderdata) {
2024 while (buf->HasData()) {
2025 byte length = buf->ReadByte();
2026 byte number = buf->ReadByte();
2028 if (length == 0 || number == 0)
break;
2030 if (statspec->
layouts.size() < length) statspec->
layouts.resize(length);
2031 if (statspec->
layouts[length - 1].size() < number) statspec->
layouts[length - 1].resize(number);
2033 const byte *layout = buf->ReadBytes(length * number);
2034 statspec->
layouts[length - 1][number - 1].assign(layout, layout + length * number);
2037 for (
auto &tile : statspec->
layouts[length - 1][number - 1]) {
2038 if ((tile & 6) != tile) {
2039 GrfMsg(1,
"StationChangeInfo: Invalid tile {} in layout {}x{}", tile, length, number);
2047 uint16_t srcid = buf->ReadExtendedByte();
2048 const StationSpec *srcstatspec = srcid >= _cur.
grffile->stations.size() ? nullptr : _cur.
grffile->stations[srcid].get();
2050 if (srcstatspec ==
nullptr) {
2051 GrfMsg(1,
"StationChangeInfo: Station {} is not defined, cannot copy tile layout to {}.", srcid, stid + i);
2064 statspec->
pylons = buf->ReadByte();
2068 if (_cur.
grffile->grf_version >= 7) {
2076 statspec->
flags = buf->ReadByte();
2080 statspec->
wires = buf->ReadByte();
2084 statspec->
blocked = buf->ReadByte();
2088 statspec->animation.
frames = buf->ReadByte();
2089 statspec->animation.
status = buf->ReadByte();
2093 statspec->animation.
speed = buf->ReadByte();
2097 statspec->animation.
triggers = buf->ReadWord();
2103 uint16_t tiles = buf->ReadExtendedByte();
2107 for (uint t = 0; t < tiles; t++) {
2109 uint num_building_sprites = buf->ReadByte();
2116 GrfMsg(1,
"StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i);
2158 if (
id + numinfo > CF_END) {
2159 GrfMsg(1,
"CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring",
id + numinfo, CF_END);
2163 for (
int i = 0; i < numinfo; i++) {
2172 cp->
flags = buf->ReadByte();
2197 GrfMsg(1,
"BridgeChangeInfo: Bridge {} is invalid, max {}, ignoring", brid + numinfo,
MAX_BRIDGES);
2201 for (
int i = 0; i < numinfo; i++) {
2207 byte year = buf->ReadByte();
2222 bridge->
price = buf->ReadByte();
2226 bridge->
speed = buf->ReadWord();
2227 if (bridge->
speed == 0) bridge->
speed = UINT16_MAX;
2231 byte tableid = buf->ReadByte();
2232 byte numtables = buf->ReadByte();
2239 for (; numtables-- != 0; tableid++) {
2241 GrfMsg(1,
"BridgeChangeInfo: Table {} >= 7, skipping", tableid);
2242 for (
byte sprite = 0; sprite < 32; sprite++) buf->ReadDWord();
2247 bridge->
sprite_table[tableid] = MallocT<PalSpriteID>(32);
2250 for (
byte sprite = 0; sprite < 32; sprite++) {
2264 bridge->
flags = buf->ReadByte();
2273 if (newone != STR_UNDEFINED) bridge->
material = newone;
2280 if (newone != STR_UNDEFINED) bridge->
transport_name[prop - 0x11] = newone;
2285 bridge->
price = buf->ReadWord();
2342 for (uint j = 0; j < 4; j++) buf->ReadByte();
2346 byte count = buf->ReadByte();
2347 for (
byte j = 0; j < count; j++) buf->ReadByte();
2352 buf->Skip(buf->ReadByte() * 2);
2375 GrfMsg(1,
"TownHouseChangeInfo: Too many houses loaded ({}), max ({}). Ignoring.", hid + numinfo,
NUM_HOUSES_PER_GRF);
2380 if (_cur.
grffile->housespec.size() < hid + numinfo) _cur.
grffile->housespec.resize(hid + numinfo);
2382 for (
int i = 0; i < numinfo; i++) {
2385 if (prop != 0x08 && housespec ==
nullptr) {
2388 if (cir > ret) ret = cir;
2394 byte subs_id = buf->ReadByte();
2395 if (subs_id == 0xFF) {
2402 GrfMsg(2,
"TownHouseChangeInfo: Attempt to use new house {} as substitute house for {}. Ignoring.", subs_id, hid + i);
2407 if (housespec ==
nullptr) {
2409 _cur.
grffile->housespec[hid + i] = std::make_unique<HouseSpec>(*HouseSpec::Get(subs_id));
2410 housespec = _cur.
grffile->housespec[hid + i].get();
2414 housespec->
grf_prop.subst_id = subs_id;
2423 housespec->
building_flags &= ~(BUILDING_IS_CHURCH | BUILDING_IS_STADIUM);
2441 uint16_t years = buf->ReadWord();
2461 int8_t goods = buf->ReadByte();
2497 byte override = buf->ReadByte();
2501 GrfMsg(2,
"TownHouseChangeInfo: Attempt to override new house {} with house id {}. Ignoring.",
override, hid + i);
2505 _house_mngr.
Add(hid + i, _cur.
grffile->grfid,
override);
2514 for (uint j = 0; j < 4; j++) housespec->
random_colour[j] =
static_cast<Colours
>(
GB(buf->ReadByte(), 0, 4));
2536 housespec->
class_id = AllocateHouseClassID(buf->ReadByte(), _cur.
grffile->grfid);
2544 uint32_t cargotypes = buf->ReadDWord();
2547 if (cargotypes == 0xFFFFFFFF)
break;
2549 for (uint j = 0; j < 3; j++) {
2551 uint8_t cargo_part =
GB(cargotypes, 8 * j, 8);
2569 byte count = buf->ReadByte();
2570 for (
byte j = 0; j < count; j++) {
2578 housespec->
min_year = buf->ReadWord();
2582 housespec->
max_year = buf->ReadWord();
2586 uint count = buf->ReadByte();
2638 template <
typename T>
2642 GrfMsg(1,
"LoadTranslationTable: {} translation table must start at zero", name);
2646 translation_table.clear();
2647 for (
int i = 0; i < numinfo; i++) {
2648 uint32_t item = buf->ReadDWord();
2649 translation_table.push_back(
BSWAP32(item));
2664 for (
int i = 0; i < 4; i++) output.push_back(reader->ReadByte());
2698 for (
int i = 0; i < numinfo; i++) {
2701 int factor = buf->ReadByte();
2702 uint price = gvid + i;
2704 if (price < PR_END) {
2707 GrfMsg(1,
"GlobalVarChangeInfo: Price {} out of range, ignoring", price);
2716 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2725 uint32_t rate = buf->ReadDWord();
2733 GrfMsg(1,
"GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx);
2740 uint16_t options = buf->ReadWord();
2749 GrfMsg(1,
"GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx);
2761 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2773 GrfMsg(1,
"GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx);
2785 GrfMsg(1,
"GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx);
2792 GrfMsg(1,
"GlobalVarChangeInfo: The snowline can only be set once ({})", numinfo);
2794 GrfMsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf->Remaining());
2800 table[i][j] = buf->ReadByte();
2801 if (_cur.
grffile->grf_version >= 8) {
2804 if (table[i][j] >= 128) {
2826 uint curidx = gvid + i;
2828 if (lang ==
nullptr) {
2829 GrfMsg(1,
"GlobalVarChangeInfo: Language {} is not known, ignoring", curidx);
2834 while (buf->ReadByte() != 0) {
2844 uint plural_form = buf->ReadByte();
2845 if (plural_form >= LANGUAGE_MAX_PLURAL) {
2846 GrfMsg(1,
"GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form);
2853 byte newgrf_id = buf->ReadByte();
2854 while (newgrf_id != 0) {
2855 const char *name = buf->ReadString();
2870 GrfMsg(1,
"GlobalVarChangeInfo: Gender name {} is not known, ignoring", name);
2877 GrfMsg(1,
"GlobalVarChangeInfo: Case name {} is not known, ignoring", name);
2882 newgrf_id = buf->ReadByte();
2918 for (
int i = 0; i < numinfo; i++) {
2942 uint32_t s = buf->ReadDWord();
2943 uint32_t t = buf->ReadDWord();
2950 while (buf->ReadByte() != 0) {
2978 GrfMsg(2,
"CargoChangeInfo: Cargo type {} out of range (max {})", cid + numinfo,
NUM_CARGO - 1);
2982 for (
int i = 0; i < numinfo; i++) {
2987 cs->
bitnum = buf->ReadByte();
3025 cs->
sprite = buf->ReadWord();
3029 cs->
weight = buf->ReadByte();
3033 cs->transit_periods[0] = buf->ReadByte();
3037 cs->transit_periods[1] = buf->ReadByte();
3045 cs->rating_colour = buf->ReadByte();
3049 cs->legend_colour = buf->ReadByte();
3057 cs->
classes = buf->ReadWord();
3061 cs->
label = buf->ReadDWord();
3066 uint8_t substitute_type = buf->ReadByte();
3068 switch (substitute_type) {
3075 GrfMsg(1,
"CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type);
3091 cs->
multiplier = std::max<uint16_t>(1u, buf->ReadWord());
3095 uint8_t substitute_type = buf->ReadByte();
3097 switch (substitute_type) {
3101 GrfMsg(1,
"CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type);
3134 if (_cur.
grffile->sound_offset == 0) {
3135 GrfMsg(1,
"SoundEffectChangeInfo: No effects defined, skipping");
3140 GrfMsg(1,
"SoundEffectChangeInfo: Attempting to change undefined sound effect ({}), max ({}). Ignoring.", sid + numinfo,
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
3144 for (
int i = 0; i < numinfo; i++) {
3149 sound->volume = buf->ReadByte();
3153 sound->priority = buf->ReadByte();
3157 SoundID orig_sound = buf->ReadByte();
3160 GrfMsg(1,
"SoundEffectChangeInfo: Original sound {} not defined (max {})", orig_sound,
ORIGINAL_SAMPLE_COUNT);
3162 SoundEntry *old_sound = GetSound(orig_sound);
3165 *old_sound = *sound;
3207 buf->Skip(buf->ReadByte() * 2);
3230 GrfMsg(1,
"IndustryTilesChangeInfo: Too many industry tiles loaded ({}), max ({}). Ignoring.", indtid + numinfo,
NUM_INDUSTRYTILES_PER_GRF);
3235 if (_cur.
grffile->indtspec.size() < indtid + numinfo) _cur.
grffile->indtspec.resize(indtid + numinfo);
3237 for (
int i = 0; i < numinfo; i++) {
3240 if (prop != 0x08 && tsp ==
nullptr) {
3242 if (cir > ret) ret = cir;
3248 byte subs_id = buf->ReadByte();
3251 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to use new industry tile {} as substitute industry tile for {}. Ignoring.", subs_id, indtid + i);
3256 if (tsp ==
nullptr) {
3257 _cur.
grffile->indtspec[indtid + i] = std::make_unique<IndustryTileSpec>(_industry_tile_specs[subs_id]);
3258 tsp = _cur.
grffile->indtspec[indtid + i].get();
3277 byte ovrid = buf->ReadByte();
3281 GrfMsg(2,
"IndustryTilesChangeInfo: Attempt to override new industry tile {} with industry tile id {}. Ignoring.", ovrid, indtid + i);
3285 _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
3292 uint16_t acctp = buf->ReadWord();
3324 byte num_cargoes = buf->ReadByte();
3325 if (num_cargoes > std::size(tsp->
acceptance)) {
3330 for (uint i = 0; i < std::size(tsp->
acceptance); i++) {
3331 if (i < num_cargoes) {
3334 tsp->
acceptance[i] = (int8_t)buf->ReadByte();
3398 byte num_table = buf->ReadByte();
3399 for (
byte j = 0; j < num_table; j++) {
3400 for (uint k = 0;; k++) {
3401 byte x = buf->ReadByte();
3402 if (x == 0xFE && k == 0) {
3408 byte y = buf->ReadByte();
3409 if (x == 0 && y == 0x80)
break;
3411 byte gfx = buf->ReadByte();
3412 if (gfx == 0xFE) buf->ReadWord();
3419 for (
byte j = 0; j < 3; j++) buf->ReadByte();
3426 buf->Skip(buf->ReadByte());
3430 int num_inputs = buf->ReadByte();
3431 int num_outputs = buf->ReadByte();
3432 buf->Skip(num_inputs * num_outputs * 2);
3450 const size_t size = layout.size();
3451 if (size == 0)
return false;
3453 for (
size_t i = 0; i < size - 1; i++) {
3454 for (
size_t j = i + 1; j < size; j++) {
3455 if (layout[i].ti.x == layout[j].ti.x &&
3456 layout[i].ti.y == layout[j].ti.y) {
3462 bool have_regular_tile =
false;
3463 for (
const auto &tilelayout : layout) {
3465 have_regular_tile =
true;
3470 return have_regular_tile;
3486 GrfMsg(1,
"IndustriesChangeInfo: Too many industries loaded ({}), max ({}). Ignoring.", indid + numinfo,
NUM_INDUSTRYTYPES_PER_GRF);
3491 if (_cur.
grffile->industryspec.size() < indid + numinfo) _cur.
grffile->industryspec.resize(indid + numinfo);
3493 for (
int i = 0; i < numinfo; i++) {
3496 if (prop != 0x08 && indsp ==
nullptr) {
3498 if (cir > ret) ret = cir;
3504 byte subs_id = buf->ReadByte();
3505 if (subs_id == 0xFF) {
3508 _industry_specs[indid + i].
enabled =
false;
3512 GrfMsg(2,
"_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id, indid + i);
3519 if (indsp ==
nullptr) {
3520 _cur.
grffile->industryspec[indid + i] = std::make_unique<IndustrySpec>(_origin_industry_specs[subs_id]);
3521 indsp = _cur.
grffile->industryspec[indid + i].get();
3525 indsp->
grf_prop.subst_id = subs_id;
3535 byte ovrid = buf->ReadByte();
3539 GrfMsg(2,
"IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid, indid + i);
3543 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3548 byte new_num_layouts = buf->ReadByte();
3549 uint32_t definition_size = buf->ReadDWord();
3550 uint32_t bytes_read = 0;
3551 std::vector<IndustryTileLayout> new_layouts;
3554 for (
byte j = 0; j < new_num_layouts; j++) {
3557 for (uint k = 0;; k++) {
3558 if (bytes_read >= definition_size) {
3559 GrfMsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.", indid);
3561 definition_size = UINT32_MAX;
3567 it.ti.
x = buf->ReadByte();
3570 if (it.ti.
x == 0xFE && k == 0) {
3572 IndustryType type = buf->ReadByte();
3573 byte laynbr = buf->ReadByte();
3576 if (type >=
lengthof(_origin_industry_specs)) {
3577 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry {}", indid);
3581 if (laynbr >= _origin_industry_specs[type].layouts.size()) {
3582 GrfMsg(1,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}", indid);
3586 layout = _origin_industry_specs[type].layouts[laynbr];
3590 it.ti.
y = buf->ReadByte();
3593 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
3599 it.gfx = buf->ReadByte();
3602 if (it.gfx == 0xFE) {
3604 int local_tile_id = buf->ReadWord();
3608 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3611 GrfMsg(2,
"IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id, indid);
3617 it.ti.
x = (int8_t)
GB(it.ti.
x, 0, 8);
3618 it.ti.
y = (int8_t)
GB(it.ti.
y, 0, 8);
3627 if (_cur.
grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
3633 GrfMsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring", indid);
3637 new_layouts.push_back(layout);
3667 for (
byte j = 0; j < 2; j++) {
3673 for (
byte j = 0; j < 3; j++) {
3681 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3694 sounds[j] = buf->ReadByte();
3710 for (
byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3736 uint32_t multiples = buf->ReadDWord();
3752 byte aflag = buf->ReadByte();
3762 uint16_t str = buf->ReadWord();
3772 byte num_cargoes = buf->ReadByte();
3773 if (num_cargoes >
lengthof(indsp->produced_cargo)) {
3778 for (uint i = 0; i <
lengthof(indsp->produced_cargo); i++) {
3779 if (i < num_cargoes) {
3781 indsp->produced_cargo[i] = cargo;
3783 indsp->produced_cargo[i] = INVALID_CARGO;
3790 byte num_cargoes = buf->ReadByte();
3797 if (i < num_cargoes) {
3808 byte num_cargoes = buf->ReadByte();
3809 if (num_cargoes >
lengthof(indsp->production_rate)) {
3814 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
3815 if (i < num_cargoes) {
3816 indsp->production_rate[i] = buf->ReadByte();
3818 indsp->production_rate[i] = 0;
3825 byte num_inputs = buf->ReadByte();
3826 byte num_outputs = buf->ReadByte();
3833 for (uint j = 0; j <
lengthof(indsp->produced_cargo); j++) {
3835 if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
3859 for (
int i = 0; i < as->
num_table; i++) {
3864 }
while ((++it)->ti.x != -0x80);
3865 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3868 as->
table = table_list;
3890 GrfMsg(1,
"AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3895 if (_cur.
grffile->airportspec.size() < airport + numinfo) _cur.
grffile->airportspec.resize(airport + numinfo);
3897 for (
int i = 0; i < numinfo; i++) {
3900 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
3901 GrfMsg(2,
"AirportChangeInfo: Attempt to modify undefined airport {}, ignoring", airport + i);
3907 byte subs_id = buf->ReadByte();
3908 if (subs_id == 0xFF) {
3915 GrfMsg(2,
"AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id, airport + i);
3922 if (as ==
nullptr) {
3924 as = _cur.
grffile->airportspec[airport + i].get();
3931 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3943 uint32_t defsize = buf->ReadDWord();
3949 for (
byte j = 0; j < as->
num_table; j++) {
3951 for (
int k = 0;; k++) {
3952 att[k].
ti.
x = buf->ReadByte();
3953 att[k].
ti.
y = buf->ReadByte();
3955 if (att[k].ti.x == 0 && att[k].
ti.
y == 0x80) {
3958 att[k].
ti.
x = -0x80;
3967 att[k].
gfx = buf->ReadByte();
3969 if (att[k].gfx == 0xFE) {
3971 int local_tile_id = buf->ReadWord();
3974 uint16_t tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3977 GrfMsg(2,
"AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id, airport + i);
3980 att[k].
gfx = tempid;
3982 }
else if (att[k].gfx == 0xFF) {
3983 att[k].
ti.
x = (int8_t)
GB(att[k].ti.x, 0, 8);
3984 att[k].
ti.
y = (int8_t)
GB(att[k].ti.y, 0, 8);
3995 tile_table[j] = CallocT<AirportTileTable>(size);
3996 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
3999 for (
int j = 0; j < old_num_table; j++) {
4005 as->
table = tile_table;
4008 for (
int i = 0; i < as->
num_table; i++) {
4009 free(tile_table[i]);
4111 GrfMsg(1,
"ObjectChangeInfo: Too many objects loaded ({}), max ({}). Ignoring.",
id + numinfo,
NUM_OBJECTS_PER_GRF);
4116 if (_cur.
grffile->objectspec.size() <
id + numinfo) _cur.
grffile->objectspec.resize(
id + numinfo);
4118 for (
int i = 0; i < numinfo; i++) {
4121 if (prop != 0x08 && spec ==
nullptr) {
4124 if (cir > ret) ret = cir;
4131 if (spec ==
nullptr) {
4132 _cur.
grffile->objectspec[
id + i] = std::make_unique<ObjectSpec>();
4133 spec = _cur.
grffile->objectspec[
id + i].get();
4139 uint32_t classid = buf->ReadDWord();
4155 spec->
climate = buf->ReadByte();
4159 spec->
size = buf->ReadByte();
4160 if (
GB(spec->
size, 0, 4) == 0 ||
GB(spec->
size, 4, 4) == 0) {
4161 GrfMsg(0,
"ObjectChangeInfo: Invalid object size requested (0x{:X}) for object id {}. Ignoring.", spec->
size,
id + i);
4206 spec->
height = buf->ReadByte();
4210 spec->
views = buf->ReadByte();
4212 GrfMsg(2,
"ObjectChangeInfo: Invalid number of views ({}) for object id {}. Ignoring.", spec->
views,
id + i);
4245 GrfMsg(1,
"RailTypeChangeInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4249 for (
int i = 0; i < numinfo; i++) {
4262 uint16_t str = buf->ReadWord();
4264 if (_cur.
grffile->grf_version < 8) {
4294 int n = buf->ReadByte();
4295 for (
int j = 0; j != n; j++) {
4296 RailTypeLabel label = buf->ReadDWord();
4356 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4375 GrfMsg(1,
"RailTypeReserveInfo: Rail type {} is invalid, max {}, ignoring",
id + numinfo,
RAILTYPE_END);
4379 for (
int i = 0; i < numinfo; i++) {
4383 RailTypeLabel rtl = buf->ReadDWord();
4392 _cur.
grffile->railtype_map[
id + i] = rt;
4410 int n = buf->ReadByte();
4411 for (
int j = 0; j != n; j++) {
4416 GrfMsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set",
id + i);
4423 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4464 GrfMsg(1,
"RoadTypeChangeInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4468 for (
int i = 0; i < numinfo; i++) {
4481 uint16_t str = buf->ReadWord();
4508 int n = buf->ReadByte();
4509 for (
int j = 0; j != n; j++) {
4510 RoadTypeLabel label = buf->ReadDWord();
4515 if (GetRoadTramType(resolved_rt) == rtt) {
4518 GrfMsg(1,
"RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt);
4563 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4594 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid, max {}, ignoring",
id + numinfo,
ROADTYPE_END);
4598 for (
int i = 0; i < numinfo; i++) {
4601 RoadTypeLabel rtl = buf->ReadDWord();
4608 }
else if (GetRoadTramType(rt) != rtt) {
4609 GrfMsg(1,
"RoadTypeReserveInfo: Road type {} is invalid type (road/tram), ignoring",
id + numinfo);
4613 type_map[
id + i] = rt;
4630 int n = buf->ReadByte();
4631 for (
int j = 0; j != n; j++) {
4636 GrfMsg(1,
"RoadTypeReserveInfo: Ignoring property 1D for road type {} because no label was set",
id + i);
4642 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4666 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_ROAD);
4671 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_TRAM);
4679 GrfMsg(1,
"AirportTileChangeInfo: Too many airport tiles loaded ({}), max ({}). Ignoring.", airtid + numinfo,
NUM_AIRPORTTILES_PER_GRF);
4684 if (_cur.
grffile->airtspec.size() < airtid + numinfo) _cur.
grffile->airtspec.resize(airtid + numinfo);
4686 for (
int i = 0; i < numinfo; i++) {
4689 if (prop != 0x08 && tsp ==
nullptr) {
4690 GrfMsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile {}. Ignoring.", airtid + i);
4696 byte subs_id = buf->ReadByte();
4699 GrfMsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile {} as substitute airport tile for {}. Ignoring.", subs_id, airtid + i);
4704 if (tsp ==
nullptr) {
4706 tsp = _cur.
grffile->airtspec[airtid + i].get();
4721 byte override = buf->ReadByte();
4725 GrfMsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile {} with airport tile id {}. Ignoring.",
override, airtid + i);
4729 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4804 GrfMsg(1,
"RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring",
id + numinfo,
NUM_ROADSTOPS_PER_GRF);
4808 if (_cur.
grffile->roadstops.size() <
id + numinfo) _cur.
grffile->roadstops.resize(
id + numinfo);
4810 for (
int i = 0; i < numinfo; i++) {
4813 if (rs ==
nullptr && prop != 0x08) {
4814 GrfMsg(1,
"RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring",
id + i);
4816 if (cir > ret) ret = cir;
4822 if (rs ==
nullptr) {
4823 _cur.
grffile->roadstops[
id + i] = std::make_unique<RoadStopSpec>();
4824 rs = _cur.
grffile->roadstops[
id + i].get();
4827 uint32_t classid = buf->ReadDWord();
4854 rs->animation.
frames = buf->ReadByte();
4855 rs->animation.
status = buf->ReadByte();
4859 rs->animation.
speed = buf->ReadByte();
4863 rs->animation.
triggers = buf->ReadWord();
4867 rs->callback_mask = buf->ReadByte();
4871 rs->flags = (uint8_t)buf->ReadDWord();
4888 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8_t feature, uint8_t property)
4891 default: NOT_REACHED();
4901 GrfMsg(1,
"{}: Ignoring property 0x{:02X} of feature 0x{:02X} (not implemented)", caller, property, feature);
4905 GrfMsg(0,
"{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature);
4918 static void FeatureChangeInfo(
ByteReader *buf)
4931 static const VCI_Handler handler[] = {
4949 AirportTilesChangeInfo,
4954 static_assert(GSF_END ==
lengthof(handler));
4956 uint8_t feature = buf->ReadByte();
4957 uint8_t numprops = buf->ReadByte();
4958 uint numinfo = buf->ReadByte();
4959 uint engine = buf->ReadExtendedByte();
4961 if (feature >= GSF_END) {
4962 GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4966 GrfMsg(6,
"FeatureChangeInfo: Feature 0x{:02X}, {} properties, to apply to {}+{}",
4967 feature, numprops, engine, numinfo);
4969 if (handler[feature] ==
nullptr) {
4970 if (feature != GSF_CARGOES) GrfMsg(1,
"FeatureChangeInfo: Unsupported feature 0x{:02X}, skipping", feature);
4977 while (numprops-- && buf->HasData()) {
4978 uint8_t prop = buf->ReadByte();
4981 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
4988 uint8_t feature = buf->ReadByte();
4989 uint8_t numprops = buf->ReadByte();
4990 uint numinfo = buf->ReadByte();
4991 buf->ReadExtendedByte();
4993 if (feature == GSF_BRIDGES && numprops == 1) {
4994 uint8_t prop = buf->ReadByte();
4997 if (prop == 0x0D)
return;
4998 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
4999 uint8_t prop = buf->ReadByte();
5002 bool is_safe =
true;
5003 for (uint i = 0; i < numinfo; i++) {
5004 uint32_t s = buf->ReadDWord();
5012 if (is_safe)
return;
5023 static void ReserveChangeInfo(
ByteReader *buf)
5025 uint8_t feature = buf->ReadByte();
5027 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES && feature != GSF_ROADTYPES && feature != GSF_TRAMTYPES)
return;
5029 uint8_t numprops = buf->ReadByte();
5030 uint8_t numinfo = buf->ReadByte();
5031 uint8_t index = buf->ReadExtendedByte();
5033 while (numprops-- && buf->HasData()) {
5034 uint8_t prop = buf->ReadByte();
5038 default: NOT_REACHED();
5044 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
5048 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
5052 cir = RoadTypeReserveInfo(index, numinfo, prop, buf);
5056 cir = TramTypeReserveInfo(index, numinfo, prop, buf);
5060 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
5081 uint8_t feature = buf->ReadByte();
5082 uint16_t num_sets = buf->ReadByte();
5083 uint16_t first_set = 0;
5085 if (num_sets == 0 && buf->HasData(3)) {
5088 first_set = buf->ReadExtendedByte();
5089 num_sets = buf->ReadExtendedByte();
5091 uint16_t num_ents = buf->ReadExtendedByte();
5093 if (feature >= GSF_END) {
5095 GrfMsg(1,
"NewSpriteSet: Unsupported feature 0x{:02X}, skipping {} sprites", feature, _cur.
skip_sprites);
5101 GrfMsg(7,
"New sprite set at {} of feature 0x{:02X}, consisting of {} sets with {} views each (total {})",
5102 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
5105 for (
int i = 0; i < num_sets * num_ents; i++) {
5115 uint16_t num_sets = buf->ReadByte();
5117 if (num_sets == 0 && buf->HasData(3)) {
5120 buf->ReadExtendedByte();
5121 num_sets = buf->ReadExtendedByte();
5123 uint16_t num_ents = buf->ReadExtendedByte();
5127 GrfMsg(3,
"SkipAct1: Skipping {} sprites", _cur.
skip_sprites);
5132 static const SpriteGroup *GetGroupFromGroupID(
byte setid,
byte type, uint16_t groupid)
5134 if (
HasBit(groupid, 15)) {
5139 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5140 GrfMsg(1,
"GetGroupFromGroupID(0x{:02X}:0x{:02X}): Groupid 0x{:04X} does not exist, leaving empty", setid, type, groupid);
5144 return _cur.spritegroups[groupid];
5157 if (
HasBit(spriteid, 15)) {
5163 GrfMsg(1,
"CreateGroupFromGroupID(0x{:02X}:0x{:02X}): Sprite set {} invalid", setid, type, spriteid);
5168 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
5171 assert(spriteset_start + num_sprites <= _cur.
spriteid);
5192 uint8_t feature = buf->ReadByte();
5193 if (feature >= GSF_END) {
5194 GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5198 uint8_t setid = buf->ReadByte();
5199 uint8_t type = buf->ReadByte();
5223 switch (
GB(type, 2, 2)) {
5224 default: NOT_REACHED();
5225 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
5226 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
5227 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
5237 adjust.variable = buf->ReadByte();
5238 if (adjust.variable == 0x7E) {
5240 adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
5245 varadjust = buf->ReadByte();
5246 adjust.shift_num =
GB(varadjust, 0, 5);
5247 adjust.type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
5248 adjust.and_mask = buf->ReadVarSize(varsize);
5250 if (adjust.type != DSGA_TYPE_NONE) {
5251 adjust.add_val = buf->ReadVarSize(varsize);
5252 adjust.divmod_val = buf->ReadVarSize(varsize);
5255 adjust.divmod_val = 0;
5259 }
while (
HasBit(varadjust, 5));
5261 std::vector<DeterministicSpriteGroupRange> ranges;
5262 ranges.resize(buf->ReadByte());
5263 for (uint i = 0; i < ranges.size(); i++) {
5264 ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5265 ranges[i].low = buf->ReadVarSize(varsize);
5266 ranges[i].high = buf->ReadVarSize(varsize);
5269 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5270 group->error_group = ranges.empty() ? group->default_group : ranges[0].group;
5272 group->calculated_result = ranges.empty();
5275 std::vector<uint32_t> bounds;
5276 for (uint i = 0; i < ranges.size(); i++) {
5277 bounds.push_back(ranges[i].low);
5278 if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1);
5280 std::sort(bounds.begin(), bounds.end());
5281 bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
5283 std::vector<const SpriteGroup *> target;
5284 for (uint j = 0; j < bounds.size(); ++j) {
5285 uint32_t v = bounds[j];
5287 for (uint i = 0; i < ranges.size(); i++) {
5288 if (ranges[i].low <= v && v <= ranges[i].high) {
5289 t = ranges[i].group;
5293 target.push_back(t);
5295 assert(target.size() == bounds.size());
5297 for (uint j = 0; j < bounds.size(); ) {
5298 if (target[j] != group->default_group) {
5300 r.group = target[j];
5302 while (j < bounds.size() && target[j] == r.group) {
5305 r.high = j < bounds.size() ? bounds[j] - 1 : UINT32_MAX;
5327 group->count = buf->ReadByte();
5330 uint8_t triggers = buf->ReadByte();
5331 group->triggers =
GB(triggers, 0, 7);
5332 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
5335 byte num_groups = buf->ReadByte();
5337 GrfMsg(1,
"NewSpriteGroup: Random Action 2 nrand should be power of 2");
5340 for (uint i = 0; i < num_groups; i++) {
5341 group->
groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
5352 case GSF_ROADVEHICLES:
5363 byte num_loaded = type;
5364 byte num_loading = buf->ReadByte();
5367 GrfMsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
5371 GrfMsg(6,
"NewSpriteGroup: New SpriteGroup 0x{:02X}, {} loaded, {} loading",
5372 setid, num_loaded, num_loading);
5374 if (num_loaded + num_loading == 0) {
5375 GrfMsg(1,
"NewSpriteGroup: no result, skipping invalid RealSpriteGroup");
5379 if (num_loaded + num_loading == 1) {
5381 uint16_t spriteid = buf->ReadWord();
5383 GrfMsg(8,
"NewSpriteGroup: one result, skipping RealSpriteGroup = subset {}", spriteid);
5387 std::vector<uint16_t> loaded;
5388 std::vector<uint16_t> loading;
5390 for (uint i = 0; i < num_loaded; i++) {
5391 loaded.push_back(buf->ReadWord());
5392 GrfMsg(8,
"NewSpriteGroup: + rg->loaded[{}] = subset {}", i, loaded[i]);
5395 for (uint i = 0; i < num_loading; i++) {
5396 loading.push_back(buf->ReadWord());
5397 GrfMsg(8,
"NewSpriteGroup: + rg->loading[{}] = subset {}", i, loading[i]);
5400 if (std::adjacent_find(loaded.begin(), loaded.end(), std::not_equal_to<>()) == loaded.end() &&
5401 std::adjacent_find(loading.begin(), loading.end(), std::not_equal_to<>()) == loading.end() &&
5402 loaded[0] == loading[0])
5406 GrfMsg(8,
"NewSpriteGroup: same result, skipping RealSpriteGroup = subset {}", loaded[0]);
5415 for (uint16_t spriteid : loaded) {
5417 group->
loaded.push_back(t);
5420 for (uint16_t spriteid : loading) {
5429 case GSF_AIRPORTTILES:
5431 case GSF_INDUSTRYTILES:
5432 case GSF_ROADSTOPS: {
5433 byte num_building_sprites = std::max((uint8_t)1, type);
5441 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
5445 case GSF_INDUSTRIES: {
5447 GrfMsg(1,
"NewSpriteGroup: Unsupported industry production version {}, skipping", type);
5458 for (uint i = 0; i < 3; i++) {
5462 for (uint i = 0; i < 2; i++) {
5465 group->again = buf->ReadByte();
5466 }
else if (type == 1) {
5468 for (uint i = 0; i < 3; i++) {
5472 for (uint i = 0; i < 2; i++) {
5475 group->again = buf->ReadByte();
5476 }
else if (type == 2) {
5480 error->
data =
"too many inputs (max 16)";
5483 for (uint i = 0; i < group->
num_input; i++) {
5484 byte rawcargo = buf->ReadByte();
5493 error->
data =
"duplicate input cargo";
5502 error->
data =
"too many outputs (max 16)";
5505 for (uint i = 0; i < group->
num_output; i++) {
5506 byte rawcargo = buf->ReadByte();
5513 error->
data =
"duplicate output cargo";
5519 group->again = buf->ReadByte();
5527 default: GrfMsg(1,
"NewSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
5532 _cur.spritegroups[setid] = act_group;
5535 static CargoID TranslateCargo(uint8_t feature, uint8_t ctype)
5544 GrfMsg(1,
"TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype);
5545 return INVALID_CARGO;
5549 if (cs->bitnum == ctype) {
5550 GrfMsg(6,
"TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index());
5555 GrfMsg(5,
"TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype);
5556 return INVALID_CARGO;
5561 GrfMsg(1,
"TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (
unsigned int)_cur.
grffile->
cargo_list.size() - 1);
5562 return INVALID_CARGO;
5568 GrfMsg(5,
"TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype);
5569 return INVALID_CARGO;
5574 GrfMsg(5,
"TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' unsupported, skipping.",
GB(cl, 24, 8),
GB(cl, 16, 8),
GB(cl, 8, 8),
GB(cl, 0, 8));
5575 return INVALID_CARGO;
5578 GrfMsg(6,
"TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' mapped to cargo type {}.",
GB(cl, 24, 8),
GB(cl, 16, 8),
GB(cl, 8, 8),
GB(cl, 0, 8), cid);
5583 static bool IsValidGroupID(uint16_t groupid,
const char *
function)
5585 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5586 GrfMsg(1,
"{}: Spritegroup 0x{:04X} out of range or empty, skipping.",
function, groupid);
5593 static void VehicleMapSpriteGroup(
ByteReader *buf,
byte feature, uint8_t idcount)
5596 static uint last_engines_count;
5597 bool wagover =
false;
5600 if (
HasBit(idcount, 7)) {
5603 idcount =
GB(idcount, 0, 7);
5605 if (last_engines_count == 0) {
5606 GrfMsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
5610 GrfMsg(6,
"VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons",
5611 last_engines_count, idcount);
5613 if (last_engines_count != idcount) {
5614 last_engines =
ReallocT(last_engines, idcount);
5615 last_engines_count = idcount;
5619 std::vector<EngineID> engines;
5620 for (uint i = 0; i < idcount; i++) {
5626 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
5630 engines.push_back(e->
index);
5631 if (!wagover) last_engines[i] = engines[i];
5634 uint8_t cidcount = buf->ReadByte();
5635 for (uint c = 0; c < cidcount; c++) {
5636 uint8_t ctype = buf->ReadByte();
5637 uint16_t groupid = buf->ReadWord();
5638 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
5640 GrfMsg(8,
"VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid);
5642 CargoID cid = TranslateCargo(feature, ctype);
5645 for (uint i = 0; i < idcount; i++) {
5648 GrfMsg(7,
"VehicleMapSpriteGroup: [{}] Engine {}...", i, engine);
5651 SetWagonOverrideSprites(engine, cid, _cur.spritegroups[groupid], last_engines, last_engines_count);
5653 SetCustomEngineSprites(engine, cid, _cur.spritegroups[groupid]);
5658 uint16_t groupid = buf->ReadWord();
5659 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
5661 GrfMsg(8,
"-- Default group id 0x{:04X}", groupid);
5663 for (uint i = 0; i < idcount; i++) {
5676 static void CanalMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5678 std::vector<uint16_t> cfs;
5679 cfs.reserve(idcount);
5680 for (uint i = 0; i < idcount; i++) {
5681 cfs.push_back(buf->ReadExtendedByte());
5684 uint8_t cidcount = buf->ReadByte();
5685 buf->Skip(cidcount * 3);
5687 uint16_t groupid = buf->ReadWord();
5688 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
5690 for (
auto &cf : cfs) {
5692 GrfMsg(1,
"CanalMapSpriteGroup: Canal subset {} out of range, skipping", cf);
5702 static void StationMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5704 if (_cur.
grffile->stations.empty()) {
5705 GrfMsg(1,
"StationMapSpriteGroup: No stations defined, skipping");
5709 std::vector<uint16_t> stations;
5710 stations.reserve(idcount);
5711 for (uint i = 0; i < idcount; i++) {
5712 stations.push_back(buf->ReadExtendedByte());
5715 uint8_t cidcount = buf->ReadByte();
5716 for (uint c = 0; c < cidcount; c++) {
5717 uint8_t ctype = buf->ReadByte();
5718 uint16_t groupid = buf->ReadWord();
5719 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5721 ctype = TranslateCargo(GSF_STATIONS, ctype);
5724 for (
auto &station : stations) {
5727 if (statspec ==
nullptr) {
5728 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5736 uint16_t groupid = buf->ReadWord();
5737 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5739 for (
auto &station : stations) {
5742 if (statspec ==
nullptr) {
5743 GrfMsg(1,
"StationMapSpriteGroup: Station {} undefined, skipping", station);
5748 GrfMsg(1,
"StationMapSpriteGroup: Station {} mapped multiple times, skipping", station);
5755 StationClass::Assign(statspec);
5760 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5762 if (_cur.
grffile->housespec.empty()) {
5763 GrfMsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5767 std::vector<uint16_t> houses;
5768 houses.reserve(idcount);
5769 for (uint i = 0; i < idcount; i++) {
5770 houses.push_back(buf->ReadExtendedByte());
5774 uint8_t cidcount = buf->ReadByte();
5775 buf->Skip(cidcount * 3);
5777 uint16_t groupid = buf->ReadWord();
5778 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5780 for (
auto &house : houses) {
5783 if (hs ==
nullptr) {
5784 GrfMsg(1,
"TownHouseMapSpriteGroup: House {} undefined, skipping.", house);
5792 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5794 if (_cur.
grffile->industryspec.empty()) {
5795 GrfMsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5799 std::vector<uint16_t> industries;
5800 industries.reserve(idcount);
5801 for (uint i = 0; i < idcount; i++) {
5802 industries.push_back(buf->ReadExtendedByte());
5806 uint8_t cidcount = buf->ReadByte();
5807 buf->Skip(cidcount * 3);
5809 uint16_t groupid = buf->ReadWord();
5810 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5812 for (
auto &industry : industries) {
5815 if (indsp ==
nullptr) {
5816 GrfMsg(1,
"IndustryMapSpriteGroup: Industry {} undefined, skipping", industry);
5824 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5826 if (_cur.
grffile->indtspec.empty()) {
5827 GrfMsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5831 std::vector<uint16_t> indtiles;
5832 indtiles.reserve(idcount);
5833 for (uint i = 0; i < idcount; i++) {
5834 indtiles.push_back(buf->ReadExtendedByte());
5838 uint8_t cidcount = buf->ReadByte();
5839 buf->Skip(cidcount * 3);
5841 uint16_t groupid = buf->ReadWord();
5842 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5844 for (
auto &indtile : indtiles) {
5847 if (indtsp ==
nullptr) {
5848 GrfMsg(1,
"IndustrytileMapSpriteGroup: Industry tile {} undefined, skipping", indtile);
5856 static void CargoMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5858 std::vector<uint16_t> cargoes;
5859 cargoes.reserve(idcount);
5860 for (uint i = 0; i < idcount; i++) {
5861 cargoes.push_back(buf->ReadExtendedByte());
5865 uint8_t cidcount = buf->ReadByte();
5866 buf->Skip(cidcount * 3);
5868 uint16_t groupid = buf->ReadWord();
5869 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5871 for (
auto &cid : cargoes) {
5873 GrfMsg(1,
"CargoMapSpriteGroup: Cargo ID {} out of range, skipping", cid);
5879 cs->group = _cur.spritegroups[groupid];
5883 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5885 if (_cur.
grffile->objectspec.empty()) {
5886 GrfMsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5890 std::vector<uint16_t> objects;
5891 objects.reserve(idcount);
5892 for (uint i = 0; i < idcount; i++) {
5893 objects.push_back(buf->ReadExtendedByte());
5896 uint8_t cidcount = buf->ReadByte();
5897 for (uint c = 0; c < cidcount; c++) {
5898 uint8_t ctype = buf->ReadByte();
5899 uint16_t groupid = buf->ReadWord();
5900 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5903 if (ctype != 0xFF) {
5904 GrfMsg(1,
"ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype);
5908 for (
auto &
object : objects) {
5911 if (spec ==
nullptr) {
5912 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5920 uint16_t groupid = buf->ReadWord();
5921 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5923 for (
auto &
object : objects) {
5926 if (spec ==
nullptr) {
5927 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} undefined, skipping",
object);
5932 GrfMsg(1,
"ObjectMapSpriteGroup: Object {} mapped multiple times, skipping",
object);
5942 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
5944 std::vector<uint8_t> railtypes;
5945 railtypes.reserve(idcount);
5946 for (uint i = 0; i < idcount; i++) {
5947 uint16_t
id = buf->ReadExtendedByte();
5948 railtypes.push_back(id < RAILTYPE_END ? _cur.grffile->railtype_map[
id] :
INVALID_RAILTYPE);
5951 uint8_t cidcount = buf->ReadByte();
5952 for (uint c = 0; c < cidcount; c++) {
5953 uint8_t ctype = buf->ReadByte();
5954 uint16_t groupid = buf->ReadWord();
5955 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5957 if (ctype >= RTSG_END)
continue;
5960 for (
auto &railtype : railtypes) {
5965 rti->
group[ctype] = _cur.spritegroups[groupid];
5974 static void RoadTypeMapSpriteGroup(
ByteReader *buf, uint8_t idcount, RoadTramType rtt)
5978 std::vector<uint8_t> roadtypes;
5979 roadtypes.reserve(idcount);
5980 for (uint i = 0; i < idcount; i++) {
5981 uint16_t
id = buf->ReadExtendedByte();
5985 uint8_t cidcount = buf->ReadByte();
5986 for (uint c = 0; c < cidcount; c++) {
5987 uint8_t ctype = buf->ReadByte();
5988 uint16_t groupid = buf->ReadWord();
5989 if (!IsValidGroupID(groupid,
"RoadTypeMapSpriteGroup"))
continue;
5991 if (ctype >= ROTSG_END)
continue;
5994 for (
auto &roadtype : roadtypes) {
5999 rti->
group[ctype] = _cur.spritegroups[groupid];
6008 static void AirportMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6010 if (_cur.
grffile->airportspec.empty()) {
6011 GrfMsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
6015 std::vector<uint16_t> airports;
6016 airports.reserve(idcount);
6017 for (uint i = 0; i < idcount; i++) {
6018 airports.push_back(buf->ReadExtendedByte());
6022 uint8_t cidcount = buf->ReadByte();
6023 buf->Skip(cidcount * 3);
6025 uint16_t groupid = buf->ReadWord();
6026 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
6028 for (
auto &airport : airports) {
6031 if (as ==
nullptr) {
6032 GrfMsg(1,
"AirportMapSpriteGroup: Airport {} undefined, skipping", airport);
6040 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6042 if (_cur.
grffile->airtspec.empty()) {
6043 GrfMsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
6047 std::vector<uint16_t> airptiles;
6048 airptiles.reserve(idcount);
6049 for (uint i = 0; i < idcount; i++) {
6050 airptiles.push_back(buf->ReadExtendedByte());
6054 uint8_t cidcount = buf->ReadByte();
6055 buf->Skip(cidcount * 3);
6057 uint16_t groupid = buf->ReadWord();
6058 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
6060 for (
auto &airptile : airptiles) {
6063 if (airtsp ==
nullptr) {
6064 GrfMsg(1,
"AirportTileMapSpriteGroup: Airport tile {} undefined, skipping", airptile);
6072 static void RoadStopMapSpriteGroup(
ByteReader *buf, uint8_t idcount)
6074 if (_cur.
grffile->roadstops.empty()) {
6075 GrfMsg(1,
"RoadStopMapSpriteGroup: No roadstops defined, skipping");
6079 std::vector<uint16_t> roadstops;
6080 roadstops.reserve(idcount);
6081 for (uint i = 0; i < idcount; i++) {
6082 roadstops.push_back(buf->ReadExtendedByte());
6085 uint8_t cidcount = buf->ReadByte();
6086 for (uint c = 0; c < cidcount; c++) {
6087 uint8_t ctype = buf->ReadByte();
6088 uint16_t groupid = buf->ReadWord();
6089 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
continue;
6091 ctype = TranslateCargo(GSF_ROADSTOPS, ctype);
6094 for (
auto &roadstop : roadstops) {
6097 if (roadstopspec ==
nullptr) {
6098 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping", roadstop);
6106 uint16_t groupid = buf->ReadWord();
6107 if (!IsValidGroupID(groupid,
"RoadStopMapSpriteGroup"))
return;
6109 for (
auto &roadstop : roadstops) {
6112 if (roadstopspec ==
nullptr) {
6113 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} undefined, skipping.", roadstop);
6118 GrfMsg(1,
"RoadStopMapSpriteGroup: Road stop {} mapped multiple times, skipping", roadstop);
6125 RoadStopClass::Assign(roadstopspec);
6130 static void FeatureMapSpriteGroup(
ByteReader *buf)
6146 uint8_t feature = buf->ReadByte();
6147 uint8_t idcount = buf->ReadByte();
6149 if (feature >= GSF_END) {
6150 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6158 uint16_t groupid = buf->ReadWord();
6159 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
6161 GrfMsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature 0x{:02X}", feature);
6170 GrfMsg(6,
"FeatureMapSpriteGroup: Feature 0x{:02X}, {} ids", feature, idcount);
6174 case GSF_ROADVEHICLES:
6177 VehicleMapSpriteGroup(buf, feature, idcount);
6181 CanalMapSpriteGroup(buf, idcount);
6185 StationMapSpriteGroup(buf, idcount);
6189 TownHouseMapSpriteGroup(buf, idcount);
6192 case GSF_INDUSTRIES:
6193 IndustryMapSpriteGroup(buf, idcount);
6196 case GSF_INDUSTRYTILES:
6197 IndustrytileMapSpriteGroup(buf, idcount);
6201 CargoMapSpriteGroup(buf, idcount);
6205 AirportMapSpriteGroup(buf, idcount);
6209 ObjectMapSpriteGroup(buf, idcount);
6213 RailTypeMapSpriteGroup(buf, idcount);
6217 RoadTypeMapSpriteGroup(buf, idcount, RTT_ROAD);
6221 RoadTypeMapSpriteGroup(buf, idcount, RTT_TRAM);
6224 case GSF_AIRPORTTILES:
6225 AirportTileMapSpriteGroup(buf, idcount);
6229 RoadStopMapSpriteGroup(buf, idcount);
6233 GrfMsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x{:02X}, skipping", feature);
6257 bool new_scheme = _cur.
grffile->grf_version >= 7;
6259 uint8_t feature = buf->ReadByte();
6260 if (feature >= GSF_END && feature != 0x48) {
6261 GrfMsg(1,
"FeatureNewName: Unsupported feature 0x{:02X}, skipping", feature);
6265 uint8_t lang = buf->ReadByte();
6266 uint8_t num = buf->ReadByte();
6267 bool generic =
HasBit(lang, 7);
6270 id = buf->ReadWord();
6271 }
else if (feature <= GSF_AIRCRAFT) {
6272 id = buf->ReadExtendedByte();
6274 id = buf->ReadByte();
6279 uint16_t endid =
id + num;
6281 GrfMsg(6,
"FeatureNewName: About to rename engines {}..{} (feature 0x{:02X}) in language 0x{:02X}",
6282 id, endid, feature, lang);
6284 for (;
id < endid && buf->HasData();
id++) {
6285 const char *name = buf->ReadString();
6286 GrfMsg(8,
"FeatureNewName: 0x{:04X} <- {}",
id, name);
6290 case GSF_ROADVEHICLES:
6295 if (e ==
nullptr)
break;
6309 switch (
GB(
id, 8, 8)) {
6311 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6312 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6320 if (
GB(
id, 0, 8) >= _cur.
grffile->stations.size() || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6321 GrfMsg(1,
"FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring",
GB(
id, 0, 8));
6328 if (
GB(
id, 0, 8) >= _cur.
grffile->airtspec.size() || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
6329 GrfMsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring",
GB(
id, 0, 8));
6336 if (
GB(
id, 0, 8) >= _cur.
grffile->housespec.size() || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
6337 GrfMsg(1,
"FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.",
GB(
id, 0, 8));
6339 _cur.
grffile->housespec[
GB(
id, 0, 8)]->building_name =
AddGRFString(_cur.
grffile->grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6344 GrfMsg(7,
"FeatureNewName: Unsupported ID (0x{:04X})",
id);
6363 if (offset >= max_sprites) {
6364 GrfMsg(1,
"GraphicsNew: {} sprite offset must be less than {}, skipping", name, max_sprites);
6365 uint orig_num = num;
6370 if (offset + num > max_sprites) {
6371 GrfMsg(4,
"GraphicsNew: {} sprite overflow, truncating...", name);
6372 uint orig_num = num;
6373 num = std::max(max_sprites - offset, 0);
6374 return orig_num - num;
6403 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
6405 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
6435 uint8_t type = buf->ReadByte();
6436 uint16_t num = buf->ReadExtendedByte();
6437 uint16_t offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
6443 GrfMsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
6460 GrfMsg(2,
"GraphicsNew: Custom graphics (type 0x{:02X}) sprite block of length {} (unimplemented, ignoring)", type, num);
6471 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
6478 GrfMsg(1,
"GraphicsNew: {} (type 0x{:02X}) count must be at least {}. Only {} were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
6488 GrfMsg(2,
"GraphicsNew: Replacing sprites {} to {} of {} (type 0x{:02X}) at SpriteID 0x{:04X}", offset, offset + num - 1, action5_type->
name, type, replace);
6500 bool dup_oneway_sprites = ((type == 0x09) && (offset + num <= SPR_ONEWAY_SLOPE_N_OFFSET));
6502 for (; num > 0; num--) {
6504 int load_index = (replace == 0 ? _cur.
spriteid++ : replace++);
6506 if (dup_oneway_sprites) {
6507 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET);
6508 DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_S_OFFSET);
6524 GrfMsg(3,
"SkipAct5: Skipping {} sprites", _cur.
skip_sprites);
6577 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
6607 *value = _game_mode;
6641 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
6650 *value = _openttd_newgrf_version;
6665 default:
return false;
6669 static uint32_t GetParamVal(
byte param, uint32_t *cond_val)
6688 if (cond_val ==
nullptr) {
6692 uint32_t index = *cond_val / 0x20;
6708 GrfMsg(1,
"Unsupported in-game variable 0x{:02X}", param);
6729 size_t pos = file.
GetPos();
6735 GrfMsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
6738 file.
SeekTo(pos, SEEK_SET);
6744 std::vector<byte> &preload_sprite = _grf_line_to_action6_sprite_override[location];
6747 if (preload_sprite.empty()) {
6748 preload_sprite.resize(num);
6749 file.
ReadBlock(preload_sprite.data(), num);
6753 file.
SeekTo(pos, SEEK_SET);
6764 param_num = buf->ReadByte();
6765 if (param_num == 0xFF)
break;
6769 param_size = buf->ReadByte();
6773 add_value =
HasBit(param_size, 7);
6774 param_size =
GB(param_size, 0, 7);
6777 offset = buf->ReadExtendedByte();
6781 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
6782 GrfMsg(2,
"CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4));
6786 GrfMsg(8,
"CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset);
6789 for (i = 0; i < param_size && offset + i < num; i++) {
6790 uint32_t value = GetParamVal(param_num + i / 4,
nullptr);
6793 if (i % 4 == 0) carry =
false;
6796 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
6797 preload_sprite[offset + i] =
GB(new_value, 0, 8);
6799 carry = new_value >= 256;
6801 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6833 uint32_t cond_val = 0;
6837 uint8_t param = buf->ReadByte();
6838 uint8_t paramsize = buf->ReadByte();
6839 uint8_t condtype = buf->ReadByte();
6846 switch (paramsize) {
6847 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6848 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6849 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6850 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6854 if (param < 0x80 && _cur.grffile->param_end <= param) {
6855 GrfMsg(7,
"SkipIf: Param {} undefined, skipping test", param);
6859 GrfMsg(7,
"SkipIf: Test condtype {}, param 0x{:02X}, condval 0x{:08X}", condtype, param, cond_val);
6864 if (condtype >= 0x0B) {
6895 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6897 }
else if (param == 0x88) {
6907 if (condtype != 10 && c ==
nullptr) {
6908 GrfMsg(7,
"SkipIf: GRFID 0x{:08X} unknown, skipping test",
BSWAP32(cond_val));
6935 default: GrfMsg(1,
"SkipIf: Unsupported GRF condition type {:02X}. Ignoring", condtype);
return;
6939 uint32_t param_val = GetParamVal(param, &cond_val);
6941 case 0x00: result = !!(param_val & (1 << cond_val));
6943 case 0x01: result = !(param_val & (1 << cond_val));
6945 case 0x02: result = (param_val & mask) == cond_val;
6947 case 0x03: result = (param_val & mask) != cond_val;
6949 case 0x04: result = (param_val & mask) < cond_val;
6951 case 0x05: result = (param_val & mask) > cond_val;
6953 default: GrfMsg(1,
"SkipIf: Unsupported condition type {:02X}. Ignoring", condtype);
return;
6958 GrfMsg(2,
"SkipIf: Not skipping sprites, test was false");
6962 uint8_t numsprites = buf->ReadByte();
6970 if (label.label != numsprites)
continue;
6973 if (choice ==
nullptr) choice = &label;
6975 if (label.nfo_line > _cur.
nfo_line) {
6981 if (choice !=
nullptr) {
6982 GrfMsg(2,
"SkipIf: Jumping to label 0x{:X} at line {}, test was true", choice->label, choice->nfo_line);
6988 GrfMsg(2,
"SkipIf: Skipping {} sprites, test was true", numsprites);
7007 uint8_t grf_version = buf->ReadByte();
7008 uint32_t grfid = buf->ReadDWord();
7009 const char *name = buf->ReadString();
7013 if (grf_version < 2 || grf_version > 8) {
7015 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);
7023 if (buf->HasData()) {
7024 const char *info = buf->ReadString();
7042 uint8_t version = buf->ReadByte();
7043 uint32_t grfid = buf->ReadDWord();
7044 const char *name = buf->ReadString();
7047 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
7051 if (_cur.
grffile->grfid != grfid) {
7052 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));
7056 _cur.
grffile->grf_version = version;
7074 uint8_t num_sets = buf->ReadByte();
7076 for (uint i = 0; i < num_sets; i++) {
7077 uint8_t num_sprites = buf->ReadByte();
7078 uint16_t first_sprite = buf->ReadWord();
7080 GrfMsg(2,
"SpriteReplace: [Set {}] Changing {} sprites, beginning with {}",
7081 i, num_sprites, first_sprite
7084 for (uint j = 0; j < num_sprites; j++) {
7085 int load_index = first_sprite + j;
7091 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
7101 uint8_t num_sets = buf->ReadByte();
7103 for (uint i = 0; i < num_sets; i++) {
7110 GrfMsg(3,
"SkipActA: Skipping {} sprites", _cur.
skip_sprites);
7132 STR_NEWGRF_ERROR_VERSION_NUMBER,
7133 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
7134 STR_NEWGRF_ERROR_UNSET_SWITCH,
7135 STR_NEWGRF_ERROR_INVALID_PARAMETER,
7136 STR_NEWGRF_ERROR_LOAD_BEFORE,
7137 STR_NEWGRF_ERROR_LOAD_AFTER,
7138 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
7142 STR_NEWGRF_ERROR_MSG_INFO,
7143 STR_NEWGRF_ERROR_MSG_WARNING,
7144 STR_NEWGRF_ERROR_MSG_ERROR,
7145 STR_NEWGRF_ERROR_MSG_FATAL
7148 byte severity = buf->ReadByte();
7149 byte lang = buf->ReadByte();
7150 byte message_id = buf->ReadByte();
7153 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
7157 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
7158 GrfMsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage {}", _cur.
stage);
7163 if (severity >=
lengthof(sevstr)) {
7164 GrfMsg(7,
"GRFLoadError: Invalid severity id {}. Setting to 2 (non-fatal error).", severity);
7166 }
else if (severity == 3) {
7175 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
7176 GrfMsg(7,
"GRFLoadError: Invalid message id.");
7180 if (buf->Remaining() <= 1) {
7181 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7191 if (message_id == 0xFF) {
7193 if (buf->HasData()) {
7194 const char *message = buf->ReadString();
7198 GrfMsg(7,
"GRFLoadError: No custom message supplied.");
7202 error->
message = msgstr[message_id];
7205 if (buf->HasData()) {
7206 const char *data = buf->ReadString();
7210 GrfMsg(7,
"GRFLoadError: No message data supplied.");
7211 error->
data.clear();
7215 for (uint i = 0; i < error->
param_value.size() && buf->HasData(); i++) {
7216 uint param_number = buf->ReadByte();
7228 if (!buf->HasData())
return;
7230 const char *text = buf->ReadString();
7231 GrfMsg(2,
"GRFComment: {}", text);
7237 uint8_t target = buf->ReadByte();
7240 if (target < 0x80 || target == 0x9E)
return;
7254 static uint32_t GetPatchVariable(uint8_t param)
7264 case 0x0F:
return 0;
7280 case 0x11:
return SPR_2CCMAP_BASE;
7297 byte max_edge = std::max(log_X, log_Y);
7299 if (log_X == log_Y) {
7302 if (max_edge == log_Y)
SetBit(map_bits, 1);
7305 return (map_bits << 24) | (std::min(log_X, log_Y) << 20) | (max_edge << 16) |
7306 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
7315 return SPR_SLOPES_BASE;
7326 GrfMsg(2,
"ParamSet: Unknown Patch variable 0x{:02X}.", param);
7332 static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint8_t op, uint8_t target,
const char *type)
7345 for (uint i = start; i < num_ids; i++) {
7349 if (op == 2 || op == 3)
break;
7354 if (size == count)
break;
7357 if (size == count) {
7359 if (op == 0 || op == 3) {
7360 GrfMsg(2,
"ParamSet: GRM: Reserving {} {} at {}", count, type, start);
7361 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
7367 if (op != 4 && op != 5) {
7369 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type);
7374 GrfMsg(1,
"ParamSet: GRM: Unable to allocate {} {}", count, type);
7404 uint8_t target = buf->ReadByte();
7405 uint8_t oper = buf->ReadByte();
7406 uint32_t src1 = buf->ReadByte();
7407 uint32_t src2 = buf->ReadByte();
7410 if (buf->Remaining() >= 4) data = buf->ReadDWord();
7419 if (target < 0x80 && target < _cur.grffile->param_end) {
7420 GrfMsg(7,
"ParamSet: Param {} already defined, skipping", target);
7424 oper =
GB(oper, 0, 7);
7428 if (
GB(data, 0, 8) == 0xFF) {
7429 if (data == 0x0000FFFF) {
7431 src1 = GetPatchVariable(src1);
7435 uint8_t feature =
GB(data, 8, 8);
7436 uint16_t count =
GB(data, 16, 16);
7438 if (_cur.
stage == GLS_RESERVE) {
7439 if (feature == 0x08) {
7443 if (_cur.
spriteid + count >= 16384) {
7444 GrfMsg(0,
"ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count);
7450 GrfMsg(4,
"ParamSet: GRM: Allocated {} sprites at {}", count, _cur.
spriteid);
7457 }
else if (_cur.
stage == GLS_ACTIVATION) {
7486 GrfMsg(4,
"ParamSet: GRM: Using pre-allocated sprites at {}", src1);
7494 GrfMsg(1,
"ParamSet: GRM: Unsupported operation {} for general sprites", op);
7505 default: GrfMsg(1,
"ParamSet: GRM: Unsupported feature 0x{:X}", feature);
return;
7522 }
else if (src1 == 0xFE) {
7534 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
7535 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
7557 res = (int32_t)src1 * (int32_t)src2;
7561 if ((int32_t)src2 < 0) {
7562 res = src1 >> -(int32_t)src2;
7564 res = src1 << (src2 & 0x1F);
7569 if ((int32_t)src2 < 0) {
7570 res = (int32_t)src1 >> -(int32_t)src2;
7572 res = (int32_t)src1 << (src2 & 0x1F);
7596 res = (int32_t)src1 / (int32_t)src2;
7612 res = (int32_t)src1 % (int32_t)src2;
7616 default: GrfMsg(0,
"ParamSet: Unknown operation {}, skipping", oper);
return;
7645 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7656 uint32_t safe_bits = 0;
7657 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
7666 GrfMsg(7,
"ParamSet: Skipping unimplemented target 0x{:02X}", target);
7670 if (target < 0x80) {
7671 _cur.
grffile->param[target] = res;
7675 GrfMsg(7,
"ParamSet: Skipping unknown target 0x{:02X}", target);
7689 uint8_t num = buf->ReadByte();
7691 for (uint i = 0; i < num; i++) {
7692 uint32_t grfid = buf->ReadDWord();
7714 uint8_t num = buf->ReadByte();
7716 for (uint i = 0; i < num; i++) {
7717 uint32_t grfid = buf->ReadDWord();
7721 if (file !=
nullptr && file != _cur.
grfconfig) {
7722 GrfMsg(2,
"GRFInhibit: Deactivating file '{}'", file->
filename);
7739 uint32_t grfid = _cur.
grffile->grfid;
7743 byte id = buf->ReadByte();
7744 GrfMsg(6,
"FeatureTownName: definition 0x{:02X}",
id & 0x7F);
7749 bool new_scheme = _cur.
grffile->grf_version >= 7;
7751 byte lang = buf->ReadByte();
7757 const char *name = buf->ReadString();
7760 GrfMsg(6,
"FeatureTownName: lang 0x{:X} -> '{}'", lang, lang_name);
7762 style =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
7764 lang = buf->ReadByte();
7765 }
while (lang != 0);
7766 townname->
styles.emplace_back(style,
id);
7769 uint8_t parts = buf->ReadByte();
7770 GrfMsg(6,
"FeatureTownName: {} parts", parts);
7773 for (uint partnum = 0; partnum < parts; partnum++) {
7775 uint8_t texts = buf->ReadByte();
7776 partlist.
bitstart = buf->ReadByte();
7777 partlist.
bitcount = buf->ReadByte();
7779 GrfMsg(6,
"FeatureTownName: part {} contains {} texts and will use GB(seed, {}, {})", partnum, texts, partlist.
bitstart, partlist.
bitcount);
7781 partlist.
parts.reserve(texts);
7782 for (uint textnum = 0; textnum < texts; textnum++) {
7784 part.
prob = buf->ReadByte();
7787 byte ref_id = buf->ReadByte();
7789 GrfMsg(0,
"FeatureTownName: definition 0x{:02X} doesn't exist, deactivating", ref_id);
7790 DelGRFTownName(grfid);
7795 GrfMsg(6,
"FeatureTownName: part {}, text {}, uses intermediate definition 0x{:02X} (with probability {})", partnum, textnum, ref_id, part.
prob & 0x7F);
7797 const char *text = buf->ReadString();
7799 GrfMsg(6,
"FeatureTownName: part {}, text {}, '{}' (with probability {})", partnum, textnum, part.
text, part.
prob);
7803 GrfMsg(6,
"FeatureTownName: part {}, total probability {}", partnum, partlist.
maxprob);
7815 byte nfo_label = buf->ReadByte();
7819 GrfMsg(2,
"DefineGotoLabel: GOTO target with label 0x{:02X}", nfo_label);
7833 if (file ==
nullptr || file->sound_offset == 0) {
7834 GrfMsg(1,
"ImportGRFSound: Source file not available");
7838 if (sound_id >= file->num_sounds) {
7839 GrfMsg(1,
"ImportGRFSound: Sound effect {} is invalid", sound_id);
7843 GrfMsg(2,
"ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid);
7845 *sound = *GetSound(file->sound_offset + sound_id);
7848 sound->volume = 128;
7849 sound->priority = 0;
7860 sound->volume = 0x80;
7861 sound->priority = 0;
7863 if (offs != SIZE_MAX) {
7865 sound->file = _cur.
file;
7866 sound->file_offset = offs;
7878 uint16_t num = buf->ReadWord();
7879 if (num == 0)
return;
7882 if (_cur.
grffile->sound_offset == 0) {
7883 _cur.
grffile->sound_offset = GetNumSounds();
7884 _cur.
grffile->num_sounds = num;
7887 sound = GetSound(_cur.
grffile->sound_offset);
7892 for (
int i = 0; i < num; i++) {
7897 bool invalid = i >= _cur.
grffile->num_sounds;
7899 size_t offs = file.
GetPos();
7904 if (grf_container_version >= 2 && type == 0xFD) {
7907 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7909 }
else if (len != 4) {
7910 GrfMsg(1,
"GRFSound: Invalid sprite section import");
7920 GrfMsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7927 GrfMsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7935 if (_cur.
stage == GLS_INIT) {
7936 if (grf_container_version >= 2) {
7937 GrfMsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7946 if (_cur.
stage == GLS_ACTIVATION) {
7949 if (file.
ReadByte() != 0) GrfMsg(1,
"GRFSound: Import type mismatch");
7957 GrfMsg(1,
"GRFSound: Unexpected Action {:x} found, skipping", action);
7973 GrfMsg(3,
"SkipAct11: Skipping {} sprites", _cur.
skip_sprites);
7986 uint8_t num_def = buf->ReadByte();
7988 for (uint i = 0; i < num_def; i++) {
7990 uint8_t num_char = buf->ReadByte();
7991 uint16_t base_char = buf->ReadWord();
7993 if (size >= FS_END) {
7994 GrfMsg(1,
"LoadFontGlyph: Size {} is not supported, ignoring", size);
7997 GrfMsg(7,
"LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size);
7999 for (uint c = 0; c < num_char; c++) {
8017 uint8_t num_def = buf->ReadByte();
8019 for (uint i = 0; i < num_def; i++) {
8030 GrfMsg(3,
"SkipAct12: Skipping {} sprites", _cur.
skip_sprites);
8043 uint32_t grfid = buf->ReadDWord();
8046 GrfMsg(7,
"TranslateGRFStrings: GRFID 0x{:08X} unknown, skipping action 13",
BSWAP32(grfid));
8055 error->
data =
GetString(STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE);
8065 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
8066 byte num_strings = buf->ReadByte();
8067 uint16_t first_id = buf->ReadWord();
8069 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
8070 GrfMsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x{:04X}, number: 0x{:02X})", first_id, num_strings);
8074 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
8075 const char *
string = buf->ReadString();
8078 GrfMsg(7,
"TranslateGRFString: Ignoring empty string.");
8082 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
8111 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got {}, ignoring this field", len);
8123 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got {}, ignoring this field", len);
8126 char data = buf->ReadByte();
8134 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'PALS', ignoring this field", data);
8149 GrfMsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got {}, ignoring this field", len);
8152 char data = buf->ReadByte();
8158 GrfMsg(2,
"StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'BLTR', ignoring this field", data);
8171 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got {}, ignoring this field", len);
8184 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got {}, ignoring this field", len);
8189 GrfMsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
8220 GrfMsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got {}, ignoring this field", len);
8227 GrfMsg(3,
"StaticGRFInfo: unknown parameter type {}, ignoring this field", type);
8237 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
8239 }
else if (len != 8) {
8240 GrfMsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got {}, ignoring this field", len);
8243 uint32_t min_value = buf->ReadDWord();
8244 uint32_t max_value = buf->ReadDWord();
8245 if (min_value <= max_value) {
8249 GrfMsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field");
8258 if (len < 1 || len > 3) {
8259 GrfMsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got {}, ignoring this field", len);
8262 byte param_nr = buf->ReadByte();
8264 GrfMsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param {}, ignoring this field", param_nr);
8280 GrfMsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got {}, ignoring this field", len);
8316 this->handler.data = handler;
8328 this->handler.text = handler;
8340 this->handler.call_handler =
true;
8341 this->handler.u.branch = handler;
8353 this->handler.call_handler =
false;
8354 this->handler.u.subtags =
subtags;
8383 byte type = buf->ReadByte();
8385 uint32_t
id = buf->ReadDWord();
8387 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
8389 type = buf->ReadByte();
8393 byte langid = buf->ReadByte();
8394 const char *name_string = buf->ReadString();
8405 type = buf->ReadByte();
8430 byte type = buf->ReadByte();
8432 uint32_t
id = buf->ReadDWord();
8434 GrfMsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
8436 type = buf->ReadByte();
8449 type = buf->ReadByte();
8486 byte new_type = buf->ReadByte();
8487 while (new_type != 0) {
8490 new_type = buf->ReadByte();
8501 uint16_t size = buf->ReadWord();
8525 while ((tag = &subtags[i++])->type != 0) {
8528 default: NOT_REACHED();
8531 byte langid = buf->ReadByte();
8532 return tag->handler.
text(langid, buf->ReadString());
8536 size_t len = buf->ReadWord();
8537 if (buf->Remaining() < len)
return false;
8538 return tag->handler.
data(len, buf);
8543 return tag->handler.u.branch(buf);
8549 GrfMsg(2,
"StaticGRFInfo: unknown type/id combination found, type={:c}, id={:x}", type,
id);
8561 byte type = buf->ReadByte();
8563 uint32_t
id = buf->ReadDWord();
8564 if (!
HandleNode(type,
id, buf, subtags))
return false;
8565 type = buf->ReadByte();
8686 file->stations.clear();
8694 file->housespec.clear();
8702 for (
auto &as : file->airportspec) {
8703 if (as !=
nullptr) {
8705 for (
int j = 0; j < as->
num_table; j++) {
8714 file->airportspec.clear();
8715 file->airtspec.clear();
8723 file->industryspec.clear();
8724 file->indtspec.clear();
8732 file->objectspec.clear();
8736 static void ResetCustomRoadStops()
8739 file->roadstops.clear();
8768 CleanUpGRFTownNames();
8812 ObjectClass::Reset();
8817 StationClass::Reset();
8821 AirportClass::Reset();
8827 RoadStopClass::Reset();
8828 ResetCustomRoadStops();
8854 _grf_id_overrides.clear();
8856 InitializeSoundPool();
8883 if (!cs->IsValid())
continue;
8903 if (newfile !=
nullptr) {
8909 newfile =
new GRFFile(config);
8927 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8932 std::fill(std::begin(this->railtype_map), std::end(this->railtype_map),
INVALID_RAILTYPE);
8939 std::fill(std::begin(this->roadtype_map), std::end(this->roadtype_map),
INVALID_ROADTYPE);
8943 std::fill(std::begin(this->tramtype_map), std::end(this->tramtype_map),
INVALID_ROADTYPE);
8948 this->param = config->
param;
8963 CargoTypes original_known_cargoes = 0;
8972 bool only_defaultcargo;
8975 if (
_gted[engine].defaultcargo_grf ==
nullptr) {
8978 static constexpr
byte T = 1 << LT_TEMPERATE;
8979 static constexpr
byte A = 1 << LT_ARCTIC;
8980 static constexpr
byte S = 1 << LT_TROPIC;
8981 static constexpr
byte Y = 1 << LT_TOYLAND;
8982 static const struct DefaultRefitMasks {
8985 CargoTypes cargo_allowed;
8986 CargoTypes cargo_disallowed;
8987 } _default_refit_masks[] = {
8989 {T | A | S , CT_MAIL,
CC_MAIL, 0},
8992 {T | A , CT_COAL,
CC_BULK, 0},
8993 { S , CT_COPPER_ORE,
CC_BULK, 0},
9008 switch (ei->cargo_type) {
9012 _gted[engine].cargo_disallowed = 0;
9017 _gted[engine].cargo_disallowed = 0;
9036 _gted[engine].cargo_disallowed = 0;
9039 for (
const auto &drm : _default_refit_masks) {
9041 if (drm.cargo_type != ei->cargo_type)
continue;
9043 _gted[engine].cargo_allowed = drm.cargo_allowed;
9044 _gted[engine].cargo_disallowed = drm.cargo_disallowed;
9049 _gted[engine].ctt_exclude_mask = original_known_cargoes;
9052 _gted[engine].UpdateRefittability(
_gted[engine].cargo_allowed != 0);
9061 CargoTypes mask = 0;
9062 CargoTypes not_mask = 0;
9063 CargoTypes xor_mask = ei->refit_mask;
9069 if (
_gted[engine].cargo_allowed != 0) {
9072 if (
_gted[engine].cargo_allowed & cs->classes)
SetBit(mask, cs->Index());
9073 if (
_gted[engine].cargo_disallowed & cs->classes)
SetBit(not_mask, cs->Index());
9077 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
9080 ei->refit_mask |=
_gted[engine].ctt_include_mask;
9081 ei->refit_mask &= ~
_gted[engine].ctt_exclude_mask;
9090 ei->cargo_type = INVALID_CARGO;
9098 if (file ==
nullptr) file = e->
GetGRF();
9099 if (file !=
nullptr && file->grf_version >= 8 && !file->
cargo_list.empty()) {
9101 byte best_local_slot = UINT8_MAX;
9103 byte local_slot = file->
cargo_map[cargo_type];
9104 if (local_slot < best_local_slot) {
9105 best_local_slot = local_slot;
9106 ei->cargo_type = cargo_type;
9128 for (uint i = 0; i < CF_END; i++) {
9140 if (e->
GetGRF() ==
nullptr) {
9143 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
9176 default: NOT_REACHED();
9188 if (parent != e->
index)
continue;
9193 GrfMsg(1,
"FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->
index].internal_id, e->
GetGRF()->filename);
9211 case 'MAIL': cs.town_production_effect =
TPE_MAIL;
break;
9212 default: cs.town_production_effect =
TPE_NONE;
break;
9215 if (!cs.IsValid()) {
9216 cs.name = cs.name_single = cs.units_volume = STR_NEWGRF_INVALID_CARGO;
9217 cs.quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
9218 cs.abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
9242 if (!filename.empty())
Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
9252 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);
9260 Debug(grf, 1,
"FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->
grf_prop.
local_id);
9267 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);
9286 if (hs ==
nullptr || !hs->
enabled)
continue;
9291 if (min_year == 0)
return;
9295 if (hs ==
nullptr || !hs->
enabled)
continue;
9319 if (file->housespec.empty())
continue;
9321 size_t num_houses = file->housespec.size();
9322 for (
size_t i = 0; i < num_houses; i++) {
9323 HouseSpec *hs = file->housespec[i].get();
9325 if (hs ==
nullptr)
continue;
9327 const HouseSpec *next1 = (i + 1 < num_houses ? file->housespec[i + 1].get() :
nullptr);
9328 const HouseSpec *next2 = (i + 2 < num_houses ? file->housespec[i + 2].get() :
nullptr);
9329 const HouseSpec *next3 = (i + 3 < num_houses ? file->housespec[i + 3].get() :
nullptr);
9381 for (
const auto &indsp : file->industryspec) {
9382 if (indsp ==
nullptr || !indsp->
enabled)
continue;
9389 if (strid != STR_UNDEFINED) indsp->
name = strid;
9392 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
9407 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
9413 for (
const auto &indtsp : file->indtspec) {
9414 if (indtsp !=
nullptr) {
9415 _industile_mngr.SetEntitySpec(indtsp.get());
9420 for (
auto &indsp : _industry_specs) {
9427 indsp.
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
9440 for (
auto &objectspec : file->objectspec) {
9441 if (objectspec !=
nullptr && objectspec->grf_prop.grffile !=
nullptr && objectspec->IsEnabled()) {
9458 for (
auto &as : file->airportspec) {
9459 if (as !=
nullptr && as->
enabled) {
9460 _airport_mngr.SetEntitySpec(as.get());
9464 for (
auto &ats : file->airtspec) {
9465 if (ats !=
nullptr && ats->enabled) {
9466 _airporttile_mngr.SetEntitySpec(ats.get());
9478 static void DecodeSpecialSprite(
byte *buf, uint num, GrfLoadingStage stage)
9492 static const SpecialSpriteHandler handlers[][GLS_END] = {
9493 {
nullptr, SafeChangeInfo,
nullptr,
nullptr, ReserveChangeInfo, FeatureChangeInfo, },
9494 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
9495 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, NewSpriteGroup, },
9496 {
nullptr,
GRFUnsafe,
nullptr,
nullptr,
nullptr, FeatureMapSpriteGroup, },
9497 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, FeatureNewName, },
9498 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
9499 {
nullptr,
nullptr,
nullptr, CfgApply, CfgApply, CfgApply, },
9500 {
nullptr,
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, },
9501 { ScanInfo,
nullptr,
nullptr, GRFInfo, GRFInfo, GRFInfo, },
9502 {
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, SkipIf, },
9503 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
9504 {
nullptr,
nullptr,
nullptr, GRFLoadError, GRFLoadError, GRFLoadError, },
9505 {
nullptr,
nullptr,
nullptr, GRFComment,
nullptr, GRFComment, },
9507 {
nullptr, SafeGRFInhibit,
nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
9510 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
9513 {
StaticGRFInfo,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
9518 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
9519 if (it == _grf_line_to_action6_sprite_override.end()) {
9525 buf = _grf_line_to_action6_sprite_override[location].data();
9526 GrfMsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
9536 byte action = bufp->ReadByte();
9538 if (action == 0xFF) {
9539 GrfMsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
9540 }
else if (action == 0xFE) {
9541 GrfMsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
9542 }
else if (action >=
lengthof(handlers)) {
9543 GrfMsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x{:02X}", action);
9544 }
else if (handlers[action][stage] ==
nullptr) {
9545 GrfMsg(7,
"DecodeSpecialSprite: Skipping action 0x{:02X} in stage {}", action, stage);
9547 GrfMsg(7,
"DecodeSpecialSprite: Handling action 0x{:02X} in stage {}", action, stage);
9548 handlers[action][stage](bufp);
9551 GrfMsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
9567 Debug(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '{}'", config->
filename);
9570 if (grf_container_version == 0) {
9571 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9575 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
9581 if (grf_container_version >= 2) file.
ReadDword();
9584 if (grf_container_version >= 2) {
9586 byte compression = file.
ReadByte();
9587 if (compression != 0) {
9588 Debug(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
9597 if (num == 4 && file.
ReadByte() == 0xFF) {
9600 Debug(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9608 while ((num = (grf_container_version >= 2 ? file.
ReadDword() : file.
ReadWord())) != 0) {
9614 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
9625 GrfMsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
9626 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
9630 if (grf_container_version >= 2 && type == 0xFD) {
9653 const std::string &filename = config->
filename;
9664 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
9666 if (_cur.
grffile ==
nullptr) UserError(
"File '{}' lost in cache.\n", filename);
9673 SpriteFile temporarySpriteFile(filename, subdir, needs_palette_remap);
9727 DupSprite(SPR_ROAD_DEPOT + 0, SPR_TRAMWAY_DEPOT_NO_TRACK + 0);
9728 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 1, SPR_TRAMWAY_DEPOT_NO_TRACK + 1);
9729 DupSprite(SPR_ROAD_DEPOT + 2, SPR_TRAMWAY_DEPOT_NO_TRACK + 2);
9730 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 3, SPR_TRAMWAY_DEPOT_NO_TRACK + 3);
9731 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 4, SPR_TRAMWAY_DEPOT_NO_TRACK + 4);
9732 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 5, SPR_TRAMWAY_DEPOT_NO_TRACK + 5);
9743 static const uint32_t override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
9747 std::vector<int> grf_overrides(num_grfs, -1);
9748 for (
int i = 0; i < num_grfs; i++) {
9750 uint32_t
override = _grf_id_overrides[source->grfid];
9751 if (
override == 0)
continue;
9754 if (dest ==
nullptr)
continue;
9757 assert(grf_overrides[i] >= 0);
9761 for (
int i = 0; i < num_grfs; i++) {
9762 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
9770 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9773 Debug(grf, 3,
"'{}' overrides price base multiplier {} of '{}'", source->filename, p, dest->filename);
9779 for (
int i = num_grfs - 1; i >= 0; i--) {
9780 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9788 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9791 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, source->filename, dest->filename);
9797 for (
int i = 0; i < num_grfs; i++) {
9798 if (grf_overrides[i] < 0)
continue;
9806 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9807 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9809 Debug(grf, 3,
"Price base multiplier {} from '{}' propagated to '{}'", p, dest->filename, source->filename);
9817 if (file->grf_version >= 8)
continue;
9818 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9819 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9821 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9824 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9831 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9832 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9833 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9835 price_base_multipliers[p] = 0;
9840 Debug(grf, 3,
"'{}' sets global price base multiplier {}", file->
filename, p);
9842 price_base_multipliers[p] = 0;
9844 Debug(grf, 3,
"'{}' sets local price base multiplier {}", file->
filename, p);
9859 _string_to_grf_mapping.clear();
9862 _grf_line_to_action6_sprite_override.clear();
9925 if (file ==
nullptr ||
_gted[e->
index].roadtramtype == 0) {
9934 if (
_gted[e->
index].roadtramtype < list->size())
9936 RoadTypeLabel rtl = (*list)[
_gted[e->
index].roadtramtype];
9965 _grm_sprites.clear();
10023 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
10030 if (stage == GLS_RESERVE) {
10031 static const uint32_t overrides[][2] = {
10032 { 0x44442202, 0x44440111 },
10033 { 0x6D620402, 0x6D620401 },
10034 { 0x4D656f20, 0x4D656F17 },
10036 for (
size_t i = 0; i <
lengthof(overrides); i++) {
10042 uint num_non_static = 0;
10044 _cur.
stage = stage;
10051 Debug(grf, 0,
"NewGRF file is missing '{}'; disabling", c->
filename);
10060 Debug(grf, 0,
"'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
10062 c->
error = {STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED};
10071 if (stage == GLS_RESERVE) {
10073 }
else if (stage == GLS_ACTIVATION) {
10078 Debug(sprite, 2,
"LoadNewGRF: Currently {} sprites are loaded", _cur.
spriteid);