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;
3690 grfmsg(1,
"AirportChangeInfo: Too many airports, trying id (%u), max (%u). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3695 if (_cur.
grffile->airportspec == NULL) {
3699 for (
int i = 0; i < numinfo; i++) {
3702 if (as == NULL && prop != 0x08 && prop != 0x09) {
3703 grfmsg(2,
"AirportChangeInfo: Attempt to modify undefined airport %u, ignoring", airport + i);
3709 byte subs_id = buf->ReadByte();
3711 if (subs_id == 0xFF) {
3718 grfmsg(2,
"AirportChangeInfo: Attempt to use new airport %u as substitute airport for %u. Ignoring.", subs_id, airport + i);
3726 if (*spec == NULL) {
3727 *spec = MallocT<AirportSpec>(1);
3732 as->grf_prop.local_id = airport + i;
3733 as->grf_prop.subst_id = subs_id;
3734 as->grf_prop.grffile = _cur.
grffile;
3736 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3746 uint32 defsize = buf->ReadDWord();
3752 for (byte j = 0; j < as->
num_table; j++) {
3754 for (
int k = 0;; k++) {
3755 att[k].ti.x = buf->ReadByte();
3756 att[k].ti.y = buf->ReadByte();
3758 if (att[k].ti.x == 0 && att[k].ti.y == 0x80) {
3761 att[k].ti.x = -0x80;
3770 att[k].
gfx = buf->ReadByte();
3772 if (att[k].gfx == 0xFE) {
3774 int local_tile_id = buf->ReadWord();
3777 uint16 tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3780 grfmsg(2,
"AirportChangeInfo: Attempt to use airport tile %u with airport id %u, not yet defined. Ignoring.", local_tile_id, airport + i);
3783 att[k].gfx = tempid;
3787 }
else if (att[k].gfx == 0xFF) {
3788 att[k].
ti.
x = (int8)
GB(att[k].ti.x, 0, 8);
3789 att[k].ti.y = (int8)
GB(att[k].ti.y, 0, 8);
3800 tile_table[j] = CallocT<AirportTileTable>(size);
3801 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
3804 as->
table = tile_table;
3807 for (
int i = 0; i < as->
num_table; i++) {
3808 free(tile_table[i]);
3914 if (_cur.
grffile->objectspec == NULL) {
3918 for (
int i = 0; i < numinfo; i++) {
3921 if (prop != 0x08 && spec == NULL) {
3924 if (cir > ret) ret = cir;
3933 if (*ospec == NULL) {
3934 *ospec = CallocT<ObjectSpec>(1);
3935 (*ospec)->
views = 1;
3939 uint32 classid = buf->ReadDWord();
3940 (*ospec)->cls_id = ObjectClass::Allocate(
BSWAP32(classid));
3941 (*ospec)->enabled =
true;
3956 spec->
climate = buf->ReadByte();
3960 spec->
size = buf->ReadByte();
4003 spec->
height = buf->ReadByte();
4007 spec->
views = buf->ReadByte();
4009 grfmsg(2,
"ObjectChangeInfo: Invalid number of views (%u) for object id %u. Ignoring.", spec->
views,
id + i);
4042 grfmsg(1,
"RailTypeChangeInfo: Rail type %u is invalid, max %u, ignoring",
id + numinfo,
RAILTYPE_END);
4046 for (
int i = 0; i < numinfo; i++) {
4059 uint16 str = buf->ReadWord();
4061 if (_cur.
grffile->grf_version < 8) {
4091 int n = buf->ReadByte();
4092 for (
int j = 0; j != n; j++) {
4093 RailTypeLabel label = buf->ReadDWord();
4153 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4172 grfmsg(1,
"RailTypeReserveInfo: Rail type %u is invalid, max %u, ignoring",
id + numinfo,
RAILTYPE_END);
4176 for (
int i = 0; i < numinfo; i++) {
4180 RailTypeLabel rtl = buf->ReadDWord();
4189 _cur.
grffile->railtype_map[
id + i] = rt;
4207 int n = buf->ReadByte();
4208 for (
int j = 0; j != n; j++) {
4213 grfmsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type %u because no label was set",
id + i);
4220 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4255 if (_cur.
grffile->airtspec == NULL) {
4259 for (
int i = 0; i < numinfo; i++) {
4262 if (prop != 0x08 && tsp == NULL) {
4263 grfmsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile %u. Ignoring.", airtid + i);
4270 byte subs_id = buf->ReadByte();
4274 grfmsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile %u as substitute airport tile for %u. Ignoring.", subs_id, airtid + i);
4279 if (*tilespec == NULL) {
4280 *tilespec = CallocT<AirportTileSpec>(1);
4284 tsp->enabled =
true;
4288 tsp->grf_prop.local_id = airtid + i;
4289 tsp->grf_prop.subst_id = subs_id;
4290 tsp->grf_prop.grffile = _cur.
grffile;
4297 byte
override = buf->ReadByte();
4301 grfmsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile %u with airport tile id %u. Ignoring.",
override, airtid + i);
4305 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4310 tsp->callback_mask = buf->ReadByte();
4314 tsp->animation.frames = buf->ReadByte();
4315 tsp->animation.status = buf->ReadByte();
4319 tsp->animation.speed = buf->ReadByte();
4323 tsp->animation.triggers = buf->ReadByte();
4335 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8 feature, uint8 property)
4338 default: NOT_REACHED();
4348 grfmsg(1,
"%s: Ignoring property 0x%02X of feature 0x%02X (not implemented)", caller, property, feature);
4352 grfmsg(0,
"%s: Unknown property 0x%02X of feature 0x%02X, disabling", caller, property, feature);
4365 static void FeatureChangeInfo(
ByteReader *buf)
4378 static const VCI_Handler handler[] = {
4396 AirportTilesChangeInfo,
4399 uint8 feature = buf->ReadByte();
4400 uint8 numprops = buf->ReadByte();
4401 uint numinfo = buf->ReadByte();
4402 uint engine = buf->ReadExtendedByte();
4404 grfmsg(6,
"FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d",
4405 feature, numprops, engine, numinfo);
4407 if (feature >=
lengthof(handler) || handler[feature] == NULL) {
4408 if (feature != GSF_CARGOES)
grfmsg(1,
"FeatureChangeInfo: Unsupported feature %d, skipping", feature);
4415 while (numprops-- && buf->HasData()) {
4416 uint8 prop = buf->ReadByte();
4419 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
4426 uint8 feature = buf->ReadByte();
4427 uint8 numprops = buf->ReadByte();
4428 uint numinfo = buf->ReadByte();
4429 buf->ReadExtendedByte();
4431 if (feature == GSF_BRIDGES && numprops == 1) {
4432 uint8 prop = buf->ReadByte();
4435 if (prop == 0x0D)
return;
4436 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
4437 uint8 prop = buf->ReadByte();
4440 bool is_safe =
true;
4441 for (uint i = 0; i < numinfo; i++) {
4442 uint32 s = buf->ReadDWord();
4450 if (is_safe)
return;
4461 static void ReserveChangeInfo(
ByteReader *buf)
4463 uint8 feature = buf->ReadByte();
4465 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES)
return;
4467 uint8 numprops = buf->ReadByte();
4468 uint8 numinfo = buf->ReadByte();
4469 uint8 index = buf->ReadExtendedByte();
4471 while (numprops-- && buf->HasData()) {
4472 uint8 prop = buf->ReadByte();
4476 default: NOT_REACHED();
4482 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
4486 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
4490 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
4511 uint8 feature = buf->ReadByte();
4512 uint16 num_sets = buf->ReadByte();
4513 uint16 first_set = 0;
4515 if (num_sets == 0 && buf->HasData(3)) {
4518 first_set = buf->ReadExtendedByte();
4519 num_sets = buf->ReadExtendedByte();
4521 uint16 num_ents = buf->ReadExtendedByte();
4525 grfmsg(7,
"New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d)",
4526 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
4529 for (
int i = 0; i < num_sets * num_ents; i++) {
4539 uint16 num_sets = buf->ReadByte();
4541 if (num_sets == 0 && buf->HasData(3)) {
4544 buf->ReadExtendedByte();
4545 num_sets = buf->ReadExtendedByte();
4547 uint16 num_ents = buf->ReadExtendedByte();
4556 static const SpriteGroup *GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
4558 if (
HasBit(groupid, 15)) {
4563 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] == NULL) {
4564 grfmsg(1,
"GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid);
4568 return _cur.spritegroups[groupid];
4581 if (
HasBit(spriteid, 15)) {
4587 grfmsg(1,
"CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid", setid, type, spriteid);
4592 uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
4595 assert(spriteset_start + num_sprites <= _cur.
spriteid);
4616 uint8 feature = buf->ReadByte();
4617 uint8 setid = buf->ReadByte();
4618 uint8 type = buf->ReadByte();
4641 switch (
GB(type, 2, 2)) {
4642 default: NOT_REACHED();
4643 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
4644 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
4645 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
4658 adjust->variable = buf->ReadByte();
4659 if (adjust->variable == 0x7E) {
4661 adjust->subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
4666 varadjust = buf->ReadByte();
4667 adjust->shift_num =
GB(varadjust, 0, 5);
4668 adjust->type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
4669 adjust->and_mask = buf->ReadVarSize(varsize);
4671 if (adjust->type != DSGA_TYPE_NONE) {
4672 adjust->add_val = buf->ReadVarSize(varsize);
4673 adjust->divmod_val = buf->ReadVarSize(varsize);
4675 adjust->add_val = 0;
4676 adjust->divmod_val = 0;
4680 }
while (
HasBit(varadjust, 5));
4682 group->num_adjusts = adjusts.
Length();
4683 group->adjusts = MallocT<DeterministicSpriteGroupAdjust>(group->num_adjusts);
4684 MemCpyT(group->adjusts, adjusts.
Begin(), group->num_adjusts);
4686 group->num_ranges = buf->ReadByte();
4687 if (group->num_ranges > 0) group->ranges = CallocT<DeterministicSpriteGroupRange>(group->num_ranges);
4689 for (uint i = 0; i < group->num_ranges; i++) {
4690 group->ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
4691 group->ranges[i].low = buf->ReadVarSize(varsize);
4692 group->ranges[i].high = buf->ReadVarSize(varsize);
4695 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
4711 group->count = buf->ReadByte();
4714 uint8 triggers = buf->ReadByte();
4715 group->triggers =
GB(triggers, 0, 7);
4716 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
4721 for (uint i = 0; i < group->
num_groups; i++) {
4722 group->
groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
4733 case GSF_ROADVEHICLES:
4742 byte num_loaded = type;
4743 byte num_loading = buf->ReadByte();
4746 grfmsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
4756 if (num_loaded > 0) group->
loaded = CallocT<const SpriteGroup*>(num_loaded);
4757 if (num_loading > 0) group->
loading = CallocT<const SpriteGroup*>(num_loading);
4759 grfmsg(6,
"NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
4760 setid, num_loaded, num_loading);
4762 for (uint i = 0; i < num_loaded; i++) {
4763 uint16 spriteid = buf->ReadWord();
4765 grfmsg(8,
"NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
4768 for (uint i = 0; i < num_loading; i++) {
4769 uint16 spriteid = buf->ReadWord();
4771 grfmsg(8,
"NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
4778 case GSF_AIRPORTTILES:
4780 case GSF_INDUSTRYTILES: {
4781 byte num_building_sprites =
max((uint8)1, type);
4788 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
4792 case GSF_INDUSTRIES: {
4794 grfmsg(1,
"NewSpriteGroup: Unsupported industry production version %d, skipping", type);
4801 group->version = type;
4803 for (uint i = 0; i < 3; i++) {
4804 group->subtract_input[i] = (int16)buf->ReadWord();
4806 for (uint i = 0; i < 2; i++) {
4807 group->add_output[i] = buf->ReadWord();
4809 group->again = buf->ReadByte();
4811 for (uint i = 0; i < 3; i++) {
4812 group->subtract_input[i] = buf->ReadByte();
4814 for (uint i = 0; i < 2; i++) {
4815 group->add_output[i] = buf->ReadByte();
4817 group->again = buf->ReadByte();
4823 default:
grfmsg(1,
"NewSpriteGroup: Unsupported feature %d, skipping", feature);
4828 _cur.spritegroups[setid] = act_group;
4831 static CargoID TranslateCargo(uint8 feature, uint8 ctype)
4833 if (feature == GSF_OBJECTS) {
4838 grfmsg(1,
"TranslateCargo: Invalid cargo bitnum %d for objects, skipping.", ctype);
4843 if (feature == GSF_STATIONS && ctype == 0xFE)
return CT_DEFAULT_NA;
4844 if (ctype == 0xFF)
return CT_PURCHASE;
4849 grfmsg(1,
"TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
4854 FOR_ALL_CARGOSPECS(cs) {
4855 if (cs->
bitnum == ctype) {
4856 grfmsg(6,
"TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, cs->
Index());
4861 grfmsg(5,
"TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
4874 grfmsg(5,
"TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype);
4880 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));
4884 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);
4889 static bool IsValidGroupID(uint16 groupid,
const char *
function)
4891 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] == NULL) {
4892 grfmsg(1,
"%s: Spritegroup 0x%04X out of range or empty, skipping.",
function, groupid);
4899 static void VehicleMapSpriteGroup(
ByteReader *buf, byte feature, uint8 idcount)
4902 static uint last_engines_count;
4903 bool wagover =
false;
4906 if (
HasBit(idcount, 7)) {
4909 idcount =
GB(idcount, 0, 7);
4911 if (last_engines_count == 0) {
4912 grfmsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
4916 grfmsg(6,
"VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
4917 last_engines_count, idcount);
4919 if (last_engines_count != idcount) {
4920 last_engines =
ReallocT(last_engines, idcount);
4921 last_engines_count = idcount;
4926 for (uint i = 0; i < idcount; i++) {
4932 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
4936 engines[i] = e->
index;
4937 if (!wagover) last_engines[i] = engines[i];
4940 uint8 cidcount = buf->ReadByte();
4941 for (uint c = 0; c < cidcount; c++) {
4942 uint8 ctype = buf->ReadByte();
4943 uint16 groupid = buf->ReadWord();
4944 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
4946 grfmsg(8,
"VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
4948 ctype = TranslateCargo(feature, ctype);
4951 for (uint i = 0; i < idcount; i++) {
4954 grfmsg(7,
"VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
4957 SetWagonOverrideSprites(engine, ctype, _cur.spritegroups[groupid], last_engines, last_engines_count);
4959 SetCustomEngineSprites(engine, ctype, _cur.spritegroups[groupid]);
4964 uint16 groupid = buf->ReadWord();
4965 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
4967 grfmsg(8,
"-- Default group id 0x%04X", groupid);
4969 for (uint i = 0; i < idcount; i++) {
4973 SetWagonOverrideSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid], last_engines, last_engines_count);
4975 SetCustomEngineSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid]);
4982 static void CanalMapSpriteGroup(
ByteReader *buf, uint8 idcount)
4985 for (uint i = 0; i < idcount; i++) {
4989 uint8 cidcount = buf->ReadByte();
4990 buf->Skip(cidcount * 3);
4992 uint16 groupid = buf->ReadWord();
4993 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
4995 for (uint i = 0; i < idcount; i++) {
4999 grfmsg(1,
"CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
5009 static void StationMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5011 uint8 *stations =
AllocaM(uint8, idcount);
5012 for (uint i = 0; i < idcount; i++) {
5013 stations[i] = buf->ReadByte();
5016 uint8 cidcount = buf->ReadByte();
5017 for (uint c = 0; c < cidcount; c++) {
5018 uint8 ctype = buf->ReadByte();
5019 uint16 groupid = buf->ReadWord();
5020 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5022 ctype = TranslateCargo(GSF_STATIONS, ctype);
5025 for (uint i = 0; i < idcount; i++) {
5028 if (statspec == NULL) {
5029 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5037 uint16 groupid = buf->ReadWord();
5038 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5040 for (uint i = 0; i < idcount; i++) {
5043 if (statspec == NULL) {
5044 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5049 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X mapped multiple times, skipping", stations[i]);
5056 StationClass::Assign(statspec);
5061 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5063 uint8 *houses =
AllocaM(uint8, idcount);
5064 for (uint i = 0; i < idcount; i++) {
5065 houses[i] = buf->ReadByte();
5069 uint8 cidcount = buf->ReadByte();
5070 buf->Skip(cidcount * 3);
5072 uint16 groupid = buf->ReadWord();
5073 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5075 if (_cur.
grffile->housespec == NULL) {
5076 grfmsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5080 for (uint i = 0; i < idcount; i++) {
5084 grfmsg(1,
"TownHouseMapSpriteGroup: House %d undefined, skipping.", houses[i]);
5092 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5094 uint8 *industries =
AllocaM(uint8, idcount);
5095 for (uint i = 0; i < idcount; i++) {
5096 industries[i] = buf->ReadByte();
5100 uint8 cidcount = buf->ReadByte();
5101 buf->Skip(cidcount * 3);
5103 uint16 groupid = buf->ReadWord();
5104 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5106 if (_cur.
grffile->industryspec == NULL) {
5107 grfmsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5111 for (uint i = 0; i < idcount; i++) {
5114 if (indsp == NULL) {
5115 grfmsg(1,
"IndustryMapSpriteGroup: Industry %d undefined, skipping", industries[i]);
5123 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5125 uint8 *indtiles =
AllocaM(uint8, idcount);
5126 for (uint i = 0; i < idcount; i++) {
5127 indtiles[i] = buf->ReadByte();
5131 uint8 cidcount = buf->ReadByte();
5132 buf->Skip(cidcount * 3);
5134 uint16 groupid = buf->ReadWord();
5135 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5137 if (_cur.
grffile->indtspec == NULL) {
5138 grfmsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5142 for (uint i = 0; i < idcount; i++) {
5145 if (indtsp == NULL) {
5146 grfmsg(1,
"IndustrytileMapSpriteGroup: Industry tile %d undefined, skipping", indtiles[i]);
5154 static void CargoMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5157 for (uint i = 0; i < idcount; i++) {
5158 cargoes[i] = buf->ReadByte();
5162 uint8 cidcount = buf->ReadByte();
5163 buf->Skip(cidcount * 3);
5165 uint16 groupid = buf->ReadWord();
5166 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5168 for (uint i = 0; i < idcount; i++) {
5172 grfmsg(1,
"CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid);
5178 cs->group = _cur.spritegroups[groupid];
5182 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5184 if (_cur.
grffile->objectspec == NULL) {
5185 grfmsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5189 uint8 *objects =
AllocaM(uint8, idcount);
5190 for (uint i = 0; i < idcount; i++) {
5191 objects[i] = buf->ReadByte();
5194 uint8 cidcount = buf->ReadByte();
5195 for (uint c = 0; c < cidcount; c++) {
5196 uint8 ctype = buf->ReadByte();
5197 uint16 groupid = buf->ReadWord();
5198 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5200 ctype = TranslateCargo(GSF_OBJECTS, ctype);
5203 for (uint i = 0; i < idcount; i++) {
5207 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
5215 uint16 groupid = buf->ReadWord();
5216 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5218 for (uint i = 0; i < idcount; i++) {
5222 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
5227 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X mapped multiple times, skipping", objects[i]);
5237 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5239 uint8 *railtypes =
AllocaM(uint8, idcount);
5240 for (uint i = 0; i < idcount; i++) {
5241 railtypes[i] = _cur.
grffile->railtype_map[buf->ReadByte()];
5244 uint8 cidcount = buf->ReadByte();
5245 for (uint c = 0; c < cidcount; c++) {
5246 uint8 ctype = buf->ReadByte();
5247 uint16 groupid = buf->ReadWord();
5248 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5250 if (ctype >= RTSG_END)
continue;
5253 for (uint i = 0; i < idcount; i++) {
5258 rti->
group[ctype] = _cur.spritegroups[groupid];
5267 static void AirportMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5269 uint8 *airports =
AllocaM(uint8, idcount);
5270 for (uint i = 0; i < idcount; i++) {
5271 airports[i] = buf->ReadByte();
5275 uint8 cidcount = buf->ReadByte();
5276 buf->Skip(cidcount * 3);
5278 uint16 groupid = buf->ReadWord();
5279 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
5281 if (_cur.
grffile->airportspec == NULL) {
5282 grfmsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
5286 for (uint i = 0; i < idcount; i++) {
5290 grfmsg(1,
"AirportMapSpriteGroup: Airport %d undefined, skipping", airports[i]);
5298 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5300 uint8 *airptiles =
AllocaM(uint8, idcount);
5301 for (uint i = 0; i < idcount; i++) {
5302 airptiles[i] = buf->ReadByte();
5306 uint8 cidcount = buf->ReadByte();
5307 buf->Skip(cidcount * 3);
5309 uint16 groupid = buf->ReadWord();
5310 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
5312 if (_cur.
grffile->airtspec == NULL) {
5313 grfmsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
5317 for (uint i = 0; i < idcount; i++) {
5320 if (airtsp == NULL) {
5321 grfmsg(1,
"AirportTileMapSpriteGroup: Airport tile %d undefined, skipping", airptiles[i]);
5331 static void FeatureMapSpriteGroup(
ByteReader *buf)
5347 uint8 feature = buf->ReadByte();
5348 uint8 idcount = buf->ReadByte();
5354 uint16 groupid = buf->ReadWord();
5355 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
5357 grfmsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature %d", feature);
5366 grfmsg(6,
"FeatureMapSpriteGroup: Feature %d, %d ids", feature, idcount);
5370 case GSF_ROADVEHICLES:
5373 VehicleMapSpriteGroup(buf, feature, idcount);
5377 CanalMapSpriteGroup(buf, idcount);
5381 StationMapSpriteGroup(buf, idcount);
5385 TownHouseMapSpriteGroup(buf, idcount);
5388 case GSF_INDUSTRIES:
5389 IndustryMapSpriteGroup(buf, idcount);
5392 case GSF_INDUSTRYTILES:
5393 IndustrytileMapSpriteGroup(buf, idcount);
5397 CargoMapSpriteGroup(buf, idcount);
5401 AirportMapSpriteGroup(buf, idcount);
5405 ObjectMapSpriteGroup(buf, idcount);
5409 RailTypeMapSpriteGroup(buf, idcount);
5412 case GSF_AIRPORTTILES:
5413 AirportTileMapSpriteGroup(buf, idcount);
5417 grfmsg(1,
"FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
5441 bool new_scheme = _cur.
grffile->grf_version >= 7;
5443 uint8 feature = buf->ReadByte();
5444 uint8 lang = buf->ReadByte();
5445 uint8 num = buf->ReadByte();
5446 bool generic =
HasBit(lang, 7);
5449 id = buf->ReadWord();
5450 }
else if (feature <= GSF_AIRCRAFT) {
5451 id = buf->ReadExtendedByte();
5453 id = buf->ReadByte();
5458 uint16 endid =
id + num;
5460 grfmsg(6,
"FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X",
5461 id, endid, feature, lang);
5463 for (;
id < endid && buf->HasData();
id++) {
5464 const char *name = buf->ReadString();
5465 grfmsg(8,
"FeatureNewName: 0x%04X <- %s",
id, name);
5469 case GSF_ROADVEHICLES:
5474 if (e == NULL)
break;
5488 switch (
GB(
id, 8, 8)) {
5490 if (_cur.
grffile->stations == NULL || _cur.
grffile->stations[
GB(
id, 0, 8)] == NULL) {
5491 grfmsg(1,
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring",
GB(
id, 0, 8));
5499 if (_cur.
grffile->stations == NULL || _cur.
grffile->stations[
GB(
id, 0, 8)] == NULL) {
5500 grfmsg(1,
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring",
GB(
id, 0, 8));
5507 if (_cur.
grffile->airtspec == NULL || _cur.
grffile->airtspec[
GB(
id, 0, 8)] == NULL) {
5508 grfmsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x%X, ignoring",
GB(
id, 0, 8));
5515 if (_cur.
grffile->housespec == NULL || _cur.
grffile->housespec[
GB(
id, 0, 8)] == NULL) {
5516 grfmsg(1,
"FeatureNewName: Attempt to name undefined house 0x%X, ignoring.",
GB(
id, 0, 8));
5523 grfmsg(7,
"FeatureNewName: Unsupported ID (0x%04X)",
id);
5542 if (offset >= max_sprites) {
5543 grfmsg(1,
"GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
5544 uint orig_num = num;
5549 if (offset + num > max_sprites) {
5550 grfmsg(4,
"GraphicsNew: %s sprite overflow, truncating...", name);
5551 uint orig_num = num;
5552 num =
max(max_sprites - offset, 0);
5553 return orig_num - num;
5582 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
5584 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
5615 uint8 type = buf->ReadByte();
5616 uint16 num = buf->ReadExtendedByte();
5617 uint16 offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
5623 grfmsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
5640 grfmsg(2,
"GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
5645 const Action5Type *action5_type = &_action5_types[type];
5651 grfmsg(1,
"GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
5658 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);
5668 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);
5670 for (; num > 0; num--) {
5743 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
5773 *value = _game_mode;
5807 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
5816 *value = _openttd_newgrf_version;
5831 default:
return false;
5835 static uint32 GetParamVal(byte param, uint32 *cond_val)
5853 if (cond_val == NULL) {
5872 grfmsg(1,
"Unsupported in-game variable 0x%02X", param);
5895 byte *preload_sprite = NULL;
5899 preload_sprite = MallocT<byte>(num);
5907 grfmsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
5908 free(preload_sprite);
5913 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
5914 if (it != _grf_line_to_action6_sprite_override.end()) {
5915 free(preload_sprite);
5916 preload_sprite = _grf_line_to_action6_sprite_override[location];
5918 _grf_line_to_action6_sprite_override[location] = preload_sprite;
5931 param_num = buf->ReadByte();
5932 if (param_num == 0xFF)
break;
5936 param_size = buf->ReadByte();
5940 add_value =
HasBit(param_size, 7);
5941 param_size =
GB(param_size, 0, 7);
5944 offset = buf->ReadExtendedByte();
5948 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
5949 grfmsg(2,
"CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
5953 grfmsg(8,
"CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
5956 for (i = 0; i < param_size && offset + i < num; i++) {
5957 uint32 value = GetParamVal(param_num + i / 4, NULL);
5960 if (i % 4 == 0) carry =
false;
5963 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
5964 preload_sprite[offset + i] =
GB(new_value, 0, 8);
5966 carry = new_value >= 256;
5968 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6001 uint32 cond_val = 0;
6005 uint8 param = buf->ReadByte();
6006 uint8 paramsize = buf->ReadByte();
6007 uint8 condtype = buf->ReadByte();
6014 switch (paramsize) {
6015 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6016 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6017 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6018 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6022 if (param < 0x80 && _cur.grffile->param_end <= param) {
6023 grfmsg(7,
"SkipIf: Param %d undefined, skipping test", param);
6027 uint32 param_val = GetParamVal(param, &cond_val);
6029 grfmsg(7,
"SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
6039 if (param == 0x88 && (condtype < 0x0B || condtype > 0x0E)) {
6049 if (condtype != 10 && c == NULL) {
6050 grfmsg(7,
"SkipIf: GRFID 0x%08X unknown, skipping test",
BSWAP32(cond_val));
6077 default:
grfmsg(1,
"SkipIf: Unsupported GRF condition type %02X. Ignoring", condtype);
return;
6082 case 0x00: result = !!(param_val & (1 << cond_val));
6084 case 0x01: result = !(param_val & (1 << cond_val));
6086 case 0x02: result = (param_val & mask) == cond_val;
6088 case 0x03: result = (param_val & mask) != cond_val;
6090 case 0x04: result = (param_val & mask) < cond_val;
6092 case 0x05: result = (param_val & mask) > cond_val;
6103 default:
grfmsg(1,
"SkipIf: Unsupported condition type %02X. Ignoring", condtype);
return;
6108 grfmsg(2,
"SkipIf: Not skipping sprites, test was false");
6112 uint8 numsprites = buf->ReadByte();
6120 if (label->label != numsprites)
continue;
6123 if (choice == NULL) choice = label;
6125 if (label->nfo_line > _cur.
nfo_line) {
6131 if (choice != NULL) {
6132 grfmsg(2,
"SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line);
6138 grfmsg(2,
"SkipIf: Skipping %d sprites, test was true", numsprites);
6157 uint8 grf_version = buf->ReadByte();
6158 uint32 grfid = buf->ReadDWord();
6159 const char *name = buf->ReadString();
6163 if (grf_version < 2 || grf_version > 8) {
6165 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);
6173 if (buf->HasData()) {
6174 const char *info = buf->ReadString();
6192 uint8 version = buf->ReadByte();
6193 uint32 grfid = buf->ReadDWord();
6194 const char *name = buf->ReadString();
6197 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
6201 if (_cur.
grffile->grfid != grfid) {
6202 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));
6206 _cur.
grffile->grf_version = version;
6224 uint8 num_sets = buf->ReadByte();
6226 for (uint i = 0; i < num_sets; i++) {
6227 uint8 num_sprites = buf->ReadByte();
6228 uint16 first_sprite = buf->ReadWord();
6230 grfmsg(2,
"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
6231 i, num_sprites, first_sprite
6234 for (uint j = 0; j < num_sprites; j++) {
6235 int load_index = first_sprite + j;
6241 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
6251 uint8 num_sets = buf->ReadByte();
6253 for (uint i = 0; i < num_sets; i++) {
6282 STR_NEWGRF_ERROR_VERSION_NUMBER,
6283 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
6284 STR_NEWGRF_ERROR_UNSET_SWITCH,
6285 STR_NEWGRF_ERROR_INVALID_PARAMETER,
6286 STR_NEWGRF_ERROR_LOAD_BEFORE,
6287 STR_NEWGRF_ERROR_LOAD_AFTER,
6288 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
6292 STR_NEWGRF_ERROR_MSG_INFO,
6293 STR_NEWGRF_ERROR_MSG_WARNING,
6294 STR_NEWGRF_ERROR_MSG_ERROR,
6295 STR_NEWGRF_ERROR_MSG_FATAL
6298 byte severity = buf->ReadByte();
6299 byte lang = buf->ReadByte();
6300 byte message_id = buf->ReadByte();
6303 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
6307 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
6308 grfmsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur.
stage);
6313 if (severity >=
lengthof(sevstr)) {
6314 grfmsg(7,
"GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity);
6316 }
else if (severity == 3) {
6326 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
6327 grfmsg(7,
"GRFLoadError: Invalid message id.");
6331 if (buf->Remaining() <= 1) {
6332 grfmsg(7,
"GRFLoadError: No message data supplied.");
6341 if (message_id == 0xFF) {
6343 if (buf->HasData()) {
6344 const char *message = buf->ReadString();
6348 grfmsg(7,
"GRFLoadError: No custom message supplied.");
6352 error->
message = msgstr[message_id];
6355 if (buf->HasData()) {
6356 const char *data = buf->ReadString();
6360 grfmsg(7,
"GRFLoadError: No message data supplied.");
6366 uint param_number = buf->ReadByte();
6380 if (!buf->HasData())
return;
6382 const char *text = buf->ReadString();
6383 grfmsg(2,
"GRFComment: %s", text);
6389 uint8 target = buf->ReadByte();
6392 if (target < 0x80 || target == 0x9E)
return;
6406 static uint32 GetPatchVariable(uint8 param)
6416 case 0x0F:
return 0;
6432 case 0x11:
return SPR_2CCMAP_BASE;
6449 byte max_edge =
max(log_X, log_Y);
6451 if (log_X == log_Y) {
6454 if (max_edge == log_Y)
SetBit(map_bits, 1);
6457 return (map_bits << 24) | (
min(log_X, log_Y) << 20) | (max_edge << 16) |
6458 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
6467 return SPR_SLOPES_BASE;
6474 grfmsg(2,
"ParamSet: Unknown Patch variable 0x%02X.", param);
6480 static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target,
const char *type)
6493 for (uint i = start; i < num_ids; i++) {
6497 if (op == 2 || op == 3)
break;
6502 if (size == count)
break;
6505 if (size == count) {
6507 if (op == 0 || op == 3) {
6508 grfmsg(2,
"ParamSet: GRM: Reserving %d %s at %d", count, type, start);
6509 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
6515 if (op != 4 && op != 5) {
6517 grfmsg(0,
"ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
6522 grfmsg(1,
"ParamSet: GRM: Unable to allocate %d %s", count, type);
6552 uint8 target = buf->ReadByte();
6553 uint8 oper = buf->ReadByte();
6554 uint32 src1 = buf->ReadByte();
6555 uint32 src2 = buf->ReadByte();
6558 if (buf->Remaining() >= 4) data = buf->ReadDWord();
6567 if (target < 0x80 && target < _cur.grffile->param_end) {
6568 grfmsg(7,
"ParamSet: Param %u already defined, skipping", target);
6572 oper =
GB(oper, 0, 7);
6576 if (
GB(data, 0, 8) == 0xFF) {
6577 if (data == 0x0000FFFF) {
6579 src1 = GetPatchVariable(src1);
6583 uint8 feature =
GB(data, 8, 8);
6584 uint16 count =
GB(data, 16, 16);
6586 if (_cur.
stage == GLS_RESERVE) {
6587 if (feature == 0x08) {
6591 if (_cur.
spriteid + count >= 16384) {
6592 grfmsg(0,
"ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
6598 grfmsg(4,
"ParamSet: GRM: Allocated %d sprites at %d", count, _cur.
spriteid);
6605 }
else if (_cur.
stage == GLS_ACTIVATION) {
6634 grfmsg(4,
"ParamSet: GRM: Using pre-allocated sprites at %d", src1);
6642 grfmsg(1,
"ParamSet: GRM: Unsupported operation %d for general sprites", op);
6653 default:
grfmsg(1,
"ParamSet: GRM: Unsupported feature 0x%X", feature);
return;
6670 }
else if (src1 == 0xFE) {
6682 src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
6683 src2 = (src2 == 0xFF) ? data : GetParamVal(src2, NULL);
6711 res = (int32)src1 * (int32)src2;
6715 if ((int32)src2 < 0) {
6716 res = src1 >> -(int32)src2;
6718 res = src1 << (src2 & 0x1F);
6723 if ((int32)src2 < 0) {
6724 res = (int32)src1 >> -(int32)src2;
6726 res = (int32)src1 << (src2 & 0x1F);
6750 res = (int32)src1 / (int32)src2;
6766 res = (int32)src1 % (int32)src2;
6770 default:
grfmsg(0,
"ParamSet: Unknown operation %d, skipping", oper);
return;
6799 grfmsg(7,
"ParamSet: Skipping unimplemented target 0x%02X", target);
6810 uint32 safe_bits = 0;
6811 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
6820 grfmsg(7,
"ParamSet: Skipping unimplemented target 0x%02X", target);
6824 if (target < 0x80) {
6825 _cur.
grffile->param[target] = res;
6829 grfmsg(7,
"ParamSet: Skipping unknown target 0x%02X", target);
6843 uint8 num = buf->ReadByte();
6845 for (uint i = 0; i < num; i++) {
6846 uint32 grfid = buf->ReadDWord();
6868 uint8 num = buf->ReadByte();
6870 for (uint i = 0; i < num; i++) {
6871 uint32 grfid = buf->ReadDWord();
6875 if (file != NULL && file != _cur.
grfconfig) {
6893 uint32 grfid = _cur.
grffile->grfid;
6897 byte
id = buf->ReadByte();
6898 grfmsg(6,
"FeatureTownName: definition 0x%02X",
id & 0x7F);
6903 bool new_scheme = _cur.
grffile->grf_version >= 7;
6905 byte lang = buf->ReadByte();
6907 byte nb_gen = townname->nb_gen;
6911 const char *name = buf->ReadString();
6914 grfmsg(6,
"FeatureTownName: lang 0x%X -> '%s'", lang, lang_name);
6917 townname->name[nb_gen] =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
6919 lang = buf->ReadByte();
6920 }
while (lang != 0);
6921 townname->id[nb_gen] = id;
6925 byte nb = buf->ReadByte();
6926 grfmsg(6,
"FeatureTownName: %u parts", nb);
6928 townname->nbparts[id] = nb;
6929 townname->partlist[id] = CallocT<NamePartList>(nb);
6931 for (
int i = 0; i < nb; i++) {
6932 byte nbtext = buf->ReadByte();
6933 townname->partlist[id][i].bitstart = buf->ReadByte();
6934 townname->partlist[id][i].bitcount = buf->ReadByte();
6935 townname->partlist[id][i].maxprob = 0;
6936 townname->partlist[id][i].partcount = nbtext;
6937 townname->partlist[id][i].parts = CallocT<NamePart>(nbtext);
6938 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);
6940 for (
int j = 0; j < nbtext; j++) {
6941 byte prob = buf->ReadByte();
6944 byte ref_id = buf->ReadByte();
6946 if (townname->nbparts[ref_id] == 0) {
6947 grfmsg(0,
"FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
6948 DelGRFTownName(grfid);
6953 grfmsg(6,
"FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
6954 townname->partlist[id][i].parts[j].data.
id = ref_id;
6956 const char *text = buf->ReadString();
6958 grfmsg(6,
"FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[
id][i].parts[j].data.
text, prob);
6960 townname->partlist[id][i].parts[j].
prob = prob;
6961 townname->partlist[id][i].maxprob +=
GB(prob, 0, 7);
6963 grfmsg(6,
"FeatureTownName: part %d, total probability %d", i, townname->partlist[
id][i].maxprob);
6975 byte nfo_label = buf->ReadByte();
6977 GRFLabel *label = MallocT<GRFLabel>(1);
6978 label->label = nfo_label;
6989 for (l = _cur.
grffile->
label; l->next != NULL; l = l->next) {}
6993 grfmsg(2,
"DefineGotoLabel: GOTO target with label 0x%02X", label->label);
7007 if (file == NULL || file->sound_offset == 0) {
7008 grfmsg(1,
"ImportGRFSound: Source file not available");
7012 if (sound_id >= file->num_sounds) {
7013 grfmsg(1,
"ImportGRFSound: Sound effect %d is invalid", sound_id);
7017 grfmsg(2,
"ImportGRFSound: Copying sound %d (%d) from file %X", sound_id, file->sound_offset + sound_id, grfid);
7019 *sound = *GetSound(file->sound_offset + sound_id);
7022 sound->volume = 128;
7023 sound->priority = 0;
7034 sound->volume = 0x80;
7035 sound->priority = 0;
7037 if (offs != SIZE_MAX) {
7040 sound->file_offset = offs;
7052 uint16 num = buf->ReadWord();
7053 if (num == 0)
return;
7056 if (_cur.
grffile->sound_offset == 0) {
7057 _cur.
grffile->sound_offset = GetNumSounds();
7058 _cur.
grffile->num_sounds = num;
7061 sound = GetSound(_cur.
grffile->sound_offset);
7064 for (
int i = 0; i < num; i++) {
7069 bool invalid = i >= _cur.
grffile->num_sounds;
7079 grfmsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7081 }
else if (len != 4) {
7082 grfmsg(1,
"GRFSound: Invalid sprite section import");
7092 grfmsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7099 grfmsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7107 if (_cur.
stage == GLS_INIT) {
7109 grfmsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7118 if (_cur.
stage == GLS_ACTIVATION) {
7129 grfmsg(1,
"GRFSound: Unexpected Action %x found, skipping", action);
7158 uint8 num_def = buf->ReadByte();
7160 for (uint i = 0; i < num_def; i++) {
7162 uint8 num_char = buf->ReadByte();
7163 uint16 base_char = buf->ReadWord();
7165 if (size >= FS_END) {
7166 grfmsg(1,
"LoadFontGlyph: Size %u is not supported, ignoring", size);
7169 grfmsg(7,
"LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
7171 for (uint c = 0; c < num_char; c++) {
7189 uint8 num_def = buf->ReadByte();
7191 for (uint i = 0; i < num_def; i++) {
7215 uint32 grfid = buf->ReadDWord();
7218 grfmsg(7,
"TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13",
BSWAP32(grfid));
7228 GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE,
lastof(tmp));
7239 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
7240 byte num_strings = buf->ReadByte();
7241 uint16 first_id = buf->ReadWord();
7243 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
7244 grfmsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
7248 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
7249 const char *
string = buf->ReadString();
7252 grfmsg(7,
"TranslateGRFString: Ignoring empty string.");
7256 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
7285 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE
", ignoring this field", len);
7297 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got " PRINTF_SIZE
", ignoring this field", len);
7300 char data = buf->ReadByte();
7308 grfmsg(2,
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data);
7323 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got " PRINTF_SIZE
", ignoring this field", len);
7326 char data = buf->ReadByte();
7332 grfmsg(2,
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'BLTR', ignoring this field", data);
7345 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got " PRINTF_SIZE
", ignoring this field", len);
7358 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got " PRINTF_SIZE
", ignoring this field", len);
7363 grfmsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
7394 grfmsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got " PRINTF_SIZE
", ignoring this field", len);
7399 _cur_parameter->
type = type;
7401 grfmsg(3,
"StaticGRFInfo: unknown parameter type %d, ignoring this field", type);
7411 grfmsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
7413 }
else if (len != 8) {
7414 grfmsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got " PRINTF_SIZE
", ignoring this field", len);
7417 _cur_parameter->
min_value = buf->ReadDWord();
7418 _cur_parameter->
max_value = buf->ReadDWord();
7426 if (len < 1 || len > 3) {
7427 grfmsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got " PRINTF_SIZE
", ignoring this field", len);
7430 byte param_nr = buf->ReadByte();
7432 grfmsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param %d, ignoring this field", param_nr);
7435 _cur_parameter->
param_nr = param_nr;
7436 if (len >= 2) _cur_parameter->
first_bit =
min(buf->ReadByte(), 31);
7437 if (len >= 3) _cur_parameter->
num_bit =
min(buf->ReadByte(), 32 - _cur_parameter->
first_bit);
7448 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got " PRINTF_SIZE
", ignoring this field", len);
7451 _cur_parameter->
def_value = buf->ReadDWord();
7484 this->handler.data = handler;
7496 this->handler.text = handler;
7508 this->handler.call_handler =
true;
7509 this->handler.u.branch = handler;
7521 this->handler.call_handler =
false;
7522 this->handler.u.subtags =
subtags;
7551 byte type = buf->ReadByte();
7553 uint32
id = buf->ReadDWord();
7554 if (type !=
'T' ||
id > _cur_parameter->
max_value) {
7555 grfmsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
7557 type = buf->ReadByte();
7561 byte langid = buf->ReadByte();
7562 const char *name_string = buf->ReadString();
7573 type = buf->ReadByte();
7598 byte type = buf->ReadByte();
7600 uint32
id = buf->ReadDWord();
7602 grfmsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
7604 type = buf->ReadByte();
7611 MemSetT<GRFParameterInfo *>(newdata, 0, num_to_add);
7618 if (!
HandleNodes(buf, _tags_parameters))
return false;
7619 type = buf->ReadByte();
7656 byte new_type = buf->ReadByte();
7657 while (new_type != 0) {
7660 new_type = buf->ReadByte();
7671 uint16 size = buf->ReadWord();
7695 while ((tag = &subtags[i++])->type != 0) {
7698 default: NOT_REACHED();
7701 byte langid = buf->ReadByte();
7702 return tag->handler.
text(langid, buf->ReadString());
7706 size_t len = buf->ReadWord();
7707 if (buf->Remaining() < len)
return false;
7708 return tag->handler.
data(len, buf);
7713 return tag->handler.u.branch(buf);
7719 grfmsg(2,
"StaticGRFInfo: unknown type/id combination found, type=%c, id=%x", type,
id);
7731 byte type = buf->ReadByte();
7733 uint32
id = buf->ReadDWord();
7734 if (!
HandleNode(type,
id, buf, subtags))
return false;
7735 type = buf->ReadByte();
7852 const GRFFile *
const *end = _grf_files.
End();
7853 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7855 if (stations == NULL)
continue;
7857 if (stations[i] == NULL)
continue;
7863 if (!statspec->copied_layouts) {
7864 for (uint l = 0; l < statspec->lengths; l++) {
7865 for (uint p = 0; p < statspec->platforms[l]; p++) {
7866 free(statspec->layouts[l][p]);
7868 free(statspec->layouts[l]);
7870 free(statspec->layouts);
7871 free(statspec->platforms);
7887 const GRFFile *
const *end = _grf_files.
End();
7888 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7889 HouseSpec **&housespec = (*file)->housespec;
7890 if (housespec == NULL)
continue;
7903 const GRFFile *
const *end = _grf_files.
End();
7904 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7906 if (aslist != NULL) {
7912 for (
int j = 0; j < as->
num_table; j++) {
7924 (*file)->airportspec = NULL;
7928 if (airporttilespec != NULL) {
7930 free(airporttilespec[i]);
7932 free(airporttilespec);
7933 airporttilespec = NULL;
7941 const GRFFile *
const *end = _grf_files.
End();
7942 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7948 if (industryspec != NULL) {
7951 if (ind == NULL)
continue;
7965 industryspec = NULL;
7968 if (indtspec == NULL)
continue;
7981 const GRFFile *
const *end = _grf_files.
End();
7982 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
7983 ObjectSpec **&objectspec = (*file)->objectspec;
7984 if (objectspec == NULL)
continue;
7986 free(objectspec[i]);
7997 const GRFFile *
const *end = _grf_files.
End();
7998 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8024 CleanUpGRFTownNames();
8066 ObjectClass::Reset();
8071 StationClass::Reset();
8075 AirportClass::Reset();
8098 _loaded_newgrf_features.
has_2CC =
false;
8105 _grf_id_overrides.clear();
8107 InitializeSoundPool();
8155 if (newfile != NULL) {
8161 newfile =
new GRFFile(config);
8179 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8203 free(this->filename);
8213 'PASS',
'COAL',
'MAIL',
'LVST',
'GOOD',
'GRAI',
'WHEA',
'MAIZ',
'WOOD',
8214 'IORE',
'STEL',
'VALU',
'GOLD',
'DIAM',
'PAPR',
'FOOD',
'FRUT',
'CORE',
8215 'WATR',
'SUGR',
'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
8219 static const CargoLabel _default_refitmasks_road[] = {
8222 static const CargoLabel _default_refitmasks_ships[] = {
8223 'COAL',
'MAIL',
'LVST',
'GOOD',
'GRAI',
'WHEA',
'MAIZ',
'WOOD',
'IORE',
8224 'STEL',
'VALU',
'GOLD',
'DIAM',
'PAPR',
'FOOD',
'FRUT',
'CORE',
'WATR',
8225 'RUBR',
'SUGR',
'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
8229 static const CargoLabel _default_refitmasks_aircraft[] = {
8230 'PASS',
'MAIL',
'GOOD',
'VALU',
'GOLD',
'DIAM',
'FOOD',
'FRUT',
'SUGR',
8231 'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
'PLST',
'FZDR',
8234 static const CargoLabel *
const _default_refitmasks[] = {
8236 _default_refitmasks_road,
8237 _default_refitmasks_ships,
8238 _default_refitmasks_aircraft,
8249 FOR_ALL_ENGINES(e) {
8252 bool only_defaultcargo;
8257 uint32 not_mask = 0;
8258 uint32 xor_mask = ei->refit_mask;
8264 if (_gted[engine].cargo_allowed != 0) {
8267 FOR_ALL_CARGOSPECS(cs) {
8273 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
8279 uint32 xor_mask = 0;
8284 for (uint i = 0;; i++) {
8285 if (cl[i] == 0)
break;
8297 only_defaultcargo = (ei->refit_mask == 0);
8311 if (ei->cargo_type ==
CT_INVALID && ei->refit_mask != 0) {
8313 const uint8 *cargo_map_for_first_refittable = NULL;
8316 if (file == NULL) file = e->
GetGRF();
8317 if (file != NULL && file->grf_version >= 8 && file->
cargo_list.
Length() != 0) {
8318 cargo_map_for_first_refittable = file->
cargo_map;
8322 if (cargo_map_for_first_refittable != NULL) {
8324 byte best_local_slot = 0xFF;
8326 FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) {
8327 byte local_slot = cargo_map_for_first_refittable[cargo_type];
8328 if (local_slot < best_local_slot) {
8329 best_local_slot = local_slot;
8330 ei->cargo_type = cargo_type;
8352 for (uint i = 0; i < CF_END; i++) {
8365 FOR_ALL_ENGINES(e) {
8366 if (e->
GetGRF() == NULL) {
8369 e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
8402 default: NOT_REACHED();
8416 cs->
quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
8417 cs->
abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
8441 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);
8451 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);
8459 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);
8466 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);
8485 if (hs == NULL || !hs->
enabled)
continue;
8490 if (min_year == 0)
return;
8494 if (hs == NULL || !hs->
enabled)
continue;
8517 const GRFFile *
const *end = _grf_files.
End();
8518 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8519 HouseSpec **&housespec = (*file)->housespec;
8520 if (housespec == NULL)
continue;
8525 if (hs == NULL)
continue;
8527 const HouseSpec *next1 = (i + 1 < NUM_HOUSES_PER_GRF ? housespec[i + 1] : NULL);
8528 const HouseSpec *next2 = (i + 2 < NUM_HOUSES_PER_GRF ? housespec[i + 2] : NULL);
8529 const HouseSpec *next3 = (i + 3 < NUM_HOUSES_PER_GRF ? housespec[i + 3] : NULL);
8531 if (!
IsHouseSpecValid(hs, next1, next2, next3, (*file)->filename))
continue;
8539 const HouseSpec *next1 = (i + 1 < NUM_HOUSES ? HouseSpec::Get(i + 1) : NULL);
8540 const HouseSpec *next2 = (i + 2 < NUM_HOUSES ? HouseSpec::Get(i + 2) : NULL);
8541 const HouseSpec *next3 = (i + 3 < NUM_HOUSES ? HouseSpec::Get(i + 3) : NULL);
8580 const GRFFile *
const *end = _grf_files.
End();
8581 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8584 if (industryspec != NULL) {
8588 if (indsp != NULL && indsp->
enabled) {
8594 if (strid != STR_UNDEFINED) indsp->
name = strid;
8597 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
8612 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
8621 if (indtspec != NULL) {
8624 if (indtsp != NULL) {
8625 _industile_mngr.SetEntitySpec(indtsp);
8634 for (uint i = 0; i < 3; i++) {
8639 indsp->
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
8651 const GRFFile *
const *end = _grf_files.
End();
8652 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8653 ObjectSpec **&objectspec = (*file)->objectspec;
8654 if (objectspec != NULL) {
8656 if (objectspec[i] != NULL && objectspec[i]->grf_prop.grffile != NULL && objectspec[i]->
enabled) {
8671 const GRFFile *
const *end = _grf_files.
End();
8672 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
8673 AirportSpec **&airportspec = (*file)->airportspec;
8674 if (airportspec != NULL) {
8676 if (airportspec[i] != NULL && airportspec[i]->enabled) {
8677 _airport_mngr.SetEntitySpec(airportspec[i]);
8683 if (airporttilespec != NULL) {
8685 if (airporttilespec[i] != NULL && airporttilespec[i]->enabled) {
8686 _airporttile_mngr.SetEntitySpec(airporttilespec[i]);
8699 static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
8713 static const SpecialSpriteHandler handlers[][GLS_END] = {
8714 { NULL, SafeChangeInfo, NULL, NULL, ReserveChangeInfo, FeatureChangeInfo, },
8715 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
8716 { NULL, NULL, NULL, NULL, NULL, NewSpriteGroup, },
8717 { NULL,
GRFUnsafe, NULL, NULL, NULL, FeatureMapSpriteGroup, },
8718 { NULL, NULL, NULL, NULL, NULL, FeatureNewName, },
8719 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
8720 { NULL, NULL, NULL, CfgApply, CfgApply, CfgApply, },
8721 { NULL, NULL, NULL, NULL, SkipIf, SkipIf, },
8722 { ScanInfo, NULL, NULL, GRFInfo, GRFInfo, GRFInfo, },
8723 { NULL, NULL, NULL, SkipIf, SkipIf, SkipIf, },
8724 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
8725 { NULL, NULL, NULL, GRFLoadError, GRFLoadError, GRFLoadError, },
8726 { NULL, NULL, NULL, GRFComment, NULL, GRFComment, },
8728 { NULL, SafeGRFInhibit, NULL, GRFInhibit, GRFInhibit, GRFInhibit, },
8731 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
8739 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
8740 if (it == _grf_line_to_action6_sprite_override.end()) {
8746 buf = _grf_line_to_action6_sprite_override[location];
8747 grfmsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
8757 byte action = bufp->ReadByte();
8759 if (action == 0xFF) {
8760 grfmsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
8761 }
else if (action == 0xFE) {
8762 grfmsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
8763 }
else if (action >=
lengthof(handlers)) {
8764 grfmsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x%02X", action);
8765 }
else if (handlers[action][stage] == NULL) {
8766 grfmsg(7,
"DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage);
8768 grfmsg(7,
"DecodeSpecialSprite: Handling action 0x%02X in stage %d", action, stage);
8769 handlers[action][stage](bufp);
8772 grfmsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
8779 extern const byte
_grf_cont_v2_sig[8] = {
'G',
'R',
'F', 0x82, 0x0D, 0x0A, 0x1A, 0x0A};
8792 for (uint i = 0; i <
lengthof(_grf_cont_v2_sig); i++) {
8793 if (
FioReadByte() != _grf_cont_v2_sig[i])
return 0;
8813 const char *filename = config->
filename;
8824 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
8826 if (_cur.
grffile == NULL)
usererror(
"File '%s' lost in cache.\n", filename);
8832 DEBUG(grf, 0,
"'%s' is not loaded as the maximum number of file slots has been reached", filename);
8834 config->
error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
8844 DEBUG(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
8848 DEBUG(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
8852 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
8864 if (compression != 0) {
8865 DEBUG(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
8877 DEBUG(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
8891 DecodeSpecialSprite(buf.
Allocate(num), num, stage);
8902 grfmsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
8903 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
8968 static const uint32 override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
8971 int num_grfs = _grf_files.
Length();
8972 int *grf_overrides =
AllocaM(
int, num_grfs);
8973 for (
int i = 0; i < num_grfs; i++) {
8974 grf_overrides[i] = -1;
8976 GRFFile *source = _grf_files[i];
8977 uint32
override = _grf_id_overrides[source->grfid];
8978 if (
override == 0)
continue;
8981 if (dest == NULL)
continue;
8983 grf_overrides[i] = _grf_files.
FindIndex(dest);
8984 assert(grf_overrides[i] >= 0);
8988 for (
int i = 0; i < num_grfs; i++) {
8989 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
8990 GRFFile *source = _grf_files[i];
8991 GRFFile *dest = _grf_files[grf_overrides[i]];
8997 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9000 DEBUG(grf, 3,
"'%s' overrides price base multiplier %d of '%s'", source->filename, p, dest->filename);
9006 for (
int i = num_grfs - 1; i >= 0; i--) {
9007 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9008 GRFFile *source = _grf_files[i];
9009 GRFFile *dest = _grf_files[grf_overrides[i]];
9015 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9018 DEBUG(grf, 3,
"Price base multiplier %d from '%s' propagated to '%s'", p, source->filename, dest->filename);
9024 for (
int i = 0; i < num_grfs; i++) {
9025 if (grf_overrides[i] < 0)
continue;
9026 GRFFile *source = _grf_files[i];
9027 GRFFile *dest = _grf_files[grf_overrides[i]];
9033 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9034 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9036 DEBUG(grf, 3,
"Price base multiplier %d from '%s' propagated to '%s'", p, dest->filename, source->filename);
9043 const GRFFile *
const *end = _grf_files.
End();
9044 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
9045 if ((*file)->grf_version >= 8)
continue;
9046 PriceMultipliers &price_base_multipliers = (*file)->price_base_multipliers;
9047 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9049 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9052 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9058 for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
9059 PriceMultipliers &price_base_multipliers = (*file)->price_base_multipliers;
9060 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9061 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9063 price_base_multipliers[p] = 0;
9068 DEBUG(grf, 3,
"'%s' sets global price base multiplier %d", (*file)->filename, p);
9070 price_base_multipliers[p] = 0;
9072 DEBUG(grf, 3,
"'%s' sets local price base multiplier %d", (*file)->filename, p);
9087 _string_to_grf_mapping.
Clear();
9090 for (GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.begin(); it != _grf_line_to_action6_sprite_override.end(); it++) {
9093 _grf_line_to_action6_sprite_override.clear();
9144 FOR_ALL_ENGINES_OF_TYPE(e,
VEH_ROAD) {
9157 e->u.rail.railtype = railtype;
9167 _grm_sprites.clear();
9176 void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
9216 for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
9223 if (stage == GLS_RESERVE) {
9224 static const uint32 overrides[][2] = {
9225 { 0x44442202, 0x44440111 },
9226 { 0x6D620402, 0x6D620401 },
9227 { 0x4D656f20, 0x4D656F17 },
9229 for (
size_t i = 0; i <
lengthof(overrides); i++) {
9234 uint slot = file_index;
9235 uint num_non_static = 0;
9244 DEBUG(grf, 0,
"NewGRF file is missing '%s'; disabling", c->
filename);
9253 DEBUG(grf, 0,
"'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->
filename);
9255 c->
error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
9261 if (stage == GLS_RESERVE) {
9263 }
else if (stage == GLS_ACTIVATION) {
9268 DEBUG(sprite, 2,
"LoadNewGRF: Currently %i sprites are loaded", _cur.
spriteid);