52 #include "table/strings.h"
116 for (uint i = 0; i < GSF_END; i++) {
120 memset(this->spritegroups, 0,
sizeof(this->spritegroups));
133 assert(feature < GSF_END);
134 for (uint i = 0; i < numsets; i++) {
136 set.sprite = first_sprite + i * numents;
137 set.num_sprites = numents;
149 assert(feature < GSF_END);
162 assert(feature < GSF_END);
175 return this->
spritesets[feature].find(
set)->second.sprite;
187 return this->
spritesets[feature].find(
set)->second.num_sprites;
200 template <VehicleType T>
203 return image_index == 0xFD || IsValidImageIndex<T>(image_index);
215 ByteReader(byte *data, byte *end) : data(data), end(end) { }
217 inline byte ReadByte()
219 if (data < end)
return *(data)++;
225 uint16 val = ReadByte();
226 return val | (ReadByte() << 8);
229 uint16 ReadExtendedByte()
231 uint16 val = ReadByte();
232 return val == 0xFF ? ReadWord() : val;
237 uint32 val = ReadWord();
238 return val | (ReadWord() << 16);
241 uint32 ReadVarSize(byte size)
244 case 1:
return ReadByte();
245 case 2:
return ReadWord();
246 case 4:
return ReadDWord();
253 const char *ReadString()
255 char *
string =
reinterpret_cast<char *
>(data);
256 size_t string_length =
ttd_strnlen(
string, Remaining());
258 if (string_length == Remaining()) {
260 string[string_length - 1] =
'\0';
261 grfmsg(7,
"String was not terminated with a zero byte.");
271 inline size_t Remaining()
const
276 inline bool HasData(
size_t count = 1)
const
278 return data + count <= end;
286 inline void Skip(
size_t len)
295 typedef void (*SpecialSpriteHandler)(
ByteReader *buf);
308 uint16 cargo_allowed;
309 uint16 cargo_disallowed;
310 RailTypeLabel railtypelabel;
347 GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { }
351 return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
356 return this->grfid == other.grfid && this->nfoline == other.nfoline;
360 static std::map<GRFLocation, SpriteID> _grm_sprites;
361 typedef std::map<GRFLocation, byte*> GRFLineToSpriteOverride;
362 static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
374 void CDECL
grfmsg(
int severity,
const char *str, ...)
393 const GRFFile *
const *end = _grf_files.
End();
394 for (
GRFFile *
const *file = _grf_files.
Begin(); file != end; file++) {
395 if ((*file)->grfid == grfid)
return *file;
407 const GRFFile *
const *end = _grf_files.
End();
408 for (
GRFFile *
const *file = _grf_files.
Begin(); file != end; file++) {
409 if (strcmp((*file)->filename, filename) == 0)
return *file;
435 if (config != NULL) {
446 if (message != STR_NULL) {
447 delete config->error;
448 config->error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, message);
452 return config->error;
473 *target = STR_UNDEFINED;
490 static const StringID units_volume[] = {
491 STR_ITEMS, STR_PASSENGERS, STR_TONS, STR_BAGS,
492 STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS,
493 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
494 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
495 STR_TONS, STR_TONS, STR_BAGS, STR_LITERS,
496 STR_TONS, STR_LITERS, STR_TONS, STR_ITEMS,
497 STR_BAGS, STR_LITERS, STR_TONS, STR_ITEMS,
498 STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
504 #define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
505 assert_compile(stringend - stringid == end - begin); \
506 if (str >= begin && str <= end) return str + (stringid - begin)
509 TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING, STR_CARGO_PLURAL_FIZZY_DRINKS);
510 TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING, STR_CARGO_SINGULAR_FIZZY_DRINK);
511 if (str >= 0x004E && str <= 0x006D)
return units_volume[str - 0x004E];
512 TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING, STR_QUANTITY_FIZZY_DRINKS);
513 TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING, STR_ABBREV_FIZZY_DRINKS);
514 TEXTID_TO_STRINGID(0x00D1, 0x00E0, STR_COLOUR_DARK_BLUE, STR_COLOUR_WHITE);
519 TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, STR_TOWN_BUILDING_NAME_OLD_HOUSES_1);
520 TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1);
521 TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1, STR_TOWN_BUILDING_NAME_PIGGY_BANK_1);
524 TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE, STR_INDUSTRY_NAME_SUGAR_MINE);
525 TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION, STR_NEWS_INDUSTRY_PLANTED);
526 TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL, STR_NEWS_INDUSTRY_CLOSURE_LACK_OF_TREES);
527 TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_FARM);
528 TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_FARM);
531 case 0x4830:
return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
532 case 0x4831:
return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
533 case 0x483B:
return STR_ERROR_CAN_ONLY_BE_POSITIONED;
535 #undef TEXTID_TO_STRINGID
537 if (str == STR_NULL)
return STR_EMPTY;
539 DEBUG(grf, 0,
"Unknown StringID 0x%04X remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
578 static std::map<uint32, uint32> _grf_id_overrides;
587 _grf_id_overrides[source_grfid] = target_grfid;
588 grfmsg(5,
"SetNewGRFOverride: Added override of 0x%X to 0x%X",
BSWAP32(source_grfid),
BSWAP32(target_grfid));
603 uint32 scope_grfid = INVALID_GRFID;
606 scope_grfid = file->grfid;
607 uint32
override = _grf_id_overrides[file->grfid];
609 scope_grfid =
override;
611 if (grf_match == NULL) {
612 grfmsg(5,
"Tried mapping from GRFID %x to %x but target is not loaded",
BSWAP32(file->grfid),
BSWAP32(
override));
619 EngineID engine = _engine_mngr.
GetID(type, internal_id, scope_grfid);
628 EngineID engine = _engine_mngr.
GetID(type, internal_id, INVALID_GRFID);
634 grfmsg(5,
"Replaced engine at index %d for GRFID %x, type %d, index %d", e->
index,
BSWAP32(file->grfid), type, internal_id);
638 if (!static_access) {
640 eid->
grfid = scope_grfid;
646 if (static_access)
return NULL;
649 grfmsg(0,
"Can't allocate any more engines");
663 eid->grfid = scope_grfid;
664 eid->internal_id = internal_id;
673 memset(_gted + engine_pool_size, 0, len);
679 grfmsg(5,
"Created new engine at index %d for GRFID %x, type %d, index %d", e->
index,
BSWAP32(file->grfid), type, internal_id);
696 uint32 scope_grfid = INVALID_GRFID;
698 scope_grfid = file->grfid;
699 uint32
override = _grf_id_overrides[file->grfid];
700 if (
override != 0) scope_grfid =
override;
703 return _engine_mngr.
GetID(type, internal_id, scope_grfid);
743 grf_sprite->
sprite = buf->ReadWord();
744 grf_sprite->
pal = buf->ReadWord();
749 bool custom_sprite =
HasBit(grf_sprite->
pal, 15) != invert_action1_flag;
753 uint index =
GB(grf_sprite->
sprite, 0, 14);
755 grfmsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d", index);
756 grf_sprite->
sprite = SPR_IMG_QUERY;
757 grf_sprite->
pal = PAL_NONE;
760 if (max_sprite_offset != NULL) *max_sprite_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
765 grfmsg(1,
"ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite");
766 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
772 uint index =
GB(grf_sprite->
pal, 0, 14);
774 grfmsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d for 'palette'", index);
775 grf_sprite->
pal = PAL_NONE;
778 if (max_palette_offset != NULL) *max_palette_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
783 grfmsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette");
784 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
813 regs.delta.
parent[0] = buf->ReadByte();
814 regs.delta.
parent[1] = buf->ReadByte();
826 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
835 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
854 bool has_flags =
HasBit(num_building_sprites, 6);
855 ClrBit(num_building_sprites, 6);
858 dts->
Allocate(num_building_sprites);
860 uint16 *max_sprite_offset =
AllocaM(uint16, num_building_sprites + 1);
861 uint16 *max_palette_offset =
AllocaM(uint16, num_building_sprites + 1);
862 MemSetT(max_sprite_offset, 0, num_building_sprites + 1);
863 MemSetT(max_palette_offset, 0, num_building_sprites + 1);
870 grfmsg(1,
"ReadSpriteLayout: Spritelayout uses invalid flag 0x%x for ground sprite", flags & ~(valid_flags & ~
TLF_NON_GROUND_FLAGS));
871 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
878 for (uint i = 0; i < num_building_sprites; i++) {
881 flags =
ReadSpriteLayoutSprite(buf, has_flags,
false, use_cur_spritesets, feature, &seq->image, max_sprite_offset + i + 1, max_palette_offset + i + 1);
884 if (flags & ~valid_flags) {
885 grfmsg(1,
"ReadSpriteLayout: Spritelayout uses unknown flag 0x%x", flags & ~valid_flags);
886 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
890 seq->
delta_x = buf->ReadByte();
891 seq->delta_y = buf->ReadByte();
893 if (!no_z_position) seq->
delta_z = buf->ReadByte();
896 seq->size_x = buf->ReadByte();
897 seq->size_y = buf->ReadByte();
898 seq->size_z = buf->ReadByte();
906 bool is_consistent =
true;
908 for (uint i = 0; i < num_building_sprites + 1; i++) {
909 if (max_sprite_offset[i] > 0) {
913 is_consistent =
false;
917 if (max_palette_offset[i] > 0) {
921 is_consistent =
false;
930 if (!is_consistent || dts->registers != NULL) {
934 for (uint i = 0; i < num_building_sprites + 1; i++) {
968 if (base_pointer == 0) {
969 *index = INVALID_PRICE;
973 static const uint32 start = 0x4B34;
974 static const uint32 size = 6;
976 if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) {
977 grfmsg(1,
"%s: Unsupported running cost base 0x%04X, ignoring", error_location, base_pointer);
981 *index = (
Price)((base_pointer - start) / size);
1010 ei->decay_speed = buf->ReadByte();
1027 ei->load_amount = buf->ReadByte();
1049 for (
int i = 0; i < numinfo; i++) {
1058 uint8 tracktype = buf->ReadByte();
1060 if (tracktype < _cur.grffile->railtype_list.Length()) {
1065 switch (tracktype) {
1066 case 0: _gted[e->
index].railtypelabel = rvi->
engclass >= 2 ? RAILTYPE_ELECTRIC_LABEL : RAILTYPE_RAIL_LABEL;
break;
1067 case 1: _gted[e->
index].railtypelabel = RAILTYPE_MONO_LABEL;
break;
1068 case 2: _gted[e->
index].railtypelabel = RAILTYPE_MAGLEV_LABEL;
break;
1070 grfmsg(1,
"RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype);
1083 uint16 speed = buf->ReadWord();
1084 if (speed == 0xFFFF) speed = 0;
1091 rvi->
power = buf->ReadWord();
1094 if (rvi->
power != 0) {
1112 uint8 spriteid = buf->ReadByte();
1113 uint8 orig_spriteid = spriteid;
1117 if (spriteid < 0xFD) spriteid >>= 1;
1119 if (IsValidNewGRFImageIndex<VEH_TRAIN>(spriteid)) {
1120 rvi->image_index = spriteid;
1122 grfmsg(1,
"RailVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1123 rvi->image_index = 0;
1129 uint8 dual = buf->ReadByte();
1134 rvi->railveh_type = rvi->
power == 0 ?
1146 uint8 ctype = buf->ReadByte();
1148 if (ctype == 0xFF) {
1151 }
else if (_cur.
grffile->grf_version >= 8) {
1156 ei->cargo_type = ctype;
1159 grfmsg(2,
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
1165 SB(rvi->
weight, 0, 8, buf->ReadByte());
1173 grfmsg(2,
"RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored.");
1185 uint8 traction = buf->ReadByte();
1188 if (traction <= 0x07) {
1190 }
else if (traction <= 0x27) {
1192 }
else if (traction <= 0x31) {
1194 }
else if (traction <= 0x37) {
1196 }
else if (traction <= 0x41) {
1205 if (_gted[e->
index].railtypelabel == RAILTYPE_RAIL_LABEL && engclass >=
EC_ELECTRIC) _gted[e->
index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
1206 if (_gted[e->
index].railtypelabel == RAILTYPE_ELECTRIC_LABEL && engclass <
EC_ELECTRIC) _gted[e->
index].railtypelabel = RAILTYPE_RAIL_LABEL;
1222 ei->refit_cost = buf->ReadByte();
1226 uint32 mask = buf->ReadDWord();
1264 byte weight = buf->ReadByte();
1267 grfmsg(2,
"RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8);
1289 _gted[e->
index].cargo_allowed = buf->ReadWord();
1295 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1309 uint8 count = buf->ReadByte();
1343 for (
int i = 0; i < numinfo; i++) {
1356 rvi->running_cost = buf->ReadByte();
1364 uint8 spriteid = buf->ReadByte();
1365 uint8 orig_spriteid = spriteid;
1368 if (spriteid == 0xFF) spriteid = 0xFD;
1370 if (spriteid < 0xFD) spriteid >>= 1;
1372 if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
1373 rvi->image_index = spriteid;
1375 grfmsg(1,
"RoadVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1376 rvi->image_index = 0;
1382 rvi->capacity = buf->ReadByte();
1387 uint8 ctype = buf->ReadByte();
1389 if (ctype == 0xFF) {
1392 }
else if (_cur.
grffile->grf_version >= 8) {
1397 ei->cargo_type = ctype;
1400 grfmsg(2,
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
1406 rvi->cost_factor = buf->ReadByte();
1414 rvi->
power = buf->ReadByte();
1418 rvi->
weight = buf->ReadByte();
1426 uint32 mask = buf->ReadDWord();
1446 ei->refit_cost = buf->ReadByte();
1459 _gted[e->
index].cargo_allowed = buf->ReadWord();
1465 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1497 uint8 count = buf->ReadByte();
1531 for (
int i = 0; i < numinfo; i++) {
1540 uint8 spriteid = buf->ReadByte();
1541 uint8 orig_spriteid = spriteid;
1544 if (spriteid == 0xFF) spriteid = 0xFD;
1546 if (spriteid < 0xFD) spriteid >>= 1;
1548 if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
1549 svi->image_index = spriteid;
1551 grfmsg(1,
"ShipVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1552 svi->image_index = 0;
1562 svi->cost_factor = buf->ReadByte();
1571 uint8 ctype = buf->ReadByte();
1573 if (ctype == 0xFF) {
1576 }
else if (_cur.
grffile->grf_version >= 8) {
1581 ei->cargo_type = ctype;
1584 grfmsg(2,
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
1590 svi->capacity = buf->ReadWord();
1594 svi->running_cost = buf->ReadByte();
1602 uint32 mask = buf->ReadDWord();
1614 ei->refit_cost = buf->ReadByte();
1635 _gted[e->
index].cargo_allowed = buf->ReadWord();
1641 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1669 uint8 count = buf->ReadByte();
1703 for (
int i = 0; i < numinfo; i++) {
1712 uint8 spriteid = buf->ReadByte();
1713 uint8 orig_spriteid = spriteid;
1716 if (spriteid == 0xFF) spriteid = 0xFD;
1718 if (spriteid < 0xFD) spriteid >>= 1;
1720 if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
1721 avi->image_index = spriteid;
1723 grfmsg(1,
"AircraftVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1724 avi->image_index = 0;
1730 if (buf->ReadByte() == 0) {
1738 SB(avi->
subtype, 1, 1, (buf->ReadByte() != 0 ? 1 : 0));
1742 avi->cost_factor = buf->ReadByte();
1746 avi->
max_speed = (buf->ReadByte() * 128) / 10;
1750 avi->acceleration = buf->ReadByte();
1754 avi->running_cost = buf->ReadByte();
1770 uint32 mask = buf->ReadDWord();
1782 ei->refit_cost = buf->ReadByte();
1795 _gted[e->
index].cargo_allowed = buf->ReadWord();
1801 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1819 uint8 count = buf->ReadByte();
1865 for (
int i = 0; i < numinfo; i++) {
1869 if (statspec == NULL && prop != 0x08) {
1870 grfmsg(2,
"StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
1879 if (*spec == NULL) *spec = CallocT<StationSpec>(1);
1882 uint32 classid = buf->ReadDWord();
1883 (*spec)->cls_id = StationClass::Allocate(
BSWAP32(classid));
1888 statspec->
tiles = buf->ReadExtendedByte();
1892 for (uint t = 0; t < statspec->
tiles; t++) {
1896 if (buf->HasData(4) && *(uint32*)buf->Data() == 0) {
1899 dts->
Clone(&_station_display_datas_rail[t % 8]);
1914 dtss->
delta_x = buf->ReadByte();
1916 dtss->delta_y = buf->ReadByte();
1917 dtss->
delta_z = buf->ReadByte();
1918 dtss->size_x = buf->ReadByte();
1919 dtss->size_y = buf->ReadByte();
1920 dtss->size_z = buf->ReadByte();
1931 byte srcid = buf->ReadByte();
1934 if (srcstatspec == NULL) {
1935 grfmsg(1,
"StationChangeInfo: Station %u is not defined, cannot copy sprite layout to %u.", srcid, stid + i);
1943 for (uint t = 0; t < statspec->
tiles; t++) {
1962 statspec->copied_layouts =
false;
1964 while (buf->HasData()) {
1965 byte length = buf->ReadByte();
1966 byte number = buf->ReadByte();
1967 StationLayout layout;
1970 if (length == 0 || number == 0)
break;
1972 if (length > statspec->lengths) {
1973 statspec->platforms =
ReallocT(statspec->platforms, length);
1974 memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths);
1976 statspec->layouts =
ReallocT(statspec->layouts, length);
1977 memset(statspec->layouts + statspec->lengths, 0,
1978 (length - statspec->lengths) *
sizeof(*statspec->layouts));
1980 statspec->lengths = length;
1984 if (number > statspec->platforms[l]) {
1985 statspec->layouts[l] =
ReallocT(statspec->layouts[l], number);
1987 memset(statspec->layouts[l] + statspec->platforms[l], 0,
1988 (number - statspec->platforms[l]) *
sizeof(**statspec->layouts));
1990 statspec->platforms[l] = number;
1994 layout = MallocT<byte>(length * number);
1996 for (l = 0; l < length; l++) {
1997 for (p = 0; p < number; p++) {
1998 layout[l * number + p] = buf->ReadByte();
2008 free(statspec->layouts[l][p]);
2009 statspec->layouts[l][p] = layout;
2014 byte srcid = buf->ReadByte();
2017 if (srcstatspec == NULL) {
2018 grfmsg(1,
"StationChangeInfo: Station %u is not defined, cannot copy tile layout to %u.", srcid, stid + i);
2022 statspec->lengths = srcstatspec->lengths;
2023 statspec->platforms = srcstatspec->platforms;
2024 statspec->layouts = srcstatspec->layouts;
2025 statspec->copied_layouts =
true;
2034 statspec->
pylons = buf->ReadByte();
2039 if (_cur.
grffile->grf_version >= 7) {
2045 statspec->
flags = buf->ReadByte();
2049 statspec->
wires = buf->ReadByte();
2053 statspec->
blocked = buf->ReadByte();
2057 statspec->animation.
frames = buf->ReadByte();
2058 statspec->animation.
status = buf->ReadByte();
2062 statspec->animation.
speed = buf->ReadByte();
2066 statspec->animation.
triggers = buf->ReadWord();
2070 statspec->
tiles = buf->ReadExtendedByte();
2074 for (uint t = 0; t < statspec->
tiles; t++) {
2076 uint num_building_sprites = buf->ReadByte();
2103 if (
id + numinfo > CF_END) {
2104 grfmsg(1,
"CanalChangeInfo: Canal feature %u is invalid, max %u, ignoring",
id + numinfo, CF_END);
2108 for (
int i = 0; i < numinfo; i++) {
2117 cp->
flags = buf->ReadByte();
2142 grfmsg(1,
"BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo,
MAX_BRIDGES);
2146 for (
int i = 0; i < numinfo; i++) {
2152 byte year = buf->ReadByte();
2167 bridge->
price = buf->ReadByte();
2171 bridge->
speed = buf->ReadWord();
2175 byte tableid = buf->ReadByte();
2176 byte numtables = buf->ReadByte();
2183 for (; numtables-- != 0; tableid++) {
2185 grfmsg(1,
"BridgeChangeInfo: Table %d >= 7, skipping", tableid);
2186 for (byte sprite = 0; sprite < 32; sprite++) buf->ReadDWord();
2191 bridge->
sprite_table[tableid] = MallocT<PalSpriteID>(32);
2194 for (byte sprite = 0; sprite < 32; sprite++) {
2208 bridge->
flags = buf->ReadByte();
2217 if (newone != STR_UNDEFINED) bridge->
material = newone;
2224 if (newone != STR_UNDEFINED) bridge->
transport_name[prop - 0x11] = newone;
2229 bridge->
price = buf->ReadWord();
2286 for (uint j = 0; j < 4; j++) buf->ReadByte();
2290 byte count = buf->ReadByte();
2291 for (byte j = 0; j < count; j++) buf->ReadByte();
2315 grfmsg(1,
"TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo,
NUM_HOUSES_PER_GRF);
2320 if (_cur.
grffile->housespec == NULL) {
2324 for (
int i = 0; i < numinfo; i++) {
2327 if (prop != 0x08 && housespec == NULL) {
2330 if (cir > ret) ret = cir;
2337 byte subs_id = buf->ReadByte();
2339 if (subs_id == 0xFF) {
2342 HouseSpec::Get(hid + i)->
enabled =
false;
2346 grfmsg(2,
"TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i);
2351 if (*house == NULL) *house = CallocT<HouseSpec>(1);
2355 MemCpyT(housespec, HouseSpec::Get(subs_id));
2357 housespec->enabled =
true;
2358 housespec->grf_prop.local_id = hid + i;
2359 housespec->grf_prop.subst_id = subs_id;
2360 housespec->grf_prop.grffile = _cur.
grffile;
2361 housespec->random_colour[0] = 0x04;
2362 housespec->random_colour[1] = 0x08;
2363 housespec->random_colour[2] = 0x0C;
2364 housespec->random_colour[3] = 0x06;
2371 housespec->cargo_acceptance[2] = 0;
2383 uint16 years = buf->ReadWord();
2403 int8 goods = buf->ReadByte();
2439 byte
override = buf->ReadByte();
2443 grfmsg(2,
"TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.",
override, hid + i);
2447 _house_mngr.
Add(hid + i, _cur.
grffile->grfid,
override);
2456 for (uint j = 0; j < 4; j++) housespec->
random_colour[j] = buf->ReadByte();
2478 housespec->
class_id = AllocateHouseClassID(buf->ReadByte(), _cur.
grffile->grfid);
2486 uint32 cargotypes = buf->ReadDWord();
2489 if (cargotypes == 0xFFFFFFFF)
break;
2491 for (uint j = 0; j < 3; j++) {
2493 uint8 cargo_part =
GB(cargotypes, 8 * j, 8);
2511 byte count = buf->ReadByte();
2512 for (byte j = 0; j < count; j++) {
2520 housespec->
min_year = buf->ReadWord();
2524 housespec->
max_year = buf->ReadWord();
2558 template <
typename T>
2562 grfmsg(1,
"LoadTranslationTable: %s translation table must start at zero", name);
2566 translation_table.Clear();
2567 for (
int i = 0; i < numinfo; i++) {
2568 uint32 item = buf->ReadDWord();
2569 *translation_table.Append() =
BSWAP32(item);
2599 for (
int i = 0; i < numinfo; i++) {
2602 int factor = buf->ReadByte();
2603 uint price = gvid + i;
2605 if (price < PR_END) {
2608 grfmsg(1,
"GlobalVarChangeInfo: Price %d out of range, ignoring", price);
2617 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2625 uint32 rate = buf->ReadDWord();
2633 grfmsg(1,
"GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx);
2640 uint16 options = buf->ReadWord();
2649 grfmsg(1,
"GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx);
2656 uint32 tempfix = buf->ReadDWord();
2662 grfmsg(1,
"GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
2669 uint32 tempfix = buf->ReadDWord();
2675 grfmsg(1,
"GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
2682 Year year_euro = buf->ReadWord();
2687 grfmsg(1,
"GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
2694 grfmsg(1,
"GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
2696 grfmsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table (" PRINTF_SIZE
")", buf->Remaining());
2702 table[i][j] = buf->ReadByte();
2703 if (_cur.
grffile->grf_version >= 8) {
2706 if (table[i][j] >= 128) {
2728 uint curidx = gvid + i;
2731 grfmsg(1,
"GlobalVarChangeInfo: Language %d is not known, ignoring", curidx);
2736 while (buf->ReadByte() != 0) {
2746 uint plural_form = buf->ReadByte();
2747 if (plural_form >= LANGUAGE_MAX_PLURAL) {
2748 grfmsg(1,
"GlobalVarChanceInfo: Plural form %d is out of range, ignoring", plural_form);
2755 byte newgrf_id = buf->ReadByte();
2756 while (newgrf_id != 0) {
2757 const char *name = buf->ReadString();
2772 grfmsg(1,
"GlobalVarChangeInfo: Gender name %s is not known, ignoring", name);
2779 grfmsg(1,
"GlobalVarChangeInfo: Case name %s is not known, ignoring", name);
2784 newgrf_id = buf->ReadByte();
2814 for (
int i = 0; i < numinfo; i++) {
2838 uint32 s = buf->ReadDWord();
2839 uint32 t = buf->ReadDWord();
2846 while (buf->ReadByte() != 0) {
2874 grfmsg(2,
"CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo,
NUM_CARGO - 1);
2878 for (
int i = 0; i < numinfo; i++) {
2883 cs->
bitnum = buf->ReadByte();
2921 cs->
sprite = buf->ReadWord();
2925 cs->
weight = buf->ReadByte();
2929 cs->transit_days[0] = buf->ReadByte();
2933 cs->transit_days[1] = buf->ReadByte();
2937 cs->initial_payment = buf->ReadDWord();
2941 cs->rating_colour = buf->ReadByte();
2945 cs->legend_colour = buf->ReadByte();
2953 cs->
classes = buf->ReadWord();
2957 cs->
label = buf->ReadDWord();
2962 uint8 substitute_type = buf->ReadByte();
2964 switch (substitute_type) {
2971 grfmsg(1,
"CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
2987 cs->
multiplier = max<uint16>(1u, buf->ReadWord());
3012 if (_cur.
grffile->sound_offset == 0) {
3013 grfmsg(1,
"SoundEffectChangeInfo: No effects defined, skipping");
3018 grfmsg(1,
"SoundEffectChangeInfo: Attempting to change undefined sound effect (%u), max (%u). Ignoring.", sid + numinfo,
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
3022 for (
int i = 0; i < numinfo; i++) {
3027 sound->volume = buf->ReadByte();
3031 sound->priority = buf->ReadByte();
3035 SoundID orig_sound = buf->ReadByte();
3040 SoundEntry *old_sound = GetSound(orig_sound);
3043 *old_sound = *sound;
3109 if (_cur.
grffile->indtspec == NULL) {
3113 for (
int i = 0; i < numinfo; i++) {
3116 if (prop != 0x08 && tsp == NULL) {
3118 if (cir > ret) ret = cir;
3125 byte subs_id = buf->ReadByte();
3129 grfmsg(2,
"IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
3134 if (*tilespec == NULL) {
3135 *tilespec = CallocT<IndustryTileSpec>(1);
3138 memcpy(tsp, &_industry_tile_specs[subs_id],
sizeof(_industry_tile_specs[subs_id]));
3139 tsp->enabled =
true;
3147 tsp->grf_prop.local_id = indtid + i;
3148 tsp->grf_prop.subst_id = subs_id;
3149 tsp->grf_prop.grffile = _cur.
grffile;
3156 byte ovrid = buf->ReadByte();
3160 grfmsg(2,
"IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
3164 _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
3171 uint16 acctp = buf->ReadWord();
3257 byte num_table = buf->ReadByte();
3258 for (byte j = 0; j < num_table; j++) {
3259 for (uint k = 0;; k++) {
3260 byte x = buf->ReadByte();
3261 if (x == 0xFE && k == 0) {
3267 byte y = buf->ReadByte();
3268 if (x == 0 && y == 0x80)
break;
3270 byte gfx = buf->ReadByte();
3271 if (gfx == 0xFE) buf->ReadWord();
3278 for (byte j = 0; j < 3; j++) buf->ReadByte();
3282 byte number_of_sounds = buf->ReadByte();
3283 for (uint8 j = 0; j < number_of_sounds; j++) {
3304 for (
int i = 0; i < size - 1; i++) {
3305 for (
int j = i + 1; j < size; j++) {
3306 if (layout[i].ti.x == layout[j].ti.
x &&
3307 layout[i].ti.
y == layout[j].ti.
y) {
3319 for (
int j = 0; j < ind->
num_table; j++) {
3347 if (_cur.
grffile->industryspec == NULL) {
3351 for (
int i = 0; i < numinfo; i++) {
3354 if (prop != 0x08 && indsp == NULL) {
3356 if (cir > ret) ret = cir;
3363 byte subs_id = buf->ReadByte();
3365 if (subs_id == 0xFF) {
3368 _industry_specs[indid + i].
enabled =
false;
3372 grfmsg(2,
"_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
3379 if (*indspec == NULL) {
3380 *indspec = CallocT<IndustrySpec>(1);
3383 memcpy(indsp, &_origin_industry_specs[subs_id],
sizeof(_industry_specs[subs_id]));
3384 indsp->enabled =
true;
3385 indsp->grf_prop.local_id = indid + i;
3386 indsp->grf_prop.subst_id = subs_id;
3387 indsp->grf_prop.grffile = _cur.
grffile;
3396 byte ovrid = buf->ReadByte();
3400 grfmsg(2,
"IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
3404 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3409 byte new_num_layouts = buf->ReadByte();
3415 uint32 def_num_tiles = buf->ReadDWord() / 3 + 1;
3422 for (byte j = 0; j < new_num_layouts; j++) {
3423 for (uint k = 0;; k++) {
3424 if (k >= def_num_tiles) {
3425 grfmsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry %u.", indid);
3428 itt = ReallocT<IndustryTileTable>(itt, def_num_tiles);
3431 itt[k].ti.x = buf->ReadByte();
3433 if (itt[k].ti.x == 0xFE && k == 0) {
3435 IndustryType type = buf->ReadByte();
3436 byte laynbr = buf->ReadByte();
3438 copy_from = _origin_industry_specs[type].table[laynbr];
3439 for (size = 1;; size++) {
3440 if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.
y == 0)
break;
3445 itt[k].ti.
y = buf->ReadByte();
3447 if (itt[k].ti.x == 0 && itt[k].ti.y == 0x80) {
3450 itt[k].ti.x = -0x80;
3459 itt[k].gfx = buf->ReadByte();
3461 if (itt[k].gfx == 0xFE) {
3463 int local_tile_id = buf->ReadWord();
3466 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3469 grfmsg(2,
"IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
3472 itt[k].gfx = tempid;
3476 }
else if (itt[k].gfx == 0xFF) {
3477 itt[k].ti.
x = (int8)
GB(itt[k].ti.x, 0, 8);
3478 itt[k].ti.y = (int8)
GB(itt[k].ti.y, 0, 8);
3487 if (_cur.
grffile->grf_version < 8 && itt[k].ti.x < 0) itt[k].ti.y += 1;
3493 grfmsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id %u. Ignoring", indid);
3497 tile_table[j] = CallocT<IndustryTileTable>(size);
3498 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
3502 for (
int i = 0; i < new_num_layouts; i++) {
3503 free(tile_table[i]);
3514 indsp->
table = tile_table;
3541 for (byte j = 0; j < 2; j++) {
3547 for (byte j = 0; j < 3; j++) {
3555 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3568 sounds[j] = buf->ReadByte();
3584 for (byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3610 uint32 multiples = buf->ReadDWord();
3626 byte aflag = buf->ReadByte();
3636 uint16 str = buf->ReadWord();
3662 for (
int i = 0; i < as->
num_table; i++) {
3667 }
while ((++it)->ti.x != -0x80);
3668 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3671 as->
table = table_list;
3693 grfmsg(1,
"AirportChangeInfo: Too many airports, trying id (%u), max (%u). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3698 if (_cur.
grffile->airportspec == NULL) {
3702 for (
int i = 0; i < numinfo; i++) {
3705 if (as == NULL && prop != 0x08 && prop != 0x09) {
3706 grfmsg(2,
"AirportChangeInfo: Attempt to modify undefined airport %u, ignoring", airport + i);
3712 byte subs_id = buf->ReadByte();
3714 if (subs_id == 0xFF) {
3721 grfmsg(2,
"AirportChangeInfo: Attempt to use new airport %u as substitute airport for %u. Ignoring.", subs_id, airport + i);
3729 if (*spec == NULL) {
3730 *spec = MallocT<AirportSpec>(1);
3735 as->grf_prop.local_id = airport + i;
3736 as->grf_prop.subst_id = subs_id;
3737 as->grf_prop.grffile = _cur.
grffile;
3739 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3750 uint32 defsize = buf->ReadDWord();
3756 for (byte j = 0; j < as->
num_table; j++) {
3758 for (
int k = 0;; k++) {
3759 att[k].ti.x = buf->ReadByte();
3760 att[k].ti.y = buf->ReadByte();
3762 if (att[k].ti.x == 0 && att[k].ti.y == 0x80) {
3765 att[k].ti.x = -0x80;
3774 att[k].
gfx = buf->ReadByte();
3776 if (att[k].gfx == 0xFE) {
3778 int local_tile_id = buf->ReadWord();
3781 uint16 tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3784 grfmsg(2,
"AirportChangeInfo: Attempt to use airport tile %u with airport id %u, not yet defined. Ignoring.", local_tile_id, airport + i);
3787 att[k].gfx = tempid;
3791 }
else if (att[k].gfx == 0xFF) {
3792 att[k].
ti.
x = (int8)
GB(att[k].ti.x, 0, 8);
3793 att[k].ti.y = (int8)
GB(att[k].ti.y, 0, 8);
3804 tile_table[j] = CallocT<AirportTileTable>(size);
3805 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
3808 as->
table = tile_table;
3811 for (
int i = 0; i < as->
num_table; i++) {
3812 free(tile_table[i]);
3918 if (_cur.
grffile->objectspec == NULL) {
3922 for (
int i = 0; i < numinfo; i++) {
3925 if (prop != 0x08 && spec == NULL) {
3928 if (cir > ret) ret = cir;
3937 if (*ospec == NULL) {
3938 *ospec = CallocT<ObjectSpec>(1);
3939 (*ospec)->
views = 1;
3943 uint32 classid = buf->ReadDWord();
3944 (*ospec)->cls_id = ObjectClass::Allocate(
BSWAP32(classid));
3945 (*ospec)->enabled =
true;
3960 spec->
climate = buf->ReadByte();
3964 spec->
size = buf->ReadByte();
4007 spec->
height = buf->ReadByte();
4011 spec->
views = buf->ReadByte();
4013 grfmsg(2,
"ObjectChangeInfo: Invalid number of views (%u) for object id %u. Ignoring.", spec->
views,
id + i);
4046 grfmsg(1,
"RailTypeChangeInfo: Rail type %u is invalid, max %u, ignoring",
id + numinfo,
RAILTYPE_END);
4050 for (
int i = 0; i < numinfo; i++) {
4063 uint16 str = buf->ReadWord();
4065 if (_cur.
grffile->grf_version < 8) {
4095 int n = buf->ReadByte();
4096 for (
int j = 0; j != n; j++) {
4097 RailTypeLabel label = buf->ReadDWord();
4157 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4176 grfmsg(1,
"RailTypeReserveInfo: Rail type %u is invalid, max %u, ignoring",
id + numinfo,
RAILTYPE_END);
4180 for (
int i = 0; i < numinfo; i++) {
4184 RailTypeLabel rtl = buf->ReadDWord();
4193 _cur.
grffile->railtype_map[
id + i] = rt;
4211 int n = buf->ReadByte();
4212 for (
int j = 0; j != n; j++) {
4217 grfmsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type %u because no label was set",
id + i);
4224 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4259 if (_cur.
grffile->airtspec == NULL) {
4263 for (
int i = 0; i < numinfo; i++) {
4266 if (prop != 0x08 && tsp == NULL) {
4267 grfmsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile %u. Ignoring.", airtid + i);
4274 byte subs_id = buf->ReadByte();
4278 grfmsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile %u as substitute airport tile for %u. Ignoring.", subs_id, airtid + i);
4283 if (*tilespec == NULL) {
4284 *tilespec = CallocT<AirportTileSpec>(1);
4288 tsp->enabled =
true;
4292 tsp->grf_prop.local_id = airtid + i;
4293 tsp->grf_prop.subst_id = subs_id;
4294 tsp->grf_prop.grffile = _cur.
grffile;
4301 byte
override = buf->ReadByte();
4305 grfmsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile %u with airport tile id %u. Ignoring.",
override, airtid + i);
4309 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4314 tsp->callback_mask = buf->ReadByte();
4318 tsp->animation.frames = buf->ReadByte();
4319 tsp->animation.status = buf->ReadByte();
4323 tsp->animation.speed = buf->ReadByte();
4327 tsp->animation.triggers = buf->ReadByte();
4339 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8 feature, uint8 property)
4342 default: NOT_REACHED();
4352 grfmsg(1,
"%s: Ignoring property 0x%02X of feature 0x%02X (not implemented)", caller, property, feature);
4356 grfmsg(0,
"%s: Unknown property 0x%02X of feature 0x%02X, disabling", caller, property, feature);
4369 static void FeatureChangeInfo(
ByteReader *buf)
4382 static const VCI_Handler handler[] = {
4400 AirportTilesChangeInfo,
4403 uint8 feature = buf->ReadByte();
4404 uint8 numprops = buf->ReadByte();
4405 uint numinfo = buf->ReadByte();
4406 uint engine = buf->ReadExtendedByte();
4408 grfmsg(6,
"FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d",
4409 feature, numprops, engine, numinfo);
4411 if (feature >=
lengthof(handler) || handler[feature] == NULL) {
4412 if (feature != GSF_CARGOES)
grfmsg(1,
"FeatureChangeInfo: Unsupported feature %d, skipping", feature);
4419 while (numprops-- && buf->HasData()) {
4420 uint8 prop = buf->ReadByte();
4423 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
4430 uint8 feature = buf->ReadByte();
4431 uint8 numprops = buf->ReadByte();
4432 uint numinfo = buf->ReadByte();
4433 buf->ReadExtendedByte();
4435 if (feature == GSF_BRIDGES && numprops == 1) {
4436 uint8 prop = buf->ReadByte();
4439 if (prop == 0x0D)
return;
4440 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
4441 uint8 prop = buf->ReadByte();
4444 bool is_safe =
true;
4445 for (uint i = 0; i < numinfo; i++) {
4446 uint32 s = buf->ReadDWord();
4454 if (is_safe)
return;
4465 static void ReserveChangeInfo(
ByteReader *buf)
4467 uint8 feature = buf->ReadByte();
4469 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES)
return;
4471 uint8 numprops = buf->ReadByte();
4472 uint8 numinfo = buf->ReadByte();
4473 uint8 index = buf->ReadExtendedByte();
4475 while (numprops-- && buf->HasData()) {
4476 uint8 prop = buf->ReadByte();
4480 default: NOT_REACHED();
4486 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
4490 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
4494 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
4515 uint8 feature = buf->ReadByte();
4516 uint16 num_sets = buf->ReadByte();
4517 uint16 first_set = 0;
4519 if (num_sets == 0 && buf->HasData(3)) {
4522 first_set = buf->ReadExtendedByte();
4523 num_sets = buf->ReadExtendedByte();
4525 uint16 num_ents = buf->ReadExtendedByte();
4529 grfmsg(7,
"New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d)",
4530 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
4533 for (
int i = 0; i < num_sets * num_ents; i++) {
4543 uint16 num_sets = buf->ReadByte();
4545 if (num_sets == 0 && buf->HasData(3)) {
4548 buf->ReadExtendedByte();
4549 num_sets = buf->ReadExtendedByte();
4551 uint16 num_ents = buf->ReadExtendedByte();
4560 static const SpriteGroup *GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
4562 if (
HasBit(groupid, 15)) {
4567 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] == NULL) {
4568 grfmsg(1,
"GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid);
4572 return _cur.spritegroups[groupid];
4585 if (
HasBit(spriteid, 15)) {
4591 grfmsg(1,
"CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid", setid, type, spriteid);
4596 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
4599 assert(spriteset_start + num_sprites <= _cur.
spriteid);
4620 uint8 feature = buf->ReadByte();
4621 uint8 setid = buf->ReadByte();
4622 uint8 type = buf->ReadByte();
4645 switch (
GB(type, 2, 2)) {
4646 default: NOT_REACHED();
4647 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
4648 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
4649 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
4662 adjust->variable = buf->ReadByte();
4663 if (adjust->variable == 0x7E) {
4665 adjust->subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
4670 varadjust = buf->ReadByte();
4671 adjust->shift_num =
GB(varadjust, 0, 5);
4672 adjust->type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
4673 adjust->and_mask = buf->ReadVarSize(varsize);
4675 if (adjust->type != DSGA_TYPE_NONE) {
4676 adjust->add_val = buf->ReadVarSize(varsize);
4677 adjust->divmod_val = buf->ReadVarSize(varsize);
4679 adjust->add_val = 0;
4680 adjust->divmod_val = 0;
4684 }
while (
HasBit(varadjust, 5));
4686 group->num_adjusts = adjusts.
Length();
4687 group->adjusts = MallocT<DeterministicSpriteGroupAdjust>(group->num_adjusts);
4688 MemCpyT(group->adjusts, adjusts.
Begin(), group->num_adjusts);
4690 group->num_ranges = buf->ReadByte();
4691 if (group->num_ranges > 0) group->ranges = CallocT<DeterministicSpriteGroupRange>(group->num_ranges);
4693 for (uint i = 0; i < group->num_ranges; i++) {
4694 group->ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
4695 group->ranges[i].low = buf->ReadVarSize(varsize);
4696 group->ranges[i].high = buf->ReadVarSize(varsize);
4699 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
4715 group->count = buf->ReadByte();
4718 uint8 triggers = buf->ReadByte();
4719 group->triggers =
GB(triggers, 0, 7);
4720 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
4725 for (uint i = 0; i < group->
num_groups; i++) {
4726 group->
groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
4737 case GSF_ROADVEHICLES:
4746 byte num_loaded = type;
4747 byte num_loading = buf->ReadByte();
4750 grfmsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
4760 if (num_loaded > 0) group->
loaded = CallocT<const SpriteGroup*>(num_loaded);
4761 if (num_loading > 0) group->
loading = CallocT<const SpriteGroup*>(num_loading);
4763 grfmsg(6,
"NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
4764 setid, num_loaded, num_loading);
4766 for (uint i = 0; i < num_loaded; i++) {
4767 uint16 spriteid = buf->ReadWord();
4769 grfmsg(8,
"NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
4772 for (uint i = 0; i < num_loading; i++) {
4773 uint16 spriteid = buf->ReadWord();
4775 grfmsg(8,
"NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
4782 case GSF_AIRPORTTILES:
4784 case GSF_INDUSTRYTILES: {
4785 byte num_building_sprites =
max((uint8)1, type);
4792 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
4796 case GSF_INDUSTRIES: {
4798 grfmsg(1,
"NewSpriteGroup: Unsupported industry production version %d, skipping", type);
4805 group->version = type;
4807 for (uint i = 0; i < 3; i++) {
4808 group->subtract_input[i] = (int16)buf->ReadWord();
4810 for (uint i = 0; i < 2; i++) {
4811 group->add_output[i] = buf->ReadWord();
4813 group->again = buf->ReadByte();
4815 for (uint i = 0; i < 3; i++) {
4816 group->subtract_input[i] = buf->ReadByte();
4818 for (uint i = 0; i < 2; i++) {
4819 group->add_output[i] = buf->ReadByte();
4821 group->again = buf->ReadByte();
4827 default:
grfmsg(1,
"NewSpriteGroup: Unsupported feature %d, skipping", feature);
4832 _cur.spritegroups[setid] = act_group;
4835 static CargoID TranslateCargo(uint8 feature, uint8 ctype)
4837 if (feature == GSF_OBJECTS) {
4842 grfmsg(1,
"TranslateCargo: Invalid cargo bitnum %d for objects, skipping.", ctype);
4847 if (feature == GSF_STATIONS && ctype == 0xFE)
return CT_DEFAULT_NA;
4848 if (ctype == 0xFF)
return CT_PURCHASE;
4853 grfmsg(1,
"TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
4858 FOR_ALL_CARGOSPECS(cs) {
4859 if (cs->
bitnum == ctype) {
4860 grfmsg(6,
"TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, cs->
Index());
4865 grfmsg(5,
"TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
4878 grfmsg(5,
"TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype);
4884 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));
4888 grfmsg(6,
"TranslateCargo: Cargo '%c%c%c%c' mapped to cargo type %d.",
GB(cl, 24, 8),
GB(cl, 16, 8),
GB(cl, 8, 8),
GB(cl, 0, 8), ctype);
4893 static bool IsValidGroupID(uint16 groupid,
const char *
function)
4895 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] == NULL) {
4896 grfmsg(1,
"%s: Spritegroup 0x%04X out of range or empty, skipping.",
function, groupid);
4903 static void VehicleMapSpriteGroup(
ByteReader *buf, byte feature, uint8 idcount)
4906 static uint last_engines_count;
4907 bool wagover =
false;
4910 if (
HasBit(idcount, 7)) {
4913 idcount =
GB(idcount, 0, 7);
4915 if (last_engines_count == 0) {
4916 grfmsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
4920 grfmsg(6,
"VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
4921 last_engines_count, idcount);
4923 if (last_engines_count != idcount) {
4924 last_engines =
ReallocT(last_engines, idcount);
4925 last_engines_count = idcount;
4930 for (uint i = 0; i < idcount; i++) {
4936 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
4940 engines[i] = e->
index;
4941 if (!wagover) last_engines[i] = engines[i];
4944 uint8 cidcount = buf->ReadByte();
4945 for (uint c = 0; c < cidcount; c++) {
4946 uint8 ctype = buf->ReadByte();
4947 uint16 groupid = buf->ReadWord();
4948 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
4950 grfmsg(8,
"VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
4952 ctype = TranslateCargo(feature, ctype);
4955 for (uint i = 0; i < idcount; i++) {
4958 grfmsg(7,
"VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
4961 SetWagonOverrideSprites(engine, ctype, _cur.spritegroups[groupid], last_engines, last_engines_count);
4963 SetCustomEngineSprites(engine, ctype, _cur.spritegroups[groupid]);
4968 uint16 groupid = buf->ReadWord();
4969 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
4971 grfmsg(8,
"-- Default group id 0x%04X", groupid);
4973 for (uint i = 0; i < idcount; i++) {
4977 SetWagonOverrideSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid], last_engines, last_engines_count);
4979 SetCustomEngineSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid]);
4986 static void CanalMapSpriteGroup(
ByteReader *buf, uint8 idcount)
4989 for (uint i = 0; i < idcount; i++) {
4993 uint8 cidcount = buf->ReadByte();
4994 buf->Skip(cidcount * 3);
4996 uint16 groupid = buf->ReadWord();
4997 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
4999 for (uint i = 0; i < idcount; i++) {
5003 grfmsg(1,
"CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
5013 static void StationMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5015 uint8 *stations =
AllocaM(uint8, idcount);
5016 for (uint i = 0; i < idcount; i++) {
5017 stations[i] = buf->ReadByte();
5020 uint8 cidcount = buf->ReadByte();
5021 for (uint c = 0; c < cidcount; c++) {
5022 uint8 ctype = buf->ReadByte();
5023 uint16 groupid = buf->ReadWord();
5024 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5026 ctype = TranslateCargo(GSF_STATIONS, ctype);
5029 for (uint i = 0; i < idcount; i++) {
5032 if (statspec == NULL) {
5033 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5041 uint16 groupid = buf->ReadWord();
5042 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5044 for (uint i = 0; i < idcount; i++) {
5047 if (statspec == NULL) {
5048 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5053 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X mapped multiple times, skipping", stations[i]);
5060 StationClass::Assign(statspec);
5065 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5067 uint8 *houses =
AllocaM(uint8, idcount);
5068 for (uint i = 0; i < idcount; i++) {
5069 houses[i] = buf->ReadByte();
5073 uint8 cidcount = buf->ReadByte();
5074 buf->Skip(cidcount * 3);
5076 uint16 groupid = buf->ReadWord();
5077 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5079 if (_cur.
grffile->housespec == NULL) {
5080 grfmsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5084 for (uint i = 0; i < idcount; i++) {
5088 grfmsg(1,
"TownHouseMapSpriteGroup: House %d undefined, skipping.", houses[i]);
5096 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5098 uint8 *industries =
AllocaM(uint8, idcount);
5099 for (uint i = 0; i < idcount; i++) {
5100 industries[i] = buf->ReadByte();
5104 uint8 cidcount = buf->ReadByte();
5105 buf->Skip(cidcount * 3);
5107 uint16 groupid = buf->ReadWord();
5108 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5110 if (_cur.
grffile->industryspec == NULL) {
5111 grfmsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5115 for (uint i = 0; i < idcount; i++) {
5118 if (indsp == NULL) {
5119 grfmsg(1,
"IndustryMapSpriteGroup: Industry %d undefined, skipping", industries[i]);
5127 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5129 uint8 *indtiles =
AllocaM(uint8, idcount);
5130 for (uint i = 0; i < idcount; i++) {
5131 indtiles[i] = buf->ReadByte();
5135 uint8 cidcount = buf->ReadByte();
5136 buf->Skip(cidcount * 3);
5138 uint16 groupid = buf->ReadWord();
5139 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5141 if (_cur.
grffile->indtspec == NULL) {
5142 grfmsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5146 for (uint i = 0; i < idcount; i++) {
5149 if (indtsp == NULL) {
5150 grfmsg(1,
"IndustrytileMapSpriteGroup: Industry tile %d undefined, skipping", indtiles[i]);
5158 static void CargoMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5161 for (uint i = 0; i < idcount; i++) {
5162 cargoes[i] = buf->ReadByte();
5166 uint8 cidcount = buf->ReadByte();
5167 buf->Skip(cidcount * 3);
5169 uint16 groupid = buf->ReadWord();
5170 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5172 for (uint i = 0; i < idcount; i++) {
5176 grfmsg(1,
"CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid);
5182 cs->group = _cur.spritegroups[groupid];
5186 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5188 if (_cur.
grffile->objectspec == NULL) {
5189 grfmsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5193 uint8 *objects =
AllocaM(uint8, idcount);
5194 for (uint i = 0; i < idcount; i++) {
5195 objects[i] = buf->ReadByte();
5198 uint8 cidcount = buf->ReadByte();
5199 for (uint c = 0; c < cidcount; c++) {
5200 uint8 ctype = buf->ReadByte();
5201 uint16 groupid = buf->ReadWord();
5202 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5204 ctype = TranslateCargo(GSF_OBJECTS, ctype);
5207 for (uint i = 0; i < idcount; i++) {
5211 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
5219 uint16 groupid = buf->ReadWord();
5220 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5222 for (uint i = 0; i < idcount; i++) {
5226 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
5231 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X mapped multiple times, skipping", objects[i]);
5241 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5243 uint8 *railtypes =
AllocaM(uint8, idcount);
5244 for (uint i = 0; i < idcount; i++) {
5245 railtypes[i] = _cur.
grffile->railtype_map[buf->ReadByte()];
5248 uint8 cidcount = buf->ReadByte();
5249 for (uint c = 0; c < cidcount; c++) {
5250 uint8 ctype = buf->ReadByte();
5251 uint16 groupid = buf->ReadWord();
5252 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5254 if (ctype >= RTSG_END)
continue;
5257 for (uint i = 0; i < idcount; i++) {
5262 rti->
group[ctype] = _cur.spritegroups[groupid];
5271 static void AirportMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5273 uint8 *airports =
AllocaM(uint8, idcount);
5274 for (uint i = 0; i < idcount; i++) {
5275 airports[i] = buf->ReadByte();
5279 uint8 cidcount = buf->ReadByte();
5280 buf->Skip(cidcount * 3);
5282 uint16 groupid = buf->ReadWord();
5283 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
5285 if (_cur.
grffile->airportspec == NULL) {
5286 grfmsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
5290 for (uint i = 0; i < idcount; i++) {
5294 grfmsg(1,
"AirportMapSpriteGroup: Airport %d undefined, skipping", airports[i]);
5302 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5304 uint8 *airptiles =
AllocaM(uint8, idcount);
5305 for (uint i = 0; i < idcount; i++) {
5306 airptiles[i] = buf->ReadByte();
5310 uint8 cidcount = buf->ReadByte();
5311 buf->Skip(cidcount * 3);
5313 uint16 groupid = buf->ReadWord();
5314 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
5316 if (_cur.
grffile->airtspec == NULL) {
5317 grfmsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
5321 for (uint i = 0; i < idcount; i++) {
5324 if (airtsp == NULL) {
5325 grfmsg(1,
"AirportTileMapSpriteGroup: Airport tile %d undefined, skipping", airptiles[i]);
5335 static void FeatureMapSpriteGroup(
ByteReader *buf)
5351 uint8 feature = buf->ReadByte();
5352 uint8 idcount = buf->ReadByte();
5358 uint16 groupid = buf->ReadWord();
5359 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
5361 grfmsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature %d", feature);
5370 grfmsg(6,
"FeatureMapSpriteGroup: Feature %d, %d ids", feature, idcount);
5374 case GSF_ROADVEHICLES:
5377 VehicleMapSpriteGroup(buf, feature, idcount);
5381 CanalMapSpriteGroup(buf, idcount);
5385 StationMapSpriteGroup(buf, idcount);
5389 TownHouseMapSpriteGroup(buf, idcount);
5392 case GSF_INDUSTRIES:
5393 IndustryMapSpriteGroup(buf, idcount);
5396 case GSF_INDUSTRYTILES:
5397 IndustrytileMapSpriteGroup(buf, idcount);
5401 CargoMapSpriteGroup(buf, idcount);
5405 AirportMapSpriteGroup(buf, idcount);
5409 ObjectMapSpriteGroup(buf, idcount);
5413 RailTypeMapSpriteGroup(buf, idcount);
5416 case GSF_AIRPORTTILES:
5417 AirportTileMapSpriteGroup(buf, idcount);
5421 grfmsg(1,
"FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
5445 bool new_scheme = _cur.
grffile->grf_version >= 7;
5447 uint8 feature = buf->ReadByte();
5448 uint8 lang = buf->ReadByte();
5449 uint8 num = buf->ReadByte();
5450 bool generic =
HasBit(lang, 7);
5453 id = buf->ReadWord();
5454 }
else if (feature <= GSF_AIRCRAFT) {
5455 id = buf->ReadExtendedByte();
5457 id = buf->ReadByte();
5462 uint16 endid =
id + num;
5464 grfmsg(6,
"FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X",
5465 id, endid, feature, lang);
5467 for (;
id < endid && buf->HasData();
id++) {
5468 const char *name = buf->ReadString();
5469 grfmsg(8,
"FeatureNewName: 0x%04X <- %s",
id, name);
5473 case GSF_ROADVEHICLES:
5478 if (e == NULL)
break;
5492 switch (
GB(
id, 8, 8)) {
5494 if (_cur.
grffile->stations == NULL || _cur.
grffile->stations[
GB(
id, 0, 8)] == NULL) {
5495 grfmsg(1,
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring",
GB(
id, 0, 8));
5503 if (_cur.
grffile->stations == NULL || _cur.
grffile->stations[
GB(
id, 0, 8)] == NULL) {
5504 grfmsg(1,
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring",
GB(
id, 0, 8));
5511 if (_cur.
grffile->airtspec == NULL || _cur.
grffile->airtspec[
GB(
id, 0, 8)] == NULL) {
5512 grfmsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x%X, ignoring",
GB(
id, 0, 8));
5519 if (_cur.
grffile->housespec == NULL || _cur.
grffile->housespec[
GB(
id, 0, 8)] == NULL) {
5520 grfmsg(1,
"FeatureNewName: Attempt to name undefined house 0x%X, ignoring.",
GB(
id, 0, 8));
5527 grfmsg(7,
"FeatureNewName: Unsupported ID (0x%04X)",
id);
5546 if (offset >= max_sprites) {
5547 grfmsg(1,
"GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
5548 uint orig_num = num;
5553 if (offset + num > max_sprites) {
5554 grfmsg(4,
"GraphicsNew: %s sprite overflow, truncating...", name);
5555 uint orig_num = num;
5556 num =
max(max_sprites - offset, 0);
5557 return orig_num - num;
5586 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
5588 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
5619 uint8 type = buf->ReadByte();
5620 uint16 num = buf->ReadExtendedByte();
5621 uint16 offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
5627 grfmsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
5644 grfmsg(2,
"GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
5649 const Action5Type *action5_type = &_action5_types[type];
5655 grfmsg(1,
"GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
5662 grfmsg(1,
"GraphicsNew: %s (type 0x%02X) count must be at least %d. Only %d were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
5672 grfmsg(2,
"GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X", offset, offset + num - 1, action5_type->
name, type, replace);
5674 for (; num > 0; num--) {
5747 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
5777 *value = _game_mode;
5811 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
5820 *value = _openttd_newgrf_version;
5835 default:
return false;
5839 static uint32 GetParamVal(byte param, uint32 *cond_val)
5857 if (cond_val == NULL) {
5876 grfmsg(1,
"Unsupported in-game variable 0x%02X", param);
5899 byte *preload_sprite = NULL;
5903 preload_sprite = MallocT<byte>(num);
5911 grfmsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
5912 free(preload_sprite);
5917 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
5918 if (it != _grf_line_to_action6_sprite_override.end()) {
5919 free(preload_sprite);
5920 preload_sprite = _grf_line_to_action6_sprite_override[location];
5922 _grf_line_to_action6_sprite_override[location] = preload_sprite;
5935 param_num = buf->ReadByte();
5936 if (param_num == 0xFF)
break;
5940 param_size = buf->ReadByte();
5944 add_value =
HasBit(param_size, 7);
5945 param_size =
GB(param_size, 0, 7);
5948 offset = buf->ReadExtendedByte();
5952 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
5953 grfmsg(2,
"CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
5957 grfmsg(8,
"CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
5960 for (i = 0; i < param_size && offset + i < num; i++) {
5961 uint32 value = GetParamVal(param_num + i / 4, NULL);
5964 if (i % 4 == 0) carry =
false;
5967 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
5968 preload_sprite[offset + i] =
GB(new_value, 0, 8);
5970 carry = new_value >= 256;
5972 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6005 uint32 cond_val = 0;
6009 uint8 param = buf->ReadByte();
6010 uint8 paramsize = buf->ReadByte();
6011 uint8 condtype = buf->ReadByte();
6018 switch (paramsize) {
6019 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6020 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6021 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6022 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6026 if (param < 0x80 && _cur.grffile->param_end <= param) {
6027 grfmsg(7,
"SkipIf: Param %d undefined, skipping test", param);
6031 uint32 param_val = GetParamVal(param, &cond_val);
6033 grfmsg(7,
"SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
6043 if (param == 0x88 && (condtype < 0x0B || condtype > 0x0E)) {
6053 if (condtype != 10 && c == NULL) {
6054 grfmsg(7,
"SkipIf: GRFID 0x%08X unknown, skipping test",
BSWAP32(cond_val));
6081 default:
grfmsg(1,
"SkipIf: Unsupported GRF condition type %02X. Ignoring", condtype);
return;
6086 case 0x00: result = !!(param_val & (1 << cond_val));
6088 case 0x01: result = !(param_val & (1 << cond_val));
6090 case 0x02: result = (param_val & mask) == cond_val;
6092 case 0x03: result = (param_val & mask) != cond_val;
6094 case 0x04: result = (param_val & mask) < cond_val;
6096 case 0x05: result = (param_val & mask) > cond_val;
6107 default:
grfmsg(1,
"SkipIf: Unsupported condition type %02X. Ignoring", condtype);
return;
6112 grfmsg(2,
"SkipIf: Not skipping sprites, test was false");
6116 uint8 numsprites = buf->ReadByte();
6124 if (label->label != numsprites)
continue;
6127 if (choice == NULL) choice = label;
6129 if (label->nfo_line > _cur.
nfo_line) {
6135 if (choice != NULL) {
6136 grfmsg(2,
"SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line);
6142 grfmsg(2,
"SkipIf: Skipping %d sprites, test was true", numsprites);
6161 uint8 grf_version = buf->ReadByte();
6162 uint32 grfid = buf->ReadDWord();
6163 const char *name = buf->ReadString();
6167 if (grf_version < 2 || grf_version > 8) {
6169 DEBUG(grf, 0,
"%s: NewGRF \"%s\" (GRFID %08X) uses GRF version %d, which is incompatible with this version of OpenTTD.", _cur.
grfconfig->
filename, name,
BSWAP32(grfid), grf_version);
6177 if (buf->HasData()) {
6178 const char *info = buf->ReadString();
6196 uint8 version = buf->ReadByte();
6197 uint32 grfid = buf->ReadDWord();
6198 const char *name = buf->ReadString();
6201 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
6205 if (_cur.
grffile->grfid != grfid) {
6206 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));
6210 _cur.
grffile->grf_version = version;
6228 uint8 num_sets = buf->ReadByte();
6230 for (uint i = 0; i < num_sets; i++) {
6231 uint8 num_sprites = buf->ReadByte();
6232 uint16 first_sprite = buf->ReadWord();
6234 grfmsg(2,
"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
6235 i, num_sprites, first_sprite
6238 for (uint j = 0; j < num_sprites; j++) {
6239 int load_index = first_sprite + j;
6245 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
6255 uint8 num_sets = buf->ReadByte();
6257 for (uint i = 0; i < num_sets; i++) {
6286 STR_NEWGRF_ERROR_VERSION_NUMBER,
6287 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
6288 STR_NEWGRF_ERROR_UNSET_SWITCH,
6289 STR_NEWGRF_ERROR_INVALID_PARAMETER,
6290 STR_NEWGRF_ERROR_LOAD_BEFORE,
6291 STR_NEWGRF_ERROR_LOAD_AFTER,
6292 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
6296 STR_NEWGRF_ERROR_MSG_INFO,
6297 STR_NEWGRF_ERROR_MSG_WARNING,
6298 STR_NEWGRF_ERROR_MSG_ERROR,
6299 STR_NEWGRF_ERROR_MSG_FATAL
6302 byte severity = buf->ReadByte();
6303 byte lang = buf->ReadByte();
6304 byte message_id = buf->ReadByte();
6307 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
6311 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
6312 grfmsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur.
stage);
6317 if (severity >=
lengthof(sevstr)) {
6318 grfmsg(7,
"GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity);
6320 }
else if (severity == 3) {
6330 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
6331 grfmsg(7,
"GRFLoadError: Invalid message id.");
6335 if (buf->Remaining() <= 1) {
6336 grfmsg(7,
"GRFLoadError: No message data supplied.");
6345 if (message_id == 0xFF) {
6347 if (buf->HasData()) {
6348 const char *message = buf->ReadString();
6352 grfmsg(7,
"GRFLoadError: No custom message supplied.");
6356 error->
message = msgstr[message_id];
6359 if (buf->HasData()) {
6360 const char *data = buf->ReadString();
6364 grfmsg(7,
"GRFLoadError: No message data supplied.");
6370 uint param_number = buf->ReadByte();
6384 if (!buf->HasData())
return;
6386 const char *text = buf->ReadString();
6387 grfmsg(2,
"GRFComment: %s", text);
6393 uint8 target = buf->ReadByte();
6396 if (target < 0x80 || target == 0x9E)
return;
6410 static uint32 GetPatchVariable(uint8 param)
6420 case 0x0F:
return 0;
6436 case 0x11:
return SPR_2CCMAP_BASE;
6453 byte max_edge =
max(log_X, log_Y);
6455 if (log_X == log_Y) {
6458 if (max_edge == log_Y)
SetBit(map_bits, 1);
6461 return (map_bits << 24) | (
min(log_X, log_Y) << 20) | (max_edge << 16) |
6462 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
6471 return SPR_SLOPES_BASE;
6478 grfmsg(2,
"ParamSet: Unknown Patch variable 0x%02X.", param);
6484 static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target,
const char *type)
6497 for (uint i = start; i < num_ids; i++) {
6501 if (op == 2 || op == 3)
break;
6506 if (size == count)
break;
6509 if (size == count) {
6511 if (op == 0 || op == 3) {
6512 grfmsg(2,
"ParamSet: GRM: Reserving %d %s at %d", count, type, start);
6513 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
6519 if (op != 4 && op != 5) {
6521 grfmsg(0,
"ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
6526 grfmsg(1,
"ParamSet: GRM: Unable to allocate %d %s", count, type);
6556 uint8 target = buf->ReadByte();
6557 uint8 oper = buf->ReadByte();
6558 uint32 src1 = buf->ReadByte();
6559 uint32 src2 = buf->ReadByte();
6562 if (buf->Remaining() >= 4) data = buf->ReadDWord();
6571 if (target < 0x80 && target < _cur.grffile->param_end) {
6572 grfmsg(7,
"ParamSet: Param %u already defined, skipping", target);
6576 oper =
GB(oper, 0, 7);
6580 if (
GB(data, 0, 8) == 0xFF) {
6581 if (data == 0x0000FFFF) {
6583 src1 = GetPatchVariable(src1);
6587 uint8 feature =
GB(data, 8, 8);
6588 uint16 count =
GB(data, 16, 16);
6590 if (_cur.
stage == GLS_RESERVE) {
6591 if (feature == 0x08) {
6595 if (_cur.
spriteid + count >= 16384) {
6596 grfmsg(0,
"ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
6602 grfmsg(4,
"ParamSet: GRM: Allocated %d sprites at %d", count, _cur.
spriteid);
6609 }
else if (_cur.
stage == GLS_ACTIVATION) {
6638 grfmsg(4,
"ParamSet: GRM: Using pre-allocated sprites at %d", src1);
6646 grfmsg(1,
"ParamSet: GRM: Unsupported operation %d for general sprites", op);
6657 default:
grfmsg(1,
"ParamSet: GRM: Unsupported feature 0x%X", feature);
return;
6674 }
else if (src1 == 0xFE) {
6686 src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
6687 src2 = (src2 == 0xFF) ? data : GetParamVal(src2, NULL);
6715 res = (int32)src1 * (int32)src2;
6719 if ((int32)src2 < 0) {
6720 res = src1 >> -(int32)src2;
6722 res = src1 << (src2 & 0x1F);
6727 if ((int32)src2 < 0) {
6728 res = (int32)src1 >> -(int32)src2;
6730 res = (int32)src1 << (src2 & 0x1F);
6754 res = (int32)src1 / (int32)src2;
6770 res = (int32)src1 % (int32)src2;
6774 default:
grfmsg(0,
"ParamSet: Unknown operation %d, skipping", oper);
return;
6803 grfmsg(7,
"ParamSet: Skipping unimplemented target 0x%02X", target);
6814 uint32 safe_bits = 0;
6815 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
6824 grfmsg(7,
"ParamSet: Skipping unimplemented target 0x%02X", target);
6828 if (target < 0x80) {
6829 _cur.
grffile->param[target] = res;
6833 grfmsg(7,
"ParamSet: Skipping unknown target 0x%02X", target);
6847 uint8 num = buf->ReadByte();
6849 for (uint i = 0; i < num; i++) {
6850 uint32 grfid = buf->ReadDWord();
6872 uint8 num = buf->ReadByte();
6874 for (uint i = 0; i < num; i++) {
6875 uint32 grfid = buf->ReadDWord();
6879 if (file != NULL && file != _cur.
grfconfig) {
6897 uint32 grfid = _cur.
grffile->grfid;
6901 byte
id = buf->ReadByte();
6902 grfmsg(6,
"FeatureTownName: definition 0x%02X",
id & 0x7F);
6907 bool new_scheme = _cur.
grffile->grf_version >= 7;
6909 byte lang = buf->ReadByte();
6911 byte nb_gen = townname->nb_gen;
6915 const char *name = buf->ReadString();
6918 grfmsg(6,
"FeatureTownName: lang 0x%X -> '%s'", lang, lang_name);
6921 townname->name[nb_gen] =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6923 lang = buf->ReadByte();
6924 }
while (lang != 0);
6925 townname->id[nb_gen] = id;
6929 byte nb = buf->ReadByte();
6930 grfmsg(6,
"FeatureTownName: %u parts", nb);
6932 townname->nbparts[id] = nb;
6933 townname->partlist[id] = CallocT<NamePartList>(nb);
6935 for (
int i = 0; i < nb; i++) {
6936 byte nbtext = buf->ReadByte();
6937 townname->partlist[id][i].bitstart = buf->ReadByte();
6938 townname->partlist[id][i].bitcount = buf->ReadByte();
6939 townname->partlist[id][i].maxprob = 0;
6940 townname->partlist[id][i].partcount = nbtext;
6941 townname->partlist[id][i].parts = CallocT<NamePart>(nbtext);
6942 grfmsg(6,
"FeatureTownName: part %d contains %d texts and will use GB(seed, %d, %d)", i, nbtext, townname->partlist[
id][i].bitstart, townname->partlist[
id][i].bitcount);
6944 for (
int j = 0; j < nbtext; j++) {
6945 byte prob = buf->ReadByte();
6948 byte ref_id = buf->ReadByte();
6950 if (townname->nbparts[ref_id] == 0) {
6951 grfmsg(0,
"FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
6952 DelGRFTownName(grfid);
6957 grfmsg(6,
"FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
6958 townname->partlist[id][i].parts[j].data.
id = ref_id;
6960 const char *text = buf->ReadString();
6962 grfmsg(6,
"FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[
id][i].parts[j].data.
text, prob);
6964 townname->partlist[id][i].parts[j].
prob = prob;
6965 townname->partlist[id][i].maxprob +=
GB(prob, 0, 7);
6967 grfmsg(6,
"FeatureTownName: part %d, total probability %d", i, townname->partlist[
id][i].maxprob);
6979 byte nfo_label = buf->ReadByte();
6981 GRFLabel *label = MallocT<GRFLabel>(1);
6982 label->label = nfo_label;
6993 for (l = _cur.
grffile->
label; l->next != NULL; l = l->next) {}
6997 grfmsg(2,
"DefineGotoLabel: GOTO target with label 0x%02X", label->label);
7011 if (file == NULL || file->sound_offset == 0) {
7012 grfmsg(1,
"ImportGRFSound: Source file not available");
7016 if (sound_id >= file->num_sounds) {
7017 grfmsg(1,
"ImportGRFSound: Sound effect %d is invalid", sound_id);
7021 grfmsg(2,
"ImportGRFSound: Copying sound %d (%d) from file %X", sound_id, file->sound_offset + sound_id, grfid);
7023 *sound = *GetSound(file->sound_offset + sound_id);
7026 sound->volume = 128;
7027 sound->priority = 0;
7038 sound->volume = 0x80;
7039 sound->priority = 0;
7041 if (offs != SIZE_MAX) {
7044 sound->file_offset = offs;
7056 uint16 num = buf->ReadWord();
7057 if (num == 0)
return;
7060 if (_cur.
grffile->sound_offset == 0) {
7061 _cur.
grffile->sound_offset = GetNumSounds();
7062 _cur.
grffile->num_sounds = num;
7065 sound = GetSound(_cur.
grffile->sound_offset);
7068 for (
int i = 0; i < num; i++) {
7073 bool invalid = i >= _cur.
grffile->num_sounds;
7083 grfmsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7085 }
else if (len != 4) {
7086 grfmsg(1,
"GRFSound: Invalid sprite section import");
7096 grfmsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7103 grfmsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7111 if (_cur.
stage == GLS_INIT) {
7113 grfmsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7122 if (_cur.
stage == GLS_ACTIVATION) {
7133 grfmsg(1,
"GRFSound: Unexpected Action %x found, skipping", action);
7162 uint8 num_def = buf->ReadByte();
7164 for (uint i = 0; i < num_def; i++) {
7166 uint8 num_char = buf->ReadByte();
7167 uint16 base_char = buf->ReadWord();
7169 if (size >= FS_END) {
7170 grfmsg(1,
"LoadFontGlyph: Size %u is not supported, ignoring", size);
7173 grfmsg(7,
"LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
7175 for (uint c = 0; c < num_char; c++) {
7193 uint8 num_def = buf->ReadByte();
7195 for (uint i = 0; i < num_def; i++) {
7219 uint32 grfid = buf->ReadDWord();
7222 grfmsg(7,
"TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13",
BSWAP32(grfid));
7232 GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE,
lastof(tmp));
7243 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
7244 byte num_strings = buf->ReadByte();
7245 uint16 first_id = buf->ReadWord();
7247 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
7248 grfmsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
7252 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
7253 const char *
string = buf->ReadString();
7256 grfmsg(7,
"TranslateGRFString: Ignoring empty string.");
7260 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
7289 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE
", ignoring this field", len);
7301 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got " PRINTF_SIZE
", ignoring this field", len);
7304 char data = buf->ReadByte();
7312 grfmsg(2,
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data);
7327 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got " PRINTF_SIZE
", ignoring this field", len);
7330 char data = buf->ReadByte();
7336 grfmsg(2,
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'BLTR', ignoring this field", data);
7349 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got " PRINTF_SIZE
", ignoring this field", len);
7362 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got " PRINTF_SIZE
", ignoring this field", len);
7367 grfmsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
7398 grfmsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got " PRINTF_SIZE
", ignoring this field", len);
7403 _cur_parameter->
type = type;
7405 grfmsg(3,
"StaticGRFInfo: unknown parameter type %d, ignoring this field", type);
7415 grfmsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
7417 }
else if (len != 8) {
7418 grfmsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got " PRINTF_SIZE
", ignoring this field", len);
7421 _cur_parameter->
min_value = buf->ReadDWord();
7422 _cur_parameter->
max_value = buf->ReadDWord();
7430 if (len < 1 || len > 3) {
7431 grfmsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got " PRINTF_SIZE
", ignoring this field", len);
7434 byte param_nr = buf->ReadByte();
7436 grfmsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param %d, ignoring this field", param_nr);
7439 _cur_parameter->
param_nr = param_nr;
7440 if (len >= 2) _cur_parameter->
first_bit =
min(buf->ReadByte(), 31);
7441 if (len >= 3) _cur_parameter->
num_bit =
min(buf->ReadByte(), 32 - _cur_parameter->
first_bit);
7452 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got " PRINTF_SIZE
", ignoring this field", len);
7455 _cur_parameter->
def_value = buf->ReadDWord();
7488 this->handler.data = handler;
7500 this->handler.text = handler;
7512 this->handler.call_handler =
true;
7513 this->handler.u.branch = handler;
7525 this->handler.call_handler =
false;
7526 this->handler.u.subtags =
subtags;
7555 byte type = buf->ReadByte();
7557 uint32
id = buf->ReadDWord();
7558 if (type !=
'T' ||
id > _cur_parameter->
max_value) {
7559 grfmsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
7561 type = buf->ReadByte();
7565 byte langid = buf->ReadByte();
7566 const char *name_string = buf->ReadString();
7577 type = buf->ReadByte();
7602 byte type = buf->ReadByte();
7604 uint32
id = buf->ReadDWord();
7606 grfmsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
7608 type = buf->ReadByte();
7615 MemSetT<GRFParameterInfo *>(newdata, 0, num_to_add);
7622 if (!
HandleNodes(buf, _tags_parameters))
return false;
7623 type = buf->ReadByte();
7660 byte new_type = buf->ReadByte();
7661 while (new_type != 0) {
7664 new_type = buf->ReadByte();
7675 uint16 size = buf->ReadWord();
7699 while ((tag = &subtags[i++])->type != 0) {
7702 default: NOT_REACHED();
7705 byte langid = buf->ReadByte();
7706 return tag->handler.
text(langid, buf->ReadString());
7710 size_t len = buf->ReadWord();
7711 if (buf->Remaining() < len)
return false;
7712 return tag->handler.
data(len, buf);
7717 return tag->handler.u.branch(buf);
7723 grfmsg(2,
"StaticGRFInfo: unknown type/id combination found, type=%c, id=%x", type,
id);
7735 byte type = buf->ReadByte();
7737 uint32
id = buf->ReadDWord();
7738 if (!
HandleNode(type,
id, buf, subtags))
return false;
7739 type = buf->ReadByte();
7856 const GRFFile *
const *end = _grf_files.
End();
7857 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7859 if (stations == NULL)
continue;
7861 if (stations[i] == NULL)
continue;
7867 if (!statspec->copied_layouts) {
7868 for (uint l = 0; l < statspec->lengths; l++) {
7869 for (uint p = 0; p < statspec->platforms[l]; p++) {
7870 free(statspec->layouts[l][p]);
7872 free(statspec->layouts[l]);
7874 free(statspec->layouts);
7875 free(statspec->platforms);
7891 const GRFFile *
const *end = _grf_files.
End();
7892 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7893 HouseSpec **&housespec = (*file)->housespec;
7894 if (housespec == NULL)
continue;
7907 const GRFFile *
const *end = _grf_files.
End();
7908 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7910 if (aslist != NULL) {
7916 for (
int j = 0; j < as->
num_table; j++) {
7928 (*file)->airportspec = NULL;
7932 if (airporttilespec != NULL) {
7934 free(airporttilespec[i]);
7936 free(airporttilespec);
7937 airporttilespec = NULL;
7945 const GRFFile *
const *end = _grf_files.
End();
7946 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7952 if (industryspec != NULL) {
7955 if (ind == NULL)
continue;
7969 industryspec = NULL;
7972 if (indtspec == NULL)
continue;
7985 const GRFFile *
const *end = _grf_files.
End();
7986 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7987 ObjectSpec **&objectspec = (*file)->objectspec;
7988 if (objectspec == NULL)
continue;
7990 free(objectspec[i]);
8001 const GRFFile *
const *end = _grf_files.
End();
8002 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8028 CleanUpGRFTownNames();
8070 ObjectClass::Reset();
8075 StationClass::Reset();
8079 AirportClass::Reset();
8102 _loaded_newgrf_features.
has_2CC =
false;
8109 _grf_id_overrides.clear();
8111 InitializeSoundPool();
8159 if (newfile != NULL) {
8165 newfile =
new GRFFile(config);
8183 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8207 free(this->filename);
8217 'PASS',
'COAL',
'MAIL',
'LVST',
'GOOD',
'GRAI',
'WHEA',
'MAIZ',
'WOOD',
8218 'IORE',
'STEL',
'VALU',
'GOLD',
'DIAM',
'PAPR',
'FOOD',
'FRUT',
'CORE',
8219 'WATR',
'SUGR',
'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
8223 static const CargoLabel _default_refitmasks_road[] = {
8226 static const CargoLabel _default_refitmasks_ships[] = {
8227 'COAL',
'MAIL',
'LVST',
'GOOD',
'GRAI',
'WHEA',
'MAIZ',
'WOOD',
'IORE',
8228 'STEL',
'VALU',
'GOLD',
'DIAM',
'PAPR',
'FOOD',
'FRUT',
'CORE',
'WATR',
8229 'RUBR',
'SUGR',
'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
8233 static const CargoLabel _default_refitmasks_aircraft[] = {
8234 'PASS',
'MAIL',
'GOOD',
'VALU',
'GOLD',
'DIAM',
'FOOD',
'FRUT',
'SUGR',
8235 'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
'PLST',
'FZDR',
8238 static const CargoLabel *
const _default_refitmasks[] = {
8240 _default_refitmasks_road,
8241 _default_refitmasks_ships,
8242 _default_refitmasks_aircraft,
8253 FOR_ALL_ENGINES(e) {
8256 bool only_defaultcargo;
8261 uint32 not_mask = 0;
8262 uint32 xor_mask = ei->refit_mask;
8268 if (_gted[engine].cargo_allowed != 0) {
8271 FOR_ALL_CARGOSPECS(cs) {
8277 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
8283 uint32 xor_mask = 0;
8288 for (uint i = 0;; i++) {
8289 if (cl[i] == 0)
break;
8301 only_defaultcargo = (ei->refit_mask == 0);
8315 if (ei->cargo_type ==
CT_INVALID && ei->refit_mask != 0) {
8317 const uint8 *cargo_map_for_first_refittable = NULL;
8320 if (file == NULL) file = e->
GetGRF();
8321 if (file != NULL && file->grf_version >= 8 && file->
cargo_list.
Length() != 0) {
8322 cargo_map_for_first_refittable = file->
cargo_map;
8326 if (cargo_map_for_first_refittable != NULL) {
8328 byte best_local_slot = 0xFF;
8330 FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) {
8331 byte local_slot = cargo_map_for_first_refittable[cargo_type];
8332 if (local_slot < best_local_slot) {
8333 best_local_slot = local_slot;
8334 ei->cargo_type = cargo_type;
8356 for (uint i = 0; i < CF_END; i++) {
8369 FOR_ALL_ENGINES(e) {
8370 if (e->
GetGRF() == NULL) {
8373 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
8406 default: NOT_REACHED();
8420 cs->
quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
8421 cs->
abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
8445 if (filename != NULL)
DEBUG(grf, 1,
"FinaliseHouseArray: %s defines house %d as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
8455 if (filename != NULL)
DEBUG(grf, 1,
"FinaliseHouseArray: %s defines multitile house %d with non-zero population on additional tiles. Disabling house.", filename, hs->
grf_prop.
local_id);
8463 DEBUG(grf, 1,
"FinaliseHouseArray: %s defines house %d with different house size then it's substitute type. Disabling house.", filename, hs->
grf_prop.
local_id);
8470 if (filename != NULL)
DEBUG(grf, 1,
"FinaliseHouseArray: %s defines house %d without a size but marked it as available. Disabling house.", filename, hs->
grf_prop.
local_id);
8489 if (hs == NULL || !hs->
enabled)
continue;
8494 if (min_year == 0)
return;
8498 if (hs == NULL || !hs->
enabled)
continue;
8521 const GRFFile *
const *end = _grf_files.
End();
8522 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8523 HouseSpec **&housespec = (*file)->housespec;
8524 if (housespec == NULL)
continue;
8529 if (hs == NULL)
continue;
8531 const HouseSpec *next1 = (i + 1 < NUM_HOUSES_PER_GRF ? housespec[i + 1] : NULL);
8532 const HouseSpec *next2 = (i + 2 < NUM_HOUSES_PER_GRF ? housespec[i + 2] : NULL);
8533 const HouseSpec *next3 = (i + 3 < NUM_HOUSES_PER_GRF ? housespec[i + 3] : NULL);
8535 if (!
IsHouseSpecValid(hs, next1, next2, next3, (*file)->filename))
continue;
8543 const HouseSpec *next1 = (i + 1 < NUM_HOUSES ? HouseSpec::Get(i + 1) : NULL);
8544 const HouseSpec *next2 = (i + 2 < NUM_HOUSES ? HouseSpec::Get(i + 2) : NULL);
8545 const HouseSpec *next3 = (i + 3 < NUM_HOUSES ? HouseSpec::Get(i + 3) : NULL);
8584 const GRFFile *
const *end = _grf_files.
End();
8585 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8588 if (industryspec != NULL) {
8592 if (indsp != NULL && indsp->
enabled) {
8598 if (strid != STR_UNDEFINED) indsp->
name = strid;
8601 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
8616 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
8625 if (indtspec != NULL) {
8628 if (indtsp != NULL) {
8629 _industile_mngr.SetEntitySpec(indtsp);
8638 for (uint i = 0; i < 3; i++) {
8643 indsp->
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
8655 const GRFFile *
const *end = _grf_files.
End();
8656 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8657 ObjectSpec **&objectspec = (*file)->objectspec;
8658 if (objectspec != NULL) {
8660 if (objectspec[i] != NULL && objectspec[i]->grf_prop.grffile != NULL && objectspec[i]->
enabled) {
8675 const GRFFile *
const *end = _grf_files.
End();
8676 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8677 AirportSpec **&airportspec = (*file)->airportspec;
8678 if (airportspec != NULL) {
8680 if (airportspec[i] != NULL && airportspec[i]->enabled) {
8681 _airport_mngr.SetEntitySpec(airportspec[i]);
8687 if (airporttilespec != NULL) {
8689 if (airporttilespec[i] != NULL && airporttilespec[i]->enabled) {
8690 _airporttile_mngr.SetEntitySpec(airporttilespec[i]);
8703 static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
8717 static const SpecialSpriteHandler handlers[][GLS_END] = {
8718 { NULL, SafeChangeInfo, NULL, NULL, ReserveChangeInfo, FeatureChangeInfo, },
8719 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
8720 { NULL, NULL, NULL, NULL, NULL, NewSpriteGroup, },
8721 { NULL,
GRFUnsafe, NULL, NULL, NULL, FeatureMapSpriteGroup, },
8722 { NULL, NULL, NULL, NULL, NULL, FeatureNewName, },
8723 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
8724 { NULL, NULL, NULL, CfgApply, CfgApply, CfgApply, },
8725 { NULL, NULL, NULL, NULL, SkipIf, SkipIf, },
8726 { ScanInfo, NULL, NULL, GRFInfo, GRFInfo, GRFInfo, },
8727 { NULL, NULL, NULL, SkipIf, SkipIf, SkipIf, },
8728 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
8729 { NULL, NULL, NULL, GRFLoadError, GRFLoadError, GRFLoadError, },
8730 { NULL, NULL, NULL, GRFComment, NULL, GRFComment, },
8732 { NULL, SafeGRFInhibit, NULL, GRFInhibit, GRFInhibit, GRFInhibit, },
8735 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
8743 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
8744 if (it == _grf_line_to_action6_sprite_override.end()) {
8750 buf = _grf_line_to_action6_sprite_override[location];
8751 grfmsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
8761 byte action = bufp->ReadByte();
8763 if (action == 0xFF) {
8764 grfmsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
8765 }
else if (action == 0xFE) {
8766 grfmsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
8767 }
else if (action >=
lengthof(handlers)) {
8768 grfmsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x%02X", action);
8769 }
else if (handlers[action][stage] == NULL) {
8770 grfmsg(7,
"DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage);
8772 grfmsg(7,
"DecodeSpecialSprite: Handling action 0x%02X in stage %d", action, stage);
8773 handlers[action][stage](bufp);
8776 grfmsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
8783 extern const byte
_grf_cont_v2_sig[8] = {
'G',
'R',
'F', 0x82, 0x0D, 0x0A, 0x1A, 0x0A};
8796 for (uint i = 0; i <
lengthof(_grf_cont_v2_sig); i++) {
8797 if (
FioReadByte() != _grf_cont_v2_sig[i])
return 0;
8817 const char *filename = config->
filename;
8828 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
8830 if (_cur.
grffile == NULL)
usererror(
"File '%s' lost in cache.\n", filename);
8836 DEBUG(grf, 0,
"'%s' is not loaded as the maximum number of file slots has been reached", filename);
8838 config->
error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
8848 DEBUG(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
8852 DEBUG(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
8856 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
8868 if (compression != 0) {
8869 DEBUG(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
8881 DEBUG(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
8895 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
8906 grfmsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
8907 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
8972 static const uint32 override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
8975 int num_grfs = _grf_files.
Length();
8976 int *grf_overrides =
AllocaM(
int, num_grfs);
8977 for (
int i = 0; i < num_grfs; i++) {
8978 grf_overrides[i] = -1;
8980 GRFFile *source = _grf_files[i];
8981 uint32
override = _grf_id_overrides[source->grfid];
8982 if (
override == 0)
continue;
8985 if (dest == NULL)
continue;
8987 grf_overrides[i] = _grf_files.
FindIndex(dest);
8988 assert(grf_overrides[i] >= 0);
8992 for (
int i = 0; i < num_grfs; i++) {
8993 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
8994 GRFFile *source = _grf_files[i];
8995 GRFFile *dest = _grf_files[grf_overrides[i]];
9001 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9004 DEBUG(grf, 3,
"'%s' overrides price base multiplier %d of '%s'", source->filename, p, dest->filename);
9010 for (
int i = num_grfs - 1; i >= 0; i--) {
9011 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9012 GRFFile *source = _grf_files[i];
9013 GRFFile *dest = _grf_files[grf_overrides[i]];
9019 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9022 DEBUG(grf, 3,
"Price base multiplier %d from '%s' propagated to '%s'", p, source->filename, dest->filename);
9028 for (
int i = 0; i < num_grfs; i++) {
9029 if (grf_overrides[i] < 0)
continue;
9030 GRFFile *source = _grf_files[i];
9031 GRFFile *dest = _grf_files[grf_overrides[i]];
9037 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9038 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9040 DEBUG(grf, 3,
"Price base multiplier %d from '%s' propagated to '%s'", p, dest->filename, source->filename);
9047 const GRFFile *
const *end = _grf_files.
End();
9048 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
9049 if ((*file)->grf_version >= 8)
continue;
9050 PriceMultipliers &price_base_multipliers = (*file)->price_base_multipliers;
9051 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9053 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9056 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9062 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
9063 PriceMultipliers &price_base_multipliers = (*file)->price_base_multipliers;
9064 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9065 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9067 price_base_multipliers[p] = 0;
9072 DEBUG(grf, 3,
"'%s' sets global price base multiplier %d", (*file)->filename, p);
9074 price_base_multipliers[p] = 0;
9076 DEBUG(grf, 3,
"'%s' sets local price base multiplier %d", (*file)->filename, p);
9091 _string_to_grf_mapping.
Clear();
9094 for (GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.begin(); it != _grf_line_to_action6_sprite_override.end(); it++) {
9097 _grf_line_to_action6_sprite_override.clear();
9148 FOR_ALL_ENGINES_OF_TYPE(e,
VEH_ROAD) {
9161 e->u.rail.railtype = railtype;
9171 _grm_sprites.clear();
9180 void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
9220 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
9227 if (stage == GLS_RESERVE) {
9228 static const uint32 overrides[][2] = {
9229 { 0x44442202, 0x44440111 },
9230 { 0x6D620402, 0x6D620401 },
9231 { 0x4D656f20, 0x4D656F17 },
9233 for (
size_t i = 0; i <
lengthof(overrides); i++) {
9238 uint slot = file_index;
9239 uint num_non_static = 0;
9248 DEBUG(grf, 0,
"NewGRF file is missing '%s'; disabling", c->
filename);
9257 DEBUG(grf, 0,
"'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
9259 c->
error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
9265 if (stage == GLS_RESERVE) {
9267 }
else if (stage == GLS_ACTIVATION) {
9272 DEBUG(sprite, 2,
"LoadNewGRF: Currently %i sprites are loaded", _cur.
spriteid);