52 #include "table/strings.h" 69 const std::vector<GRFFile *> &GetAllGRFFiles()
119 this->skip_sprites = 0;
121 for (uint i = 0; i < GSF_END; i++) {
122 this->spritesets[i].clear();
125 memset(this->spritegroups, 0,
sizeof(this->spritegroups));
138 assert(feature < GSF_END);
139 for (uint i = 0; i < numsets; i++) {
140 SpriteSet &
set = this->spritesets[feature][first_set + i];
141 set.
sprite = first_sprite + i * numents;
142 set.num_sprites = numents;
154 assert(feature < GSF_END);
155 return !this->spritesets[feature].empty();
167 assert(feature < GSF_END);
168 return this->spritesets[feature].find(
set) != this->spritesets[feature].end();
180 return this->spritesets[feature].find(
set)->second.sprite;
192 return this->spritesets[feature].find(
set)->second.num_sprites;
205 template <VehicleType T>
208 return image_index == 0xFD || IsValidImageIndex<T>(image_index);
220 ByteReader(byte *data, byte *end) : data(data), end(end) { }
224 if (data < end)
return *(data)++;
234 uint16 ReadExtendedByte()
237 return val == 0xFF ? ReadWord() : val;
242 uint32 val = ReadWord();
243 return val | (ReadWord() << 16);
246 uint32 ReadVarSize(byte size)
250 case 2:
return ReadWord();
251 case 4:
return ReadDWord();
258 const char *ReadString()
260 char *
string =
reinterpret_cast<char *
>(data);
261 size_t string_length =
ttd_strnlen(
string, Remaining());
263 if (string_length == Remaining()) {
265 string[string_length - 1] =
'\0';
266 grfmsg(7,
"String was not terminated with a zero byte.");
276 inline size_t Remaining()
const 281 inline bool HasData(
size_t count = 1)
const 283 return data + count <= end;
291 inline void Skip(
size_t len)
300 typedef void (*SpecialSpriteHandler)(
ByteReader *buf);
313 uint16 cargo_allowed;
314 uint16 cargo_disallowed;
315 RailTypeLabel railtypelabel;
331 this->refittability = NONEMPTY;
332 }
else if (this->refittability == UNSET) {
333 this->refittability = EMPTY;
353 GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { }
357 return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
362 return this->grfid == other.grfid && this->nfoline == other.nfoline;
366 static std::map<GRFLocation, SpriteID> _grm_sprites;
367 typedef std::map<GRFLocation, byte*> GRFLineToSpriteOverride;
368 static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
380 void CDECL
grfmsg(
int severity,
const char *str, ...)
400 if (file->grfid == grfid)
return file;
413 if (strcmp(file->filename, filename) == 0)
return file;
439 if (config !=
nullptr) {
450 if (message != STR_NULL) {
451 delete config->error;
452 config->error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, message);
456 return config->error;
467 typedef std::vector<StringIDMapping> StringIDMappingVector;
468 static StringIDMappingVector _string_to_grf_mapping;
477 *target = STR_UNDEFINED;
478 _string_to_grf_mapping.push_back({_cur.
grffile->grfid, source, target});
491 static const StringID units_volume[] = {
492 STR_ITEMS, STR_PASSENGERS, STR_TONS, STR_BAGS,
493 STR_LITERS, STR_ITEMS, STR_CRATES, STR_TONS,
494 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
495 STR_TONS, STR_TONS, STR_TONS, STR_BAGS,
496 STR_TONS, STR_TONS, STR_BAGS, STR_LITERS,
497 STR_TONS, STR_LITERS, STR_TONS, STR_ITEMS,
498 STR_BAGS, STR_LITERS, STR_TONS, STR_ITEMS,
499 STR_TONS, STR_ITEMS, STR_LITERS, STR_ITEMS
505 #define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \ 506 assert_compile(stringend - stringid == end - begin); \ 507 if (str >= begin && str <= end) return str + (stringid - begin) 510 TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING, STR_CARGO_PLURAL_FIZZY_DRINKS);
511 TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING, STR_CARGO_SINGULAR_FIZZY_DRINK);
512 if (str >= 0x004E && str <= 0x006D)
return units_volume[str - 0x004E];
513 TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING, STR_QUANTITY_FIZZY_DRINKS);
514 TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING, STR_ABBREV_FIZZY_DRINKS);
515 TEXTID_TO_STRINGID(0x00D1, 0x00E0, STR_COLOUR_DARK_BLUE, STR_COLOUR_WHITE);
520 TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1, STR_TOWN_BUILDING_NAME_OLD_HOUSES_1);
521 TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1, STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1);
522 TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1, STR_TOWN_BUILDING_NAME_PIGGY_BANK_1);
525 TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE, STR_INDUSTRY_NAME_SUGAR_MINE);
526 TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION, STR_NEWS_INDUSTRY_PLANTED);
527 TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL, STR_NEWS_INDUSTRY_CLOSURE_LACK_OF_TREES);
528 TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_FARM);
529 TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_FARM);
532 case 0x4830:
return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
533 case 0x4831:
return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
534 case 0x483B:
return STR_ERROR_CAN_ONLY_BE_POSITIONED;
536 #undef TEXTID_TO_STRINGID 538 if (str == STR_NULL)
return STR_EMPTY;
540 DEBUG(grf, 0,
"Unknown StringID 0x%04X remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
579 static std::map<uint32, uint32> _grf_id_overrides;
588 _grf_id_overrides[source_grfid] = target_grfid;
589 grfmsg(5,
"SetNewGRFOverride: Added override of 0x%X to 0x%X",
BSWAP32(source_grfid),
BSWAP32(target_grfid));
604 uint32 scope_grfid = INVALID_GRFID;
607 scope_grfid = file->grfid;
608 uint32
override = _grf_id_overrides[file->grfid];
610 scope_grfid =
override;
612 if (grf_match ==
nullptr) {
613 grfmsg(5,
"Tried mapping from GRFID %x to %x but target is not loaded",
BSWAP32(file->grfid),
BSWAP32(
override));
620 EngineID engine = _engine_mngr.
GetID(type, internal_id, scope_grfid);
629 EngineID engine = _engine_mngr.
GetID(type, internal_id, INVALID_GRFID);
635 grfmsg(5,
"Replaced engine at index %d for GRFID %x, type %d, index %d", e->
index,
BSWAP32(file->grfid), type, internal_id);
639 if (!static_access) {
641 eid->
grfid = scope_grfid;
647 if (static_access)
return nullptr;
650 grfmsg(0,
"Can't allocate any more engines");
661 assert(_engine_mngr.size() == e->
index);
662 _engine_mngr.push_back({
675 memset(_gted + engine_pool_size, 0, len);
681 grfmsg(5,
"Created new engine at index %d for GRFID %x, type %d, index %d", e->
index,
BSWAP32(file->grfid), type, internal_id);
698 uint32 scope_grfid = INVALID_GRFID;
700 scope_grfid = file->grfid;
701 uint32
override = _grf_id_overrides[file->grfid];
702 if (
override != 0) scope_grfid =
override;
705 return _engine_mngr.
GetID(type, internal_id, scope_grfid);
745 grf_sprite->
sprite = buf->ReadWord();
746 grf_sprite->
pal = buf->ReadWord();
751 bool custom_sprite =
HasBit(grf_sprite->
pal, 15) != invert_action1_flag;
755 uint index =
GB(grf_sprite->
sprite, 0, 14);
757 grfmsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d", index);
758 grf_sprite->
sprite = SPR_IMG_QUERY;
759 grf_sprite->
pal = PAL_NONE;
762 if (max_sprite_offset !=
nullptr) *max_sprite_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
767 grfmsg(1,
"ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite");
768 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
774 uint index =
GB(grf_sprite->
pal, 0, 14);
776 grfmsg(1,
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d for 'palette'", index);
777 grf_sprite->
pal = PAL_NONE;
780 if (max_palette_offset !=
nullptr) *max_palette_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
785 grfmsg(1,
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette");
786 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
815 regs.delta.
parent[0] = buf->ReadByte();
816 regs.delta.
parent[1] = buf->ReadByte();
828 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
837 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
856 bool has_flags =
HasBit(num_building_sprites, 6);
857 ClrBit(num_building_sprites, 6);
860 dts->
Allocate(num_building_sprites);
862 uint16 *max_sprite_offset =
AllocaM(uint16, num_building_sprites + 1);
863 uint16 *max_palette_offset =
AllocaM(uint16, num_building_sprites + 1);
864 MemSetT(max_sprite_offset, 0, num_building_sprites + 1);
865 MemSetT(max_palette_offset, 0, num_building_sprites + 1);
872 grfmsg(1,
"ReadSpriteLayout: Spritelayout uses invalid flag 0x%x for ground sprite", flags & ~(valid_flags & ~
TLF_NON_GROUND_FLAGS));
873 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
880 for (uint i = 0; i < num_building_sprites; i++) {
883 flags =
ReadSpriteLayoutSprite(buf, has_flags,
false, use_cur_spritesets, feature, &seq->image, max_sprite_offset + i + 1, max_palette_offset + i + 1);
886 if (flags & ~valid_flags) {
887 grfmsg(1,
"ReadSpriteLayout: Spritelayout uses unknown flag 0x%x", flags & ~valid_flags);
888 DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
892 seq->
delta_x = buf->ReadByte();
893 seq->delta_y = buf->ReadByte();
895 if (!no_z_position) seq->
delta_z = buf->ReadByte();
898 seq->size_x = buf->ReadByte();
899 seq->size_y = buf->ReadByte();
900 seq->size_z = buf->ReadByte();
908 bool is_consistent =
true;
910 for (uint i = 0; i < num_building_sprites + 1; i++) {
911 if (max_sprite_offset[i] > 0) {
915 is_consistent =
false;
919 if (max_palette_offset[i] > 0) {
923 is_consistent =
false;
932 if (!is_consistent || dts->registers !=
nullptr) {
936 for (uint i = 0; i < num_building_sprites + 1; i++) {
951 CargoTypes result = 0;
970 if (base_pointer == 0) {
971 *index = INVALID_PRICE;
975 static const uint32 start = 0x4B34;
976 static const uint32 size = 6;
978 if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) {
979 grfmsg(1,
"%s: Unsupported running cost base 0x%04X, ignoring", error_location, base_pointer);
983 *index = (
Price)((base_pointer - start) / size);
1012 ei->decay_speed = buf->ReadByte();
1029 ei->load_amount = buf->ReadByte();
1051 for (
int i = 0; i < numinfo; i++) {
1060 uint8 tracktype = buf->ReadByte();
1062 if (tracktype < _cur.grffile->railtype_list.size()) {
1067 switch (tracktype) {
1068 case 0: _gted[e->
index].railtypelabel = rvi->
engclass >= 2 ? RAILTYPE_ELECTRIC_LABEL : RAILTYPE_RAIL_LABEL;
break;
1069 case 1: _gted[e->
index].railtypelabel = RAILTYPE_MONO_LABEL;
break;
1070 case 2: _gted[e->
index].railtypelabel = RAILTYPE_MAGLEV_LABEL;
break;
1072 grfmsg(1,
"RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype);
1085 uint16 speed = buf->ReadWord();
1086 if (speed == 0xFFFF) speed = 0;
1093 rvi->
power = buf->ReadWord();
1096 if (rvi->
power != 0) {
1119 if (spriteid < 0xFD) spriteid >>= 1;
1121 if (IsValidNewGRFImageIndex<VEH_TRAIN>(spriteid)) {
1124 grfmsg(1,
"RailVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1125 rvi->image_index = 0;
1131 uint8 dual = buf->ReadByte();
1136 rvi->railveh_type = rvi->
power == 0 ?
1148 uint8 ctype = buf->ReadByte();
1150 if (ctype == 0xFF) {
1153 }
else if (_cur.
grffile->grf_version >= 8) {
1158 ei->cargo_type = ctype;
1161 grfmsg(2,
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
1167 SB(rvi->
weight, 0, 8, buf->ReadByte());
1175 grfmsg(2,
"RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored.");
1187 uint8 traction = buf->ReadByte();
1190 if (traction <= 0x07) {
1192 }
else if (traction <= 0x27) {
1194 }
else if (traction <= 0x31) {
1196 }
else if (traction <= 0x37) {
1198 }
else if (traction <= 0x41) {
1207 if (_gted[e->
index].railtypelabel == RAILTYPE_RAIL_LABEL && engclass >=
EC_ELECTRIC) _gted[e->
index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
1208 if (_gted[e->
index].railtypelabel == RAILTYPE_ELECTRIC_LABEL && engclass <
EC_ELECTRIC) _gted[e->
index].railtypelabel = RAILTYPE_RAIL_LABEL;
1224 ei->refit_cost = buf->ReadByte();
1228 uint32 mask = buf->ReadDWord();
1266 byte weight = buf->ReadByte();
1269 grfmsg(2,
"RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8);
1291 _gted[e->
index].cargo_allowed = buf->ReadWord();
1297 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1311 uint8 count = buf->ReadByte();
1345 for (
int i = 0; i < numinfo; i++) {
1356 _gted[e->
index].roadtramtype = buf->ReadByte() + 1;
1364 rvi->running_cost = buf->ReadByte();
1376 if (spriteid == 0xFF) spriteid = 0xFD;
1378 if (spriteid < 0xFD) spriteid >>= 1;
1380 if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
1383 grfmsg(1,
"RoadVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1384 rvi->image_index = 0;
1390 rvi->capacity = buf->ReadByte();
1395 uint8 ctype = buf->ReadByte();
1397 if (ctype == 0xFF) {
1400 }
else if (_cur.
grffile->grf_version >= 8) {
1405 ei->cargo_type = ctype;
1408 grfmsg(2,
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
1414 rvi->cost_factor = buf->ReadByte();
1422 rvi->
power = buf->ReadByte();
1426 rvi->
weight = buf->ReadByte();
1434 uint32 mask = buf->ReadDWord();
1454 ei->refit_cost = buf->ReadByte();
1467 _gted[e->
index].cargo_allowed = buf->ReadWord();
1473 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1505 uint8 count = buf->ReadByte();
1539 for (
int i = 0; i < numinfo; i++) {
1552 if (spriteid == 0xFF) spriteid = 0xFD;
1554 if (spriteid < 0xFD) spriteid >>= 1;
1556 if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
1559 grfmsg(1,
"ShipVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1560 svi->image_index = 0;
1570 svi->cost_factor = buf->ReadByte();
1579 uint8 ctype = buf->ReadByte();
1581 if (ctype == 0xFF) {
1584 }
else if (_cur.
grffile->grf_version >= 8) {
1589 ei->cargo_type = ctype;
1592 grfmsg(2,
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
1598 svi->capacity = buf->ReadWord();
1602 svi->running_cost = buf->ReadByte();
1610 uint32 mask = buf->ReadDWord();
1622 ei->refit_cost = buf->ReadByte();
1643 _gted[e->
index].cargo_allowed = buf->ReadWord();
1649 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1677 uint8 count = buf->ReadByte();
1711 for (
int i = 0; i < numinfo; i++) {
1724 if (spriteid == 0xFF) spriteid = 0xFD;
1726 if (spriteid < 0xFD) spriteid >>= 1;
1728 if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
1731 grfmsg(1,
"AircraftVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
1732 avi->image_index = 0;
1738 if (buf->ReadByte() == 0) {
1746 SB(avi->
subtype, 1, 1, (buf->ReadByte() != 0 ? 1 : 0));
1750 avi->cost_factor = buf->ReadByte();
1754 avi->
max_speed = (buf->ReadByte() * 128) / 10;
1758 avi->acceleration = buf->ReadByte();
1762 avi->running_cost = buf->ReadByte();
1778 uint32 mask = buf->ReadDWord();
1790 ei->refit_cost = buf->ReadByte();
1803 _gted[e->
index].cargo_allowed = buf->ReadWord();
1809 _gted[e->
index].cargo_disallowed = buf->ReadWord();
1827 uint8 count = buf->ReadByte();
1873 for (
int i = 0; i < numinfo; i++) {
1877 if (statspec ==
nullptr && prop != 0x08) {
1878 grfmsg(2,
"StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
1887 if (*spec ==
nullptr) *spec = CallocT<StationSpec>(1);
1890 uint32 classid = buf->ReadDWord();
1891 (*spec)->cls_id = StationClass::Allocate(
BSWAP32(classid));
1896 statspec->
tiles = buf->ReadExtendedByte();
1900 for (uint t = 0; t < statspec->
tiles; t++) {
1904 if (buf->HasData(4) && *(uint32*)buf->Data() == 0) {
1907 dts->
Clone(&_station_display_datas_rail[t % 8]);
1915 static std::vector<DrawTileSeqStruct> tmp_layout;
1919 tmp_layout.emplace_back();
1923 dtss.
delta_x = buf->ReadByte();
1925 dtss.delta_y = buf->ReadByte();
1926 dtss.
delta_z = buf->ReadByte();
1927 dtss.size_x = buf->ReadByte();
1928 dtss.size_y = buf->ReadByte();
1929 dtss.size_z = buf->ReadByte();
1935 dts->
Clone(tmp_layout.data());
1940 byte srcid = buf->ReadByte();
1943 if (srcstatspec ==
nullptr) {
1944 grfmsg(1,
"StationChangeInfo: Station %u is not defined, cannot copy sprite layout to %u.", srcid, stid + i);
1952 for (uint t = 0; t < statspec->
tiles; t++) {
1971 statspec->copied_layouts =
false;
1973 while (buf->HasData()) {
1974 byte length = buf->ReadByte();
1975 byte number = buf->ReadByte();
1976 StationLayout layout;
1979 if (length == 0 || number == 0)
break;
1981 if (length > statspec->lengths) {
1982 byte diff_length = length - statspec->lengths;
1983 statspec->platforms =
ReallocT(statspec->platforms, length);
1984 memset(statspec->platforms + statspec->lengths, 0, diff_length);
1986 statspec->layouts =
ReallocT(statspec->layouts, length);
1987 memset(statspec->layouts + statspec->lengths, 0, diff_length *
sizeof(*statspec->layouts));
1989 statspec->lengths = length;
1993 if (number > statspec->platforms[l]) {
1994 statspec->layouts[l] =
ReallocT(statspec->layouts[l], number);
1996 memset(statspec->layouts[l] + statspec->platforms[l], 0,
1997 (number - statspec->platforms[l]) *
sizeof(**statspec->layouts));
1999 statspec->platforms[l] = number;
2003 layout = MallocT<byte>(length * number);
2005 for (l = 0; l < length; l++) {
2006 for (p = 0; p < number; p++) {
2007 layout[l * number + p] = buf->ReadByte();
2017 free(statspec->layouts[l][p]);
2018 statspec->layouts[l][p] = layout;
2023 byte srcid = buf->ReadByte();
2026 if (srcstatspec ==
nullptr) {
2027 grfmsg(1,
"StationChangeInfo: Station %u is not defined, cannot copy tile layout to %u.", srcid, stid + i);
2031 statspec->lengths = srcstatspec->lengths;
2032 statspec->platforms = srcstatspec->platforms;
2033 statspec->layouts = srcstatspec->layouts;
2034 statspec->copied_layouts =
true;
2043 statspec->
pylons = buf->ReadByte();
2047 if (_cur.
grffile->grf_version >= 7) {
2055 statspec->
flags = buf->ReadByte();
2059 statspec->
wires = buf->ReadByte();
2063 statspec->
blocked = buf->ReadByte();
2067 statspec->animation.
frames = buf->ReadByte();
2068 statspec->animation.
status = buf->ReadByte();
2072 statspec->animation.
speed = buf->ReadByte();
2076 statspec->animation.
triggers = buf->ReadWord();
2080 statspec->
tiles = buf->ReadExtendedByte();
2084 for (uint t = 0; t < statspec->
tiles; t++) {
2086 uint num_building_sprites = buf->ReadByte();
2113 if (
id + numinfo > CF_END) {
2114 grfmsg(1,
"CanalChangeInfo: Canal feature 0x%02X is invalid, max %u, ignoring",
id + numinfo, CF_END);
2118 for (
int i = 0; i < numinfo; i++) {
2127 cp->
flags = buf->ReadByte();
2152 grfmsg(1,
"BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo,
MAX_BRIDGES);
2156 for (
int i = 0; i < numinfo; i++) {
2162 byte year = buf->ReadByte();
2177 bridge->
price = buf->ReadByte();
2181 bridge->
speed = buf->ReadWord();
2185 byte tableid = buf->ReadByte();
2186 byte numtables = buf->ReadByte();
2193 for (; numtables-- != 0; tableid++) {
2195 grfmsg(1,
"BridgeChangeInfo: Table %d >= 7, skipping", tableid);
2201 bridge->
sprite_table[tableid] = MallocT<PalSpriteID>(32);
2218 bridge->
flags = buf->ReadByte();
2227 if (newone != STR_UNDEFINED) bridge->
material = newone;
2234 if (newone != STR_UNDEFINED) bridge->
transport_name[prop - 0x11] = newone;
2239 bridge->
price = buf->ReadWord();
2296 for (uint j = 0; j < 4; j++) buf->ReadByte();
2300 byte count = buf->ReadByte();
2301 for (byte j = 0; j < count; j++) buf->ReadByte();
2306 buf->Skip(buf->ReadByte() * 2);
2329 grfmsg(1,
"TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo,
NUM_HOUSES_PER_GRF);
2334 if (_cur.
grffile->housespec ==
nullptr) {
2338 for (
int i = 0; i < numinfo; i++) {
2341 if (prop != 0x08 && housespec ==
nullptr) {
2344 if (cir > ret) ret = cir;
2351 byte subs_id = buf->ReadByte();
2353 if (subs_id == 0xFF) {
2356 HouseSpec::Get(hid + i)->
enabled =
false;
2360 grfmsg(2,
"TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i);
2365 if (*house ==
nullptr) *house = CallocT<HouseSpec>(1);
2369 MemCpyT(housespec, HouseSpec::Get(subs_id));
2371 housespec->enabled =
true;
2372 housespec->grf_prop.local_id = hid + i;
2373 housespec->grf_prop.subst_id = subs_id;
2374 housespec->grf_prop.grffile = _cur.
grffile;
2375 housespec->random_colour[0] = 0x04;
2376 housespec->random_colour[1] = 0x08;
2377 housespec->random_colour[2] = 0x0C;
2378 housespec->random_colour[3] = 0x06;
2385 housespec->cargo_acceptance[2] = 0;
2397 uint16 years = buf->ReadWord();
2417 int8 goods = buf->ReadByte();
2453 byte
override = buf->ReadByte();
2457 grfmsg(2,
"TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.",
override, hid + i);
2461 _house_mngr.
Add(hid + i, _cur.
grffile->grfid,
override);
2470 for (uint j = 0; j < 4; j++) housespec->
random_colour[j] = buf->ReadByte();
2492 housespec->
class_id = AllocateHouseClassID(buf->ReadByte(), _cur.
grffile->grfid);
2500 uint32 cargotypes = buf->ReadDWord();
2503 if (cargotypes == 0xFFFFFFFF)
break;
2505 for (uint j = 0; j < 3; j++) {
2507 uint8 cargo_part =
GB(cargotypes, 8 * j, 8);
2525 byte count = buf->ReadByte();
2526 for (byte j = 0; j < count; j++) {
2534 housespec->
min_year = buf->ReadWord();
2538 housespec->
max_year = buf->ReadWord();
2542 uint count = buf->ReadByte();
2594 template <
typename T>
2598 grfmsg(1,
"LoadTranslationTable: %s translation table must start at zero", name);
2602 translation_table.clear();
2603 for (
int i = 0; i < numinfo; i++) {
2604 uint32 item = buf->ReadDWord();
2605 translation_table.push_back(
BSWAP32(item));
2641 for (
int i = 0; i < numinfo; i++) {
2644 int factor = buf->ReadByte();
2645 uint price = gvid + i;
2647 if (price < PR_END) {
2650 grfmsg(1,
"GlobalVarChangeInfo: Price %d out of range, ignoring", price);
2659 if ((newone != STR_UNDEFINED) && (curidx <
CURRENCY_END)) {
2667 uint32 rate = buf->ReadDWord();
2675 grfmsg(1,
"GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx);
2682 uint16 options = buf->ReadWord();
2691 grfmsg(1,
"GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx);
2698 uint32 tempfix = buf->ReadDWord();
2704 grfmsg(1,
"GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
2711 uint32 tempfix = buf->ReadDWord();
2717 grfmsg(1,
"GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
2724 Year year_euro = buf->ReadWord();
2729 grfmsg(1,
"GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
2736 grfmsg(1,
"GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
2738 grfmsg(1,
"GlobalVarChangeInfo: Not enough entries set in the snowline table (" PRINTF_SIZE
")", buf->Remaining());
2744 table[i][j] = buf->ReadByte();
2745 if (_cur.
grffile->grf_version >= 8) {
2748 if (table[i][j] >= 128) {
2770 uint curidx = gvid + i;
2772 if (lang ==
nullptr) {
2773 grfmsg(1,
"GlobalVarChangeInfo: Language %d is not known, ignoring", curidx);
2778 while (buf->ReadByte() != 0) {
2788 uint plural_form = buf->ReadByte();
2789 if (plural_form >= LANGUAGE_MAX_PLURAL) {
2790 grfmsg(1,
"GlobalVarChanceInfo: Plural form %d is out of range, ignoring", plural_form);
2797 byte newgrf_id = buf->ReadByte();
2798 while (newgrf_id != 0) {
2799 const char *name = buf->ReadString();
2814 grfmsg(1,
"GlobalVarChangeInfo: Gender name %s is not known, ignoring", name);
2821 grfmsg(1,
"GlobalVarChangeInfo: Case name %s is not known, ignoring", name);
2826 newgrf_id = buf->ReadByte();
2862 for (
int i = 0; i < numinfo; i++) {
2886 uint32 s = buf->ReadDWord();
2887 uint32 t = buf->ReadDWord();
2894 while (buf->ReadByte() != 0) {
2922 grfmsg(2,
"CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo,
NUM_CARGO - 1);
2926 for (
int i = 0; i < numinfo; i++) {
2931 cs->
bitnum = buf->ReadByte();
2969 cs->
sprite = buf->ReadWord();
2973 cs->
weight = buf->ReadByte();
2977 cs->transit_days[0] = buf->ReadByte();
2981 cs->transit_days[1] = buf->ReadByte();
2985 cs->initial_payment = buf->ReadDWord();
2989 cs->rating_colour = buf->ReadByte();
2993 cs->legend_colour = buf->ReadByte();
3001 cs->
classes = buf->ReadWord();
3005 cs->
label = buf->ReadDWord();
3010 uint8 substitute_type = buf->ReadByte();
3012 switch (substitute_type) {
3019 grfmsg(1,
"CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
3035 cs->
multiplier = max<uint16>(1u, buf->ReadWord());
3060 if (_cur.
grffile->sound_offset == 0) {
3061 grfmsg(1,
"SoundEffectChangeInfo: No effects defined, skipping");
3066 grfmsg(1,
"SoundEffectChangeInfo: Attempting to change undefined sound effect (%u), max (%u). Ignoring.", sid + numinfo,
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
3070 for (
int i = 0; i < numinfo; i++) {
3075 sound->volume = buf->ReadByte();
3079 sound->priority = buf->ReadByte();
3083 SoundID orig_sound = buf->ReadByte();
3088 SoundEntry *old_sound = GetSound(orig_sound);
3091 *old_sound = *sound;
3133 buf->Skip(buf->ReadByte() * 2);
3161 if (_cur.
grffile->indtspec ==
nullptr) {
3165 for (
int i = 0; i < numinfo; i++) {
3168 if (prop != 0x08 && tsp ==
nullptr) {
3170 if (cir > ret) ret = cir;
3177 byte subs_id = buf->ReadByte();
3181 grfmsg(2,
"IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
3186 if (*tilespec ==
nullptr) {
3187 *tilespec = CallocT<IndustryTileSpec>(1);
3190 memcpy(tsp, &_industry_tile_specs[subs_id],
sizeof(_industry_tile_specs[subs_id]));
3191 tsp->enabled =
true;
3199 tsp->grf_prop.local_id = indtid + i;
3200 tsp->grf_prop.subst_id = subs_id;
3201 tsp->grf_prop.grffile = _cur.
grffile;
3208 byte ovrid = buf->ReadByte();
3212 grfmsg(2,
"IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
3216 _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
3223 uint16 acctp = buf->ReadWord();
3255 byte num_cargoes = buf->ReadByte();
3262 if (i < num_cargoes) {
3329 byte num_table = buf->ReadByte();
3330 for (byte j = 0; j < num_table; j++) {
3331 for (uint k = 0;; k++) {
3332 byte x = buf->ReadByte();
3333 if (x == 0xFE && k == 0) {
3339 byte y = buf->ReadByte();
3340 if (x == 0 && y == 0x80)
break;
3342 byte gfx = buf->ReadByte();
3343 if (gfx == 0xFE) buf->ReadWord();
3350 for (byte j = 0; j < 3; j++) buf->ReadByte();
3357 buf->Skip(buf->ReadByte());
3361 int num_inputs = buf->ReadByte();
3362 int num_outputs = buf->ReadByte();
3363 buf->Skip(num_inputs * num_outputs * 2);
3381 const size_t size = layout.size();
3382 for (
size_t i = 0; i < size - 1; i++) {
3383 for (
size_t j = i + 1; j < size; j++) {
3384 if (layout[i].ti.x == layout[j].ti.x &&
3385 layout[i].ti.y == layout[j].ti.y) {
3411 if (_cur.
grffile->industryspec ==
nullptr) {
3415 for (
int i = 0; i < numinfo; i++) {
3418 if (prop != 0x08 && indsp ==
nullptr) {
3420 if (cir > ret) ret = cir;
3427 byte subs_id = buf->ReadByte();
3429 if (subs_id == 0xFF) {
3432 _industry_specs[indid + i].
enabled =
false;
3436 grfmsg(2,
"_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
3443 if (*indspec ==
nullptr) {
3447 *indsp = _origin_industry_specs[subs_id];
3450 indsp->
grf_prop.subst_id = subs_id;
3460 byte ovrid = buf->ReadByte();
3464 grfmsg(2,
"IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
3468 _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
3473 byte new_num_layouts = buf->ReadByte();
3474 uint32 definition_size = buf->ReadDWord();
3475 uint32 bytes_read = 0;
3476 std::vector<IndustryTileLayout> new_layouts;
3479 for (byte j = 0; j < new_num_layouts; j++) {
3482 for (uint k = 0;; k++) {
3483 if (bytes_read >= definition_size) {
3484 grfmsg(3,
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry %u.", indid);
3486 definition_size = UINT32_MAX;
3492 it.ti.
x = buf->ReadByte();
3495 if (it.ti.
x == 0xFE && k == 0) {
3497 IndustryType type = buf->ReadByte();
3498 byte laynbr = buf->ReadByte();
3501 if (type >=
lengthof(_origin_industry_specs)) {
3502 grfmsg(1,
"IndustriesChangeInfo: Invalid original industry number for layout import, industry %u", indid);
3506 if (laynbr >= _origin_industry_specs[type].layouts.size()) {
3507 grfmsg(1,
"IndustriesChangeInfo: Invalid original industry layout index for layout import, industry %u", indid);
3511 layout = _origin_industry_specs[type].layouts[laynbr];
3515 it.ti.
y = buf->ReadByte();
3518 if (it.ti.
x == 0 && it.ti.
y == 0x80) {
3524 it.gfx = buf->ReadByte();
3527 if (it.gfx == 0xFE) {
3529 int local_tile_id = buf->ReadWord();
3533 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3536 grfmsg(2,
"IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
3541 }
else if (it.gfx == 0xFF) {
3542 it.ti.
x = (int8)
GB(it.ti.
x, 0, 8);
3543 it.ti.
y = (int8)
GB(it.ti.
y, 0, 8);
3552 if (_cur.
grffile->grf_version < 8 && it.ti.
x < 0) it.ti.
y += 1;
3558 grfmsg(1,
"IndustriesChangeInfo: Invalid industry layout for industry id %u. Ignoring", indid);
3562 new_layouts.push_back(layout);
3592 for (byte j = 0; j < 2; j++) {
3598 for (byte j = 0; j < 3; j++) {
3606 indsp->production_rate[prop - 0x12] = buf->ReadByte();
3619 sounds[j] = buf->ReadByte();
3635 for (byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
3661 uint32 multiples = buf->ReadDWord();
3677 byte aflag = buf->ReadByte();
3687 uint16 str = buf->ReadWord();
3697 byte num_cargoes = buf->ReadByte();
3698 if (num_cargoes >
lengthof(indsp->produced_cargo)) {
3703 for (uint i = 0; i <
lengthof(indsp->produced_cargo); i++) {
3704 if (i < num_cargoes) {
3706 indsp->produced_cargo[i] = cargo;
3715 byte num_cargoes = buf->ReadByte();
3722 if (i < num_cargoes) {
3733 byte num_cargoes = buf->ReadByte();
3734 if (num_cargoes >
lengthof(indsp->production_rate)) {
3739 for (uint i = 0; i <
lengthof(indsp->production_rate); i++) {
3740 if (i < num_cargoes) {
3741 indsp->production_rate[i] = buf->ReadByte();
3743 indsp->production_rate[i] = 0;
3750 byte num_inputs = buf->ReadByte();
3751 byte num_outputs = buf->ReadByte();
3758 for (uint j = 0; j <
lengthof(indsp->produced_cargo); j++) {
3760 if (i < num_inputs && j < num_outputs) mult = buf->ReadWord();
3784 for (
int i = 0; i < as->
num_table; i++) {
3789 }
while ((++it)->ti.x != -0x80);
3790 table_list[i] = MallocT<AirportTileTable>(num_tiles);
3793 as->
table = table_list;
3815 grfmsg(1,
"AirportChangeInfo: Too many airports, trying id (%u), max (%u). Ignoring.", airport + numinfo,
NUM_AIRPORTS_PER_GRF);
3820 if (_cur.
grffile->airportspec ==
nullptr) {
3824 for (
int i = 0; i < numinfo; i++) {
3827 if (as ==
nullptr && prop != 0x08 && prop != 0x09) {
3828 grfmsg(2,
"AirportChangeInfo: Attempt to modify undefined airport %u, ignoring", airport + i);
3834 byte subs_id = buf->ReadByte();
3836 if (subs_id == 0xFF) {
3843 grfmsg(2,
"AirportChangeInfo: Attempt to use new airport %u as substitute airport for %u. Ignoring.", subs_id, airport + i);
3851 if (*spec ==
nullptr) {
3852 *spec = MallocT<AirportSpec>(1);
3857 as->grf_prop.local_id = airport + i;
3858 as->grf_prop.subst_id = subs_id;
3859 as->grf_prop.grffile = _cur.
grffile;
3861 _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
3872 uint32 defsize = buf->ReadDWord();
3878 for (byte j = 0; j < as->
num_table; j++) {
3880 for (
int k = 0;; k++) {
3881 att[k].ti.x = buf->ReadByte();
3882 att[k].ti.y = buf->ReadByte();
3884 if (att[k].ti.x == 0 && att[k].ti.y == 0x80) {
3887 att[k].ti.x = -0x80;
3896 att[k].
gfx = buf->ReadByte();
3898 if (att[k].gfx == 0xFE) {
3900 int local_tile_id = buf->ReadWord();
3903 uint16 tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
3906 grfmsg(2,
"AirportChangeInfo: Attempt to use airport tile %u with airport id %u, not yet defined. Ignoring.", local_tile_id, airport + i);
3909 att[k].gfx = tempid;
3911 }
else if (att[k].gfx == 0xFF) {
3912 att[k].ti.x = (int8)
GB(att[k].ti.x, 0, 8);
3913 att[k].ti.y = (int8)
GB(att[k].ti.y, 0, 8);
3924 tile_table[j] = CallocT<AirportTileTable>(size);
3925 memcpy(tile_table[j], copy_from,
sizeof(*copy_from) * size);
3928 as->
table = tile_table;
3931 for (
int i = 0; i < as->
num_table; i++) {
3932 free(tile_table[i]);
4038 if (_cur.
grffile->objectspec ==
nullptr) {
4042 for (
int i = 0; i < numinfo; i++) {
4045 if (prop != 0x08 && spec ==
nullptr) {
4048 if (cir > ret) ret = cir;
4057 if (*ospec ==
nullptr) {
4058 *ospec = CallocT<ObjectSpec>(1);
4059 (*ospec)->
views = 1;
4063 uint32 classid = buf->ReadDWord();
4064 (*ospec)->cls_id = ObjectClass::Allocate(
BSWAP32(classid));
4065 (*ospec)->enabled =
true;
4080 spec->
climate = buf->ReadByte();
4084 spec->
size = buf->ReadByte();
4127 spec->
height = buf->ReadByte();
4131 spec->
views = buf->ReadByte();
4133 grfmsg(2,
"ObjectChangeInfo: Invalid number of views (%u) for object id %u. Ignoring.", spec->
views,
id + i);
4166 grfmsg(1,
"RailTypeChangeInfo: Rail type %u is invalid, max %u, ignoring",
id + numinfo,
RAILTYPE_END);
4170 for (
int i = 0; i < numinfo; i++) {
4183 uint16 str = buf->ReadWord();
4185 if (_cur.
grffile->grf_version < 8) {
4215 int n = buf->ReadByte();
4216 for (
int j = 0; j != n; j++) {
4217 RailTypeLabel label = buf->ReadDWord();
4277 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4296 grfmsg(1,
"RailTypeReserveInfo: Rail type %u is invalid, max %u, ignoring",
id + numinfo,
RAILTYPE_END);
4300 for (
int i = 0; i < numinfo; i++) {
4304 RailTypeLabel rtl = buf->ReadDWord();
4313 _cur.
grffile->railtype_map[
id + i] = rt;
4331 int n = buf->ReadByte();
4332 for (
int j = 0; j != n; j++) {
4337 grfmsg(1,
"RailTypeReserveInfo: Ignoring property 1D for rail type %u because no label was set",
id + i);
4344 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4385 grfmsg(1,
"RoadTypeChangeInfo: Road type %u is invalid, max %u, ignoring",
id + numinfo,
ROADTYPE_END);
4389 for (
int i = 0; i < numinfo; i++) {
4402 uint16 str = buf->ReadWord();
4429 int n = buf->ReadByte();
4430 for (
int j = 0; j != n; j++) {
4431 RoadTypeLabel label = buf->ReadDWord();
4478 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4509 grfmsg(1,
"RoadTypeReserveInfo: Road type %u is invalid, max %u, ignoring",
id + numinfo,
ROADTYPE_END);
4513 for (
int i = 0; i < numinfo; i++) {
4516 RoadTypeLabel rtl = buf->ReadDWord();
4523 }
else if (GetRoadTramType(rt) != rtt) {
4524 grfmsg(1,
"RoadTypeReserveInfo: Road type %u is invalid type (road/tram), ignoring",
id + numinfo);
4528 type_map[
id + i] = rt;
4545 int n = buf->ReadByte();
4546 for (
int j = 0; j != n; j++) {
4551 grfmsg(1,
"RoadTypeReserveInfo: Ignoring property 1D for road type %u because no label was set",
id + i);
4557 for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
4581 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_ROAD);
4586 return RoadTypeReserveInfo(
id, numinfo, prop, buf, RTT_TRAM);
4599 if (_cur.
grffile->airtspec ==
nullptr) {
4603 for (
int i = 0; i < numinfo; i++) {
4606 if (prop != 0x08 && tsp ==
nullptr) {
4607 grfmsg(2,
"AirportTileChangeInfo: Attempt to modify undefined airport tile %u. Ignoring.", airtid + i);
4614 byte subs_id = buf->ReadByte();
4618 grfmsg(2,
"AirportTileChangeInfo: Attempt to use new airport tile %u as substitute airport tile for %u. Ignoring.", subs_id, airtid + i);
4623 if (*tilespec ==
nullptr) {
4624 *tilespec = CallocT<AirportTileSpec>(1);
4628 tsp->enabled =
true;
4632 tsp->grf_prop.local_id = airtid + i;
4633 tsp->grf_prop.subst_id = subs_id;
4634 tsp->grf_prop.grffile = _cur.
grffile;
4641 byte
override = buf->ReadByte();
4645 grfmsg(2,
"AirportTileChangeInfo: Attempt to override new airport tile %u with airport tile id %u. Ignoring.",
override, airtid + i);
4649 _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid,
override);
4679 static bool HandleChangeInfoResult(
const char *caller,
ChangeInfoResult cir, uint8 feature, uint8 property)
4682 default: NOT_REACHED();
4692 grfmsg(1,
"%s: Ignoring property 0x%02X of feature 0x%02X (not implemented)", caller, property, feature);
4696 grfmsg(0,
"%s: Unknown property 0x%02X of feature 0x%02X, disabling", caller, property, feature);
4709 static void FeatureChangeInfo(
ByteReader *buf)
4722 static const VCI_Handler handler[] = {
4740 AirportTilesChangeInfo,
4745 uint8 feature = buf->ReadByte();
4746 uint8 numprops = buf->ReadByte();
4747 uint numinfo = buf->ReadByte();
4748 uint engine = buf->ReadExtendedByte();
4750 if (feature >= GSF_END) {
4751 grfmsg(1,
"FeatureChangeInfo: Unsupported feature 0x%02X, skipping", feature);
4755 grfmsg(6,
"FeatureChangeInfo: Feature 0x%02X, %d properties, to apply to %d+%d",
4756 feature, numprops, engine, numinfo);
4758 if (feature >=
lengthof(handler) || handler[feature] ==
nullptr) {
4759 if (feature != GSF_CARGOES)
grfmsg(1,
"FeatureChangeInfo: Unsupported feature 0x%02X, skipping", feature);
4766 while (numprops-- && buf->HasData()) {
4767 uint8 prop = buf->ReadByte();
4770 if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop))
return;
4777 uint8 feature = buf->ReadByte();
4778 uint8 numprops = buf->ReadByte();
4779 uint numinfo = buf->ReadByte();
4780 buf->ReadExtendedByte();
4782 if (feature == GSF_BRIDGES && numprops == 1) {
4783 uint8 prop = buf->ReadByte();
4786 if (prop == 0x0D)
return;
4787 }
else if (feature == GSF_GLOBALVAR && numprops == 1) {
4788 uint8 prop = buf->ReadByte();
4791 bool is_safe =
true;
4792 for (uint i = 0; i < numinfo; i++) {
4793 uint32 s = buf->ReadDWord();
4801 if (is_safe)
return;
4812 static void ReserveChangeInfo(
ByteReader *buf)
4814 uint8 feature = buf->ReadByte();
4816 if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES && feature != GSF_ROADTYPES && feature != GSF_TRAMTYPES)
return;
4818 uint8 numprops = buf->ReadByte();
4819 uint8 numinfo = buf->ReadByte();
4820 uint8 index = buf->ReadExtendedByte();
4822 while (numprops-- && buf->HasData()) {
4823 uint8 prop = buf->ReadByte();
4827 default: NOT_REACHED();
4833 cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
4837 cir = RailTypeReserveInfo(index, numinfo, prop, buf);
4841 cir = RoadTypeReserveInfo(index, numinfo, prop, buf);
4845 cir = TramTypeReserveInfo(index, numinfo, prop, buf);
4849 if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop))
return;
4870 uint8 feature = buf->ReadByte();
4871 uint16 num_sets = buf->ReadByte();
4872 uint16 first_set = 0;
4874 if (num_sets == 0 && buf->HasData(3)) {
4877 first_set = buf->ReadExtendedByte();
4878 num_sets = buf->ReadExtendedByte();
4880 uint16 num_ents = buf->ReadExtendedByte();
4882 if (feature >= GSF_END) {
4884 grfmsg(1,
"NewSpriteSet: Unsupported feature 0x%02X, skipping %d sprites", feature, _cur.
skip_sprites);
4890 grfmsg(7,
"New sprite set at %d of feature 0x%02X, consisting of %d sets with %d views each (total %d)",
4891 _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
4894 for (
int i = 0; i < num_sets * num_ents; i++) {
4904 uint16 num_sets = buf->ReadByte();
4906 if (num_sets == 0 && buf->HasData(3)) {
4909 buf->ReadExtendedByte();
4910 num_sets = buf->ReadExtendedByte();
4912 uint16 num_ents = buf->ReadExtendedByte();
4921 static const SpriteGroup *GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
4923 if (
HasBit(groupid, 15)) {
4928 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
4929 grfmsg(1,
"GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid);
4933 return _cur.spritegroups[groupid];
4946 if (
HasBit(spriteid, 15)) {
4952 grfmsg(1,
"CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid", setid, type, spriteid);
4960 assert(spriteset_start + num_sprites <= _cur.
spriteid);
4981 uint8 feature = buf->ReadByte();
4982 if (feature >= GSF_END) {
4983 grfmsg(1,
"NewSpriteGroup: Unsupported feature 0x%02X, skipping", feature);
4987 uint8 setid = buf->ReadByte();
4988 uint8 type = buf->ReadByte();
5012 switch (
GB(type, 2, 2)) {
5013 default: NOT_REACHED();
5014 case 0: group->size = DSG_SIZE_BYTE; varsize = 1;
break;
5015 case 1: group->size = DSG_SIZE_WORD; varsize = 2;
break;
5016 case 2: group->size = DSG_SIZE_DWORD; varsize = 4;
break;
5019 static std::vector<DeterministicSpriteGroupAdjust> adjusts;
5025 adjusts.emplace_back();
5030 adjust.variable = buf->ReadByte();
5031 if (adjust.variable == 0x7E) {
5033 adjust.subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
5038 varadjust = buf->ReadByte();
5039 adjust.shift_num =
GB(varadjust, 0, 5);
5040 adjust.type = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
5041 adjust.and_mask = buf->ReadVarSize(varsize);
5043 if (adjust.type != DSGA_TYPE_NONE) {
5044 adjust.add_val = buf->ReadVarSize(varsize);
5045 adjust.divmod_val = buf->ReadVarSize(varsize);
5048 adjust.divmod_val = 0;
5052 }
while (
HasBit(varadjust, 5));
5054 group->num_adjusts = (uint)adjusts.size();
5055 group->adjusts = MallocT<DeterministicSpriteGroupAdjust>(group->num_adjusts);
5056 MemCpyT(group->adjusts, adjusts.data(), group->num_adjusts);
5058 std::vector<DeterministicSpriteGroupRange> ranges;
5059 ranges.resize(buf->ReadByte());
5060 for (uint i = 0; i < ranges.size(); i++) {
5061 ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5062 ranges[i].low = buf->ReadVarSize(varsize);
5063 ranges[i].high = buf->ReadVarSize(varsize);
5066 group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
5067 group->error_group = ranges.size() > 0 ? ranges[0].group : group->default_group;
5069 group->calculated_result = ranges.size() == 0;
5072 std::vector<uint32> bounds;
5073 for (uint i = 0; i < ranges.size(); i++) {
5074 bounds.push_back(ranges[i].low);
5075 if (ranges[i].high != UINT32_MAX) bounds.push_back(ranges[i].high + 1);
5077 std::sort(bounds.begin(), bounds.end());
5078 bounds.erase(std::unique(bounds.begin(), bounds.end()), bounds.end());
5080 std::vector<const SpriteGroup *> target;
5081 for (uint j = 0; j < bounds.size(); ++j) {
5082 uint32 v = bounds[j];
5084 for (uint i = 0; i < ranges.size(); i++) {
5085 if (ranges[i].low <= v && v <= ranges[i].high) {
5086 t = ranges[i].group;
5090 target.push_back(t);
5092 assert(target.size() == bounds.size());
5094 std::vector<DeterministicSpriteGroupRange> optimised;
5095 for (uint j = 0; j < bounds.size(); ) {
5096 if (target[j] != group->default_group) {
5098 r.group = target[j];
5100 while (j < bounds.size() && target[j] == r.group) {
5103 r.high = j < bounds.size() ? bounds[j] - 1 : UINT32_MAX;
5104 optimised.push_back(r);
5110 group->num_ranges = (uint)optimised.size();
5111 if (group->num_ranges > 0) {
5112 group->ranges = MallocT<DeterministicSpriteGroupRange>(group->num_ranges);
5113 MemCpyT(group->ranges, &optimised.front(), group->num_ranges);
5131 group->count = buf->ReadByte();
5134 uint8 triggers = buf->ReadByte();
5135 group->triggers =
GB(triggers, 0, 7);
5136 group->
cmp_mode =
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
5141 for (uint i = 0; i < group->
num_groups; i++) {
5142 group->
groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
5153 case GSF_ROADVEHICLES:
5164 byte num_loaded = type;
5165 byte num_loading = buf->ReadByte();
5168 grfmsg(0,
"NewSpriteGroup: No sprite set to work on! Skipping");
5179 if (num_loaded > 0) group->
loaded = CallocT<const SpriteGroup*>(num_loaded);
5180 if (num_loading > 0) group->
loading = CallocT<const SpriteGroup*>(num_loading);
5182 grfmsg(6,
"NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
5183 setid, num_loaded, num_loading);
5185 for (uint i = 0; i < num_loaded; i++) {
5188 grfmsg(8,
"NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
5191 for (uint i = 0; i < num_loading; i++) {
5194 grfmsg(8,
"NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
5201 case GSF_AIRPORTTILES:
5203 case GSF_INDUSTRYTILES: {
5204 byte num_building_sprites =
max((uint8)1, type);
5212 if (
ReadSpriteLayout(buf, num_building_sprites,
true, feature,
false, type == 0, &group->dts))
return;
5216 case GSF_INDUSTRIES: {
5218 grfmsg(1,
"NewSpriteGroup: Unsupported industry production version %d, skipping", type);
5229 for (uint i = 0; i < 3; i++) {
5233 for (uint i = 0; i < 2; i++) {
5236 group->again = buf->ReadByte();
5237 }
else if (type == 1) {
5239 for (uint i = 0; i < 3; i++) {
5243 for (uint i = 0; i < 2; i++) {
5246 group->again = buf->ReadByte();
5247 }
else if (type == 2) {
5251 error->
data =
stredup(
"too many inputs (max 16)");
5254 for (uint i = 0; i < group->
num_input; i++) {
5255 byte rawcargo = buf->ReadByte();
5273 error->
data =
stredup(
"too many outputs (max 16)");
5276 for (uint i = 0; i < group->
num_output; i++) {
5277 byte rawcargo = buf->ReadByte();
5290 group->again = buf->ReadByte();
5298 default:
grfmsg(1,
"NewSpriteGroup: Unsupported feature 0x%02X, skipping", feature);
5303 _cur.spritegroups[setid] = act_group;
5306 static CargoID TranslateCargo(uint8 feature, uint8 ctype)
5308 if (feature == GSF_OBJECTS) {
5313 grfmsg(1,
"TranslateCargo: Invalid cargo bitnum %d for objects, skipping.", ctype);
5318 if (feature == GSF_STATIONS && ctype == 0xFE)
return CT_DEFAULT_NA;
5319 if (ctype == 0xFF)
return CT_PURCHASE;
5324 grfmsg(1,
"TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
5329 FOR_ALL_CARGOSPECS(cs) {
5330 if (cs->
bitnum == ctype) {
5331 grfmsg(6,
"TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, cs->
Index());
5336 grfmsg(5,
"TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
5342 grfmsg(1,
"TranslateCargo: Cargo type %d out of range (max %d), skipping.", ctype, (
unsigned int)_cur.
grffile->
cargo_list.size() - 1);
5349 grfmsg(5,
"TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype);
5355 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));
5359 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);
5364 static bool IsValidGroupID(uint16 groupid,
const char *
function)
5366 if (groupid >
MAX_SPRITEGROUP || _cur.spritegroups[groupid] ==
nullptr) {
5367 grfmsg(1,
"%s: Spritegroup 0x%04X out of range or empty, skipping.",
function, groupid);
5374 static void VehicleMapSpriteGroup(
ByteReader *buf, byte feature, uint8 idcount)
5377 static uint last_engines_count;
5378 bool wagover =
false;
5381 if (
HasBit(idcount, 7)) {
5384 idcount =
GB(idcount, 0, 7);
5386 if (last_engines_count == 0) {
5387 grfmsg(0,
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
5391 grfmsg(6,
"VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
5392 last_engines_count, idcount);
5394 if (last_engines_count != idcount) {
5395 last_engines =
ReallocT(last_engines, idcount);
5396 last_engines_count = idcount;
5401 for (uint i = 0; i < idcount; i++) {
5407 HandleChangeInfoResult(
"VehicleMapSpriteGroup",
CIR_INVALID_ID, 0, 0);
5411 engines[i] = e->
index;
5412 if (!wagover) last_engines[i] = engines[i];
5415 uint8 cidcount = buf->ReadByte();
5416 for (uint c = 0; c < cidcount; c++) {
5417 uint8 ctype = buf->ReadByte();
5418 uint16 groupid = buf->ReadWord();
5419 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
continue;
5421 grfmsg(8,
"VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
5423 ctype = TranslateCargo(feature, ctype);
5426 for (uint i = 0; i < idcount; i++) {
5429 grfmsg(7,
"VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
5432 SetWagonOverrideSprites(engine, ctype, _cur.spritegroups[groupid], last_engines, last_engines_count);
5434 SetCustomEngineSprites(engine, ctype, _cur.spritegroups[groupid]);
5439 uint16 groupid = buf->ReadWord();
5440 if (!IsValidGroupID(groupid,
"VehicleMapSpriteGroup"))
return;
5442 grfmsg(8,
"-- Default group id 0x%04X", groupid);
5444 for (uint i = 0; i < idcount; i++) {
5448 SetWagonOverrideSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid], last_engines, last_engines_count);
5450 SetCustomEngineSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid]);
5457 static void CanalMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5460 for (uint i = 0; i < idcount; i++) {
5464 uint8 cidcount = buf->ReadByte();
5465 buf->Skip(cidcount * 3);
5467 uint16 groupid = buf->ReadWord();
5468 if (!IsValidGroupID(groupid,
"CanalMapSpriteGroup"))
return;
5470 for (uint i = 0; i < idcount; i++) {
5474 grfmsg(1,
"CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
5484 static void StationMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5486 uint8 *stations =
AllocaM(uint8, idcount);
5487 for (uint i = 0; i < idcount; i++) {
5488 stations[i] = buf->ReadByte();
5491 uint8 cidcount = buf->ReadByte();
5492 for (uint c = 0; c < cidcount; c++) {
5493 uint8 ctype = buf->ReadByte();
5494 uint16 groupid = buf->ReadWord();
5495 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
continue;
5497 ctype = TranslateCargo(GSF_STATIONS, ctype);
5500 for (uint i = 0; i < idcount; i++) {
5503 if (statspec ==
nullptr) {
5504 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5512 uint16 groupid = buf->ReadWord();
5513 if (!IsValidGroupID(groupid,
"StationMapSpriteGroup"))
return;
5515 for (uint i = 0; i < idcount; i++) {
5518 if (statspec ==
nullptr) {
5519 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5524 grfmsg(1,
"StationMapSpriteGroup: Station with ID 0x%02X mapped multiple times, skipping", stations[i]);
5531 StationClass::Assign(statspec);
5536 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5538 uint8 *houses =
AllocaM(uint8, idcount);
5539 for (uint i = 0; i < idcount; i++) {
5540 houses[i] = buf->ReadByte();
5544 uint8 cidcount = buf->ReadByte();
5545 buf->Skip(cidcount * 3);
5547 uint16 groupid = buf->ReadWord();
5548 if (!IsValidGroupID(groupid,
"TownHouseMapSpriteGroup"))
return;
5550 if (_cur.
grffile->housespec ==
nullptr) {
5551 grfmsg(1,
"TownHouseMapSpriteGroup: No houses defined, skipping");
5555 for (uint i = 0; i < idcount; i++) {
5558 if (hs ==
nullptr) {
5559 grfmsg(1,
"TownHouseMapSpriteGroup: House %d undefined, skipping.", houses[i]);
5567 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5569 uint8 *industries =
AllocaM(uint8, idcount);
5570 for (uint i = 0; i < idcount; i++) {
5571 industries[i] = buf->ReadByte();
5575 uint8 cidcount = buf->ReadByte();
5576 buf->Skip(cidcount * 3);
5578 uint16 groupid = buf->ReadWord();
5579 if (!IsValidGroupID(groupid,
"IndustryMapSpriteGroup"))
return;
5581 if (_cur.
grffile->industryspec ==
nullptr) {
5582 grfmsg(1,
"IndustryMapSpriteGroup: No industries defined, skipping");
5586 for (uint i = 0; i < idcount; i++) {
5589 if (indsp ==
nullptr) {
5590 grfmsg(1,
"IndustryMapSpriteGroup: Industry %d undefined, skipping", industries[i]);
5598 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5600 uint8 *indtiles =
AllocaM(uint8, idcount);
5601 for (uint i = 0; i < idcount; i++) {
5602 indtiles[i] = buf->ReadByte();
5606 uint8 cidcount = buf->ReadByte();
5607 buf->Skip(cidcount * 3);
5609 uint16 groupid = buf->ReadWord();
5610 if (!IsValidGroupID(groupid,
"IndustrytileMapSpriteGroup"))
return;
5612 if (_cur.
grffile->indtspec ==
nullptr) {
5613 grfmsg(1,
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
5617 for (uint i = 0; i < idcount; i++) {
5620 if (indtsp ==
nullptr) {
5621 grfmsg(1,
"IndustrytileMapSpriteGroup: Industry tile %d undefined, skipping", indtiles[i]);
5629 static void CargoMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5632 for (uint i = 0; i < idcount; i++) {
5633 cargoes[i] = buf->ReadByte();
5637 uint8 cidcount = buf->ReadByte();
5638 buf->Skip(cidcount * 3);
5640 uint16 groupid = buf->ReadWord();
5641 if (!IsValidGroupID(groupid,
"CargoMapSpriteGroup"))
return;
5643 for (uint i = 0; i < idcount; i++) {
5647 grfmsg(1,
"CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid);
5653 cs->group = _cur.spritegroups[groupid];
5657 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5659 if (_cur.
grffile->objectspec ==
nullptr) {
5660 grfmsg(1,
"ObjectMapSpriteGroup: No object tiles defined, skipping");
5664 uint8 *objects =
AllocaM(uint8, idcount);
5665 for (uint i = 0; i < idcount; i++) {
5666 objects[i] = buf->ReadByte();
5669 uint8 cidcount = buf->ReadByte();
5670 for (uint c = 0; c < cidcount; c++) {
5671 uint8 ctype = buf->ReadByte();
5672 uint16 groupid = buf->ReadWord();
5673 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
continue;
5675 ctype = TranslateCargo(GSF_OBJECTS, ctype);
5678 for (uint i = 0; i < idcount; i++) {
5681 if (spec ==
nullptr) {
5682 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
5690 uint16 groupid = buf->ReadWord();
5691 if (!IsValidGroupID(groupid,
"ObjectMapSpriteGroup"))
return;
5693 for (uint i = 0; i < idcount; i++) {
5696 if (spec ==
nullptr) {
5697 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
5702 grfmsg(1,
"ObjectMapSpriteGroup: Object with ID 0x%02X mapped multiple times, skipping", objects[i]);
5712 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5714 uint8 *railtypes =
AllocaM(uint8, idcount);
5715 for (uint i = 0; i < idcount; i++) {
5716 uint8
id = buf->ReadByte();
5720 uint8 cidcount = buf->ReadByte();
5721 for (uint c = 0; c < cidcount; c++) {
5722 uint8 ctype = buf->ReadByte();
5723 uint16 groupid = buf->ReadWord();
5724 if (!IsValidGroupID(groupid,
"RailTypeMapSpriteGroup"))
continue;
5726 if (ctype >= RTSG_END)
continue;
5729 for (uint i = 0; i < idcount; i++) {
5734 rti->
group[ctype] = _cur.spritegroups[groupid];
5743 static void RoadTypeMapSpriteGroup(
ByteReader *buf, uint8 idcount, RoadTramType rtt)
5747 uint8 *roadtypes =
AllocaM(uint8, idcount);
5748 for (uint i = 0; i < idcount; i++) {
5749 uint8
id = buf->ReadByte();
5753 uint8 cidcount = buf->ReadByte();
5754 for (uint c = 0; c < cidcount; c++) {
5755 uint8 ctype = buf->ReadByte();
5756 uint16 groupid = buf->ReadWord();
5757 if (!IsValidGroupID(groupid,
"RoadTypeMapSpriteGroup"))
continue;
5759 if (ctype >= ROTSG_END)
continue;
5762 for (uint i = 0; i < idcount; i++) {
5767 rti->
group[ctype] = _cur.spritegroups[groupid];
5776 static void AirportMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5778 uint8 *airports =
AllocaM(uint8, idcount);
5779 for (uint i = 0; i < idcount; i++) {
5780 airports[i] = buf->ReadByte();
5784 uint8 cidcount = buf->ReadByte();
5785 buf->Skip(cidcount * 3);
5787 uint16 groupid = buf->ReadWord();
5788 if (!IsValidGroupID(groupid,
"AirportMapSpriteGroup"))
return;
5790 if (_cur.
grffile->airportspec ==
nullptr) {
5791 grfmsg(1,
"AirportMapSpriteGroup: No airports defined, skipping");
5795 for (uint i = 0; i < idcount; i++) {
5798 if (as ==
nullptr) {
5799 grfmsg(1,
"AirportMapSpriteGroup: Airport %d undefined, skipping", airports[i]);
5807 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
5809 uint8 *airptiles =
AllocaM(uint8, idcount);
5810 for (uint i = 0; i < idcount; i++) {
5811 airptiles[i] = buf->ReadByte();
5815 uint8 cidcount = buf->ReadByte();
5816 buf->Skip(cidcount * 3);
5818 uint16 groupid = buf->ReadWord();
5819 if (!IsValidGroupID(groupid,
"AirportTileMapSpriteGroup"))
return;
5821 if (_cur.
grffile->airtspec ==
nullptr) {
5822 grfmsg(1,
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
5826 for (uint i = 0; i < idcount; i++) {
5829 if (airtsp ==
nullptr) {
5830 grfmsg(1,
"AirportTileMapSpriteGroup: Airport tile %d undefined, skipping", airptiles[i]);
5840 static void FeatureMapSpriteGroup(
ByteReader *buf)
5856 uint8 feature = buf->ReadByte();
5857 uint8 idcount = buf->ReadByte();
5859 if (feature >= GSF_END) {
5860 grfmsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x%02X, skipping", feature);
5868 uint16 groupid = buf->ReadWord();
5869 if (!IsValidGroupID(groupid,
"FeatureMapSpriteGroup"))
return;
5871 grfmsg(6,
"FeatureMapSpriteGroup: Adding generic feature callback for feature 0x%02X", feature);
5880 grfmsg(6,
"FeatureMapSpriteGroup: Feature 0x%02X, %d ids", feature, idcount);
5884 case GSF_ROADVEHICLES:
5887 VehicleMapSpriteGroup(buf, feature, idcount);
5891 CanalMapSpriteGroup(buf, idcount);
5895 StationMapSpriteGroup(buf, idcount);
5899 TownHouseMapSpriteGroup(buf, idcount);
5902 case GSF_INDUSTRIES:
5903 IndustryMapSpriteGroup(buf, idcount);
5906 case GSF_INDUSTRYTILES:
5907 IndustrytileMapSpriteGroup(buf, idcount);
5911 CargoMapSpriteGroup(buf, idcount);
5915 AirportMapSpriteGroup(buf, idcount);
5919 ObjectMapSpriteGroup(buf, idcount);
5923 RailTypeMapSpriteGroup(buf, idcount);
5927 RoadTypeMapSpriteGroup(buf, idcount, RTT_ROAD);
5931 RoadTypeMapSpriteGroup(buf, idcount, RTT_TRAM);
5934 case GSF_AIRPORTTILES:
5935 AirportTileMapSpriteGroup(buf, idcount);
5939 grfmsg(1,
"FeatureMapSpriteGroup: Unsupported feature 0x%02X, skipping", feature);
5963 bool new_scheme = _cur.
grffile->grf_version >= 7;
5965 uint8 feature = buf->ReadByte();
5966 if (feature >= GSF_END && feature != 0x48) {
5967 grfmsg(1,
"FeatureNewName: Unsupported feature 0x%02X, skipping", feature);
5971 uint8 lang = buf->ReadByte();
5972 uint8 num = buf->ReadByte();
5973 bool generic =
HasBit(lang, 7);
5976 id = buf->ReadWord();
5977 }
else if (feature <= GSF_AIRCRAFT) {
5978 id = buf->ReadExtendedByte();
5980 id = buf->ReadByte();
5985 uint16 endid =
id + num;
5987 grfmsg(6,
"FeatureNewName: About to rename engines %d..%d (feature 0x%02X) in language 0x%02X",
5988 id, endid, feature, lang);
5990 for (;
id < endid && buf->HasData();
id++) {
5991 const char *name = buf->ReadString();
5992 grfmsg(8,
"FeatureNewName: 0x%04X <- %s",
id, name);
5996 case GSF_ROADVEHICLES:
6001 if (e ==
nullptr)
break;
6015 switch (
GB(
id, 8, 8)) {
6017 if (_cur.
grffile->stations ==
nullptr || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6018 grfmsg(1,
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring",
GB(
id, 0, 8));
6026 if (_cur.
grffile->stations ==
nullptr || _cur.
grffile->stations[
GB(
id, 0, 8)] ==
nullptr) {
6027 grfmsg(1,
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring",
GB(
id, 0, 8));
6034 if (_cur.
grffile->airtspec ==
nullptr || _cur.
grffile->airtspec[
GB(
id, 0, 8)] ==
nullptr) {
6035 grfmsg(1,
"FeatureNewName: Attempt to name undefined airport tile 0x%X, ignoring",
GB(
id, 0, 8));
6042 if (_cur.
grffile->housespec ==
nullptr || _cur.
grffile->housespec[
GB(
id, 0, 8)] ==
nullptr) {
6043 grfmsg(1,
"FeatureNewName: Attempt to name undefined house 0x%X, ignoring.",
GB(
id, 0, 8));
6050 grfmsg(7,
"FeatureNewName: Unsupported ID (0x%04X)",
id);
6069 if (offset >= max_sprites) {
6070 grfmsg(1,
"GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
6071 uint orig_num = num;
6076 if (offset + num > max_sprites) {
6077 grfmsg(4,
"GraphicsNew: %s sprite overflow, truncating...", name);
6078 uint orig_num = num;
6079 num =
max(max_sprites - offset, 0);
6080 return orig_num - num;
6109 {
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,
"Signal graphics" },
6111 {
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT,
"Foundation graphics" },
6141 uint8 type = buf->ReadByte();
6142 uint16 num = buf->ReadExtendedByte();
6143 uint16 offset =
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
6149 grfmsg(2,
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
6166 grfmsg(2,
"GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
6171 const Action5Type *action5_type = &_action5_types[type];
6177 grfmsg(1,
"GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
6184 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);
6194 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);
6205 for (; num > 0; num--) {
6276 *value = (major << 24) | (minor << 20) | (revision << 16) | build;
6306 *value = _game_mode;
6340 *value =
Clamp(snowline * (grffile->grf_version >= 8 ? 1 :
TILE_HEIGHT), 0, 0xFE);
6349 *value = _openttd_newgrf_version;
6364 default:
return false;
6368 static uint32 GetParamVal(byte param, uint32 *cond_val)
6386 if (cond_val ==
nullptr) {
6390 uint32 index = *cond_val / 0x20;
6406 grfmsg(1,
"Unsupported in-game variable 0x%02X", param);
6429 byte *preload_sprite =
nullptr;
6433 preload_sprite = MallocT<byte>(num);
6441 grfmsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
6442 free(preload_sprite);
6447 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
6448 if (it != _grf_line_to_action6_sprite_override.end()) {
6449 free(preload_sprite);
6450 preload_sprite = _grf_line_to_action6_sprite_override[location];
6452 _grf_line_to_action6_sprite_override[location] = preload_sprite;
6465 param_num = buf->ReadByte();
6466 if (param_num == 0xFF)
break;
6470 param_size = buf->ReadByte();
6474 add_value =
HasBit(param_size, 7);
6475 param_size =
GB(param_size, 0, 7);
6478 offset = buf->ReadExtendedByte();
6482 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
6483 grfmsg(2,
"CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
6487 grfmsg(8,
"CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
6490 for (i = 0; i < param_size && offset + i < num; i++) {
6491 uint32 value = GetParamVal(param_num + i / 4,
nullptr);
6494 if (i % 4 == 0) carry =
false;
6497 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
6498 preload_sprite[offset + i] =
GB(new_value, 0, 8);
6500 carry = new_value >= 256;
6502 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
6534 uint32 cond_val = 0;
6538 uint8 param = buf->ReadByte();
6539 uint8 paramsize = buf->ReadByte();
6540 uint8 condtype = buf->ReadByte();
6547 switch (paramsize) {
6548 case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord();
break;
6549 case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF;
break;
6550 case 2: cond_val = buf->ReadWord(); mask = 0x0000FFFF;
break;
6551 case 1: cond_val = buf->ReadByte(); mask = 0x000000FF;
break;
6555 if (param < 0x80 && _cur.grffile->param_end <= param) {
6556 grfmsg(7,
"SkipIf: Param %d undefined, skipping test", param);
6560 uint32 param_val = GetParamVal(param, &cond_val);
6562 grfmsg(7,
"SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
6572 if (param == 0x88 && (condtype < 0x0B || condtype > 0x0E)) {
6582 if (condtype != 10 && c ==
nullptr) {
6583 grfmsg(7,
"SkipIf: GRFID 0x%08X unknown, skipping test",
BSWAP32(cond_val));
6610 default:
grfmsg(1,
"SkipIf: Unsupported GRF condition type %02X. Ignoring", condtype);
return;
6615 case 0x00: result = !!(param_val & (1 << cond_val));
6617 case 0x01: result = !(param_val & (1 << cond_val));
6619 case 0x02: result = (param_val & mask) == cond_val;
6621 case 0x03: result = (param_val & mask) != cond_val;
6623 case 0x04: result = (param_val & mask) < cond_val;
6625 case 0x05: result = (param_val & mask) > cond_val;
6655 default:
grfmsg(1,
"SkipIf: Unsupported condition type %02X. Ignoring", condtype);
return;
6660 grfmsg(2,
"SkipIf: Not skipping sprites, test was false");
6664 uint8 numsprites = buf->ReadByte();
6672 if (label->label != numsprites)
continue;
6675 if (choice ==
nullptr) choice = label;
6677 if (label->nfo_line > _cur.
nfo_line) {
6683 if (choice !=
nullptr) {
6684 grfmsg(2,
"SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line);
6690 grfmsg(2,
"SkipIf: Skipping %d sprites, test was true", numsprites);
6709 uint8 grf_version = buf->ReadByte();
6710 uint32 grfid = buf->ReadDWord();
6711 const char *name = buf->ReadString();
6715 if (grf_version < 2 || grf_version > 8) {
6717 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);
6725 if (buf->HasData()) {
6726 const char *info = buf->ReadString();
6744 uint8 version = buf->ReadByte();
6745 uint32 grfid = buf->ReadDWord();
6746 const char *name = buf->ReadString();
6749 DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
6753 if (_cur.
grffile->grfid != grfid) {
6754 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));
6758 _cur.
grffile->grf_version = version;
6776 uint8 num_sets = buf->ReadByte();
6778 for (uint i = 0; i < num_sets; i++) {
6780 uint16 first_sprite = buf->ReadWord();
6782 grfmsg(2,
"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
6783 i, num_sprites, first_sprite
6787 int load_index = first_sprite + j;
6793 if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
6803 uint8 num_sets = buf->ReadByte();
6805 for (uint i = 0; i < num_sets; i++) {
6834 STR_NEWGRF_ERROR_VERSION_NUMBER,
6835 STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
6836 STR_NEWGRF_ERROR_UNSET_SWITCH,
6837 STR_NEWGRF_ERROR_INVALID_PARAMETER,
6838 STR_NEWGRF_ERROR_LOAD_BEFORE,
6839 STR_NEWGRF_ERROR_LOAD_AFTER,
6840 STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
6844 STR_NEWGRF_ERROR_MSG_INFO,
6845 STR_NEWGRF_ERROR_MSG_WARNING,
6846 STR_NEWGRF_ERROR_MSG_ERROR,
6847 STR_NEWGRF_ERROR_MSG_FATAL
6850 byte severity = buf->ReadByte();
6851 byte lang = buf->ReadByte();
6852 byte message_id = buf->ReadByte();
6855 if (!CheckGrfLangID(lang, _cur.
grffile->grf_version))
return;
6859 if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
6860 grfmsg(7,
"GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur.
stage);
6865 if (severity >=
lengthof(sevstr)) {
6866 grfmsg(7,
"GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity);
6868 }
else if (severity == 3) {
6878 if (message_id >=
lengthof(msgstr) && message_id != 0xFF) {
6879 grfmsg(7,
"GRFLoadError: Invalid message id.");
6883 if (buf->Remaining() <= 1) {
6884 grfmsg(7,
"GRFLoadError: No message data supplied.");
6893 if (message_id == 0xFF) {
6895 if (buf->HasData()) {
6896 const char *message = buf->ReadString();
6900 grfmsg(7,
"GRFLoadError: No custom message supplied.");
6904 error->
message = msgstr[message_id];
6907 if (buf->HasData()) {
6908 const char *data = buf->ReadString();
6912 grfmsg(7,
"GRFLoadError: No message data supplied.");
6918 uint param_number = buf->ReadByte();
6932 if (!buf->HasData())
return;
6934 const char *text = buf->ReadString();
6935 grfmsg(2,
"GRFComment: %s", text);
6941 uint8 target = buf->ReadByte();
6944 if (target < 0x80 || target == 0x9E)
return;
6958 static uint32 GetPatchVariable(uint8 param)
6968 case 0x0F:
return 0;
6984 case 0x11:
return SPR_2CCMAP_BASE;
7001 byte max_edge =
max(log_X, log_Y);
7003 if (log_X == log_Y) {
7006 if (max_edge == log_Y)
SetBit(map_bits, 1);
7009 return (map_bits << 24) | (
min(log_X, log_Y) << 20) | (max_edge << 16) |
7010 (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
7019 return SPR_SLOPES_BASE;
7026 grfmsg(2,
"ParamSet: Unknown Patch variable 0x%02X.", param);
7032 static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target,
const char *type)
7045 for (uint i = start; i < num_ids; i++) {
7049 if (op == 2 || op == 3)
break;
7054 if (size == count)
break;
7057 if (size == count) {
7059 if (op == 0 || op == 3) {
7060 grfmsg(2,
"ParamSet: GRM: Reserving %d %s at %d", count, type, start);
7061 for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
7067 if (op != 4 && op != 5) {
7069 grfmsg(0,
"ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
7074 grfmsg(1,
"ParamSet: GRM: Unable to allocate %d %s", count, type);
7104 uint8 target = buf->ReadByte();
7105 uint8 oper = buf->ReadByte();
7106 uint32 src1 = buf->ReadByte();
7107 uint32 src2 = buf->ReadByte();
7110 if (buf->Remaining() >= 4) data = buf->ReadDWord();
7119 if (target < 0x80 && target < _cur.grffile->param_end) {
7120 grfmsg(7,
"ParamSet: Param %u already defined, skipping", target);
7124 oper =
GB(oper, 0, 7);
7128 if (
GB(data, 0, 8) == 0xFF) {
7129 if (data == 0x0000FFFF) {
7131 src1 = GetPatchVariable(src1);
7135 uint8 feature =
GB(data, 8, 8);
7136 uint16 count =
GB(data, 16, 16);
7138 if (_cur.
stage == GLS_RESERVE) {
7139 if (feature == 0x08) {
7143 if (_cur.
spriteid + count >= 16384) {
7144 grfmsg(0,
"ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
7150 grfmsg(4,
"ParamSet: GRM: Allocated %d sprites at %d", count, _cur.
spriteid);
7157 }
else if (_cur.
stage == GLS_ACTIVATION) {
7186 grfmsg(4,
"ParamSet: GRM: Using pre-allocated sprites at %d", src1);
7194 grfmsg(1,
"ParamSet: GRM: Unsupported operation %d for general sprites", op);
7205 default:
grfmsg(1,
"ParamSet: GRM: Unsupported feature 0x%X", feature);
return;
7222 }
else if (src1 == 0xFE) {
7234 src1 = (src1 == 0xFF) ? data : GetParamVal(src1,
nullptr);
7235 src2 = (src2 == 0xFF) ? data : GetParamVal(src2,
nullptr);
7257 res = (int32)src1 * (int32)src2;
7261 if ((int32)src2 < 0) {
7262 res = src1 >> -(int32)src2;
7264 res = src1 << (src2 & 0x1F);
7269 if ((int32)src2 < 0) {
7270 res = (int32)src1 >> -(int32)src2;
7272 res = (int32)src1 << (src2 & 0x1F);
7296 res = (int32)src1 / (int32)src2;
7312 res = (int32)src1 % (int32)src2;
7316 default:
grfmsg(0,
"ParamSet: Unknown operation %d, skipping", oper);
return;
7345 grfmsg(7,
"ParamSet: Skipping unimplemented target 0x%02X", target);
7356 uint32 safe_bits = 0;
7357 SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
7366 grfmsg(7,
"ParamSet: Skipping unimplemented target 0x%02X", target);
7370 if (target < 0x80) {
7371 _cur.
grffile->param[target] = res;
7375 grfmsg(7,
"ParamSet: Skipping unknown target 0x%02X", target);
7389 uint8 num = buf->ReadByte();
7391 for (uint i = 0; i < num; i++) {
7392 uint32 grfid = buf->ReadDWord();
7414 uint8 num = buf->ReadByte();
7416 for (uint i = 0; i < num; i++) {
7417 uint32 grfid = buf->ReadDWord();
7421 if (file !=
nullptr && file != _cur.
grfconfig) {
7439 uint32 grfid = _cur.
grffile->grfid;
7443 byte
id = buf->ReadByte();
7444 grfmsg(6,
"FeatureTownName: definition 0x%02X",
id & 0x7F);
7449 bool new_scheme = _cur.
grffile->grf_version >= 7;
7451 byte lang = buf->ReadByte();
7453 byte nb_gen = townname->nb_gen;
7457 const char *name = buf->ReadString();
7460 grfmsg(6,
"FeatureTownName: lang 0x%X -> '%s'", lang, lang_name);
7463 townname->name[nb_gen] =
AddGRFString(grfid,
id, lang, new_scheme,
false, name, STR_UNDEFINED);
7465 lang = buf->ReadByte();
7466 }
while (lang != 0);
7467 townname->id[nb_gen] = id;
7471 byte nb = buf->ReadByte();
7472 grfmsg(6,
"FeatureTownName: %u parts", nb);
7474 townname->nbparts[id] = nb;
7475 townname->partlist[id] = CallocT<NamePartList>(nb);
7477 for (
int i = 0; i < nb; i++) {
7478 byte nbtext = buf->ReadByte();
7479 townname->partlist[id][i].bitstart = buf->ReadByte();
7480 townname->partlist[id][i].bitcount = buf->ReadByte();
7481 townname->partlist[id][i].maxprob = 0;
7482 townname->partlist[id][i].partcount = nbtext;
7483 townname->partlist[id][i].parts = CallocT<NamePart>(nbtext);
7484 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);
7486 for (
int j = 0; j < nbtext; j++) {
7487 byte prob = buf->ReadByte();
7490 byte ref_id = buf->ReadByte();
7492 if (townname->nbparts[ref_id] == 0) {
7493 grfmsg(0,
"FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
7494 DelGRFTownName(grfid);
7499 grfmsg(6,
"FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
7500 townname->partlist[id][i].parts[j].data.
id = ref_id;
7502 const char *text = buf->ReadString();
7504 grfmsg(6,
"FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[
id][i].parts[j].data.
text, prob);
7506 townname->partlist[id][i].parts[j].
prob = prob;
7507 townname->partlist[id][i].maxprob +=
GB(prob, 0, 7);
7509 grfmsg(6,
"FeatureTownName: part %d, total probability %d", i, townname->partlist[
id][i].maxprob);
7521 byte nfo_label = buf->ReadByte();
7523 GRFLabel *label = MallocT<GRFLabel>(1);
7524 label->label = nfo_label;
7527 label->next =
nullptr;
7535 for (l = _cur.
grffile->
label; l->next !=
nullptr; l = l->next) {}
7539 grfmsg(2,
"DefineGotoLabel: GOTO target with label 0x%02X", label->label);
7553 if (file ==
nullptr || file->sound_offset == 0) {
7554 grfmsg(1,
"ImportGRFSound: Source file not available");
7558 if (sound_id >= file->num_sounds) {
7559 grfmsg(1,
"ImportGRFSound: Sound effect %d is invalid", sound_id);
7563 grfmsg(2,
"ImportGRFSound: Copying sound %d (%d) from file %X", sound_id, file->sound_offset + sound_id, grfid);
7565 *sound = *GetSound(file->sound_offset + sound_id);
7568 sound->volume = 128;
7569 sound->priority = 0;
7580 sound->volume = 0x80;
7581 sound->priority = 0;
7583 if (offs != SIZE_MAX) {
7586 sound->file_offset = offs;
7598 uint16 num = buf->ReadWord();
7599 if (num == 0)
return;
7602 if (_cur.
grffile->sound_offset == 0) {
7603 _cur.
grffile->sound_offset = GetNumSounds();
7604 _cur.
grffile->num_sounds = num;
7607 sound = GetSound(_cur.
grffile->sound_offset);
7610 for (
int i = 0; i < num; i++) {
7615 bool invalid = i >= _cur.
grffile->num_sounds;
7625 grfmsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7627 }
else if (len != 4) {
7628 grfmsg(1,
"GRFSound: Invalid sprite section import");
7638 grfmsg(1,
"GRFSound: Unexpected RealSprite found, skipping");
7645 grfmsg(1,
"GRFSound: Sound index out of range (multiple Action 11?)");
7653 if (_cur.
stage == GLS_INIT) {
7655 grfmsg(1,
"GRFSound: Inline sounds are not supported for container version >= 2");
7664 if (_cur.
stage == GLS_ACTIVATION) {
7675 grfmsg(1,
"GRFSound: Unexpected Action %x found, skipping", action);
7704 uint8 num_def = buf->ReadByte();
7706 for (uint i = 0; i < num_def; i++) {
7708 uint8 num_char = buf->ReadByte();
7709 uint16 base_char = buf->ReadWord();
7711 if (size >= FS_END) {
7712 grfmsg(1,
"LoadFontGlyph: Size %u is not supported, ignoring", size);
7715 grfmsg(7,
"LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
7717 for (uint c = 0; c < num_char; c++) {
7735 uint8 num_def = buf->ReadByte();
7737 for (uint i = 0; i < num_def; i++) {
7761 uint32 grfid = buf->ReadDWord();
7764 grfmsg(7,
"TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13",
BSWAP32(grfid));
7774 GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE,
lastof(tmp));
7785 byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
7786 byte num_strings = buf->ReadByte();
7787 uint16 first_id = buf->ReadWord();
7789 if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) {
7790 grfmsg(7,
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
7794 for (uint i = 0; i < num_strings && buf->HasData(); i++) {
7795 const char *
string = buf->ReadString();
7798 grfmsg(7,
"TranslateGRFString: Ignoring empty string.");
7802 AddGRFString(grfid, first_id + i, language,
true,
true,
string, STR_UNDEFINED);
7831 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE
", ignoring this field", len);
7843 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got " PRINTF_SIZE
", ignoring this field", len);
7846 char data = buf->ReadByte();
7854 grfmsg(2,
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data);
7869 grfmsg(2,
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got " PRINTF_SIZE
", ignoring this field", len);
7872 char data = buf->ReadByte();
7878 grfmsg(2,
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'BLTR', ignoring this field", data);
7891 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got " PRINTF_SIZE
", ignoring this field", len);
7904 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got " PRINTF_SIZE
", ignoring this field", len);
7909 grfmsg(2,
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
7940 grfmsg(2,
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got " PRINTF_SIZE
", ignoring this field", len);
7945 _cur_parameter->
type = type;
7947 grfmsg(3,
"StaticGRFInfo: unknown parameter type %d, ignoring this field", type);
7957 grfmsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
7959 }
else if (len != 8) {
7960 grfmsg(2,
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got " PRINTF_SIZE
", ignoring this field", len);
7963 uint32 min_value = buf->ReadDWord();
7964 uint32 max_value = buf->ReadDWord();
7965 if (min_value <= max_value) {
7969 grfmsg(2,
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field");
7978 if (len < 1 || len > 3) {
7979 grfmsg(2,
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got " PRINTF_SIZE
", ignoring this field", len);
7982 byte param_nr = buf->ReadByte();
7984 grfmsg(2,
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param %d, ignoring this field", param_nr);
7987 _cur_parameter->
param_nr = param_nr;
7988 if (len >= 2) _cur_parameter->
first_bit =
min(buf->ReadByte(), 31);
7989 if (len >= 3) _cur_parameter->
num_bit =
min(buf->ReadByte(), 32 - _cur_parameter->
first_bit);
8000 grfmsg(2,
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got " PRINTF_SIZE
", ignoring this field", len);
8003 _cur_parameter->
def_value = buf->ReadDWord();
8036 this->handler.data = handler;
8048 this->handler.text = handler;
8060 this->handler.call_handler =
true;
8061 this->handler.u.branch = handler;
8073 this->handler.call_handler =
false;
8074 this->handler.u.subtags = subtags;
8103 byte type = buf->ReadByte();
8105 uint32
id = buf->ReadDWord();
8106 if (type !=
'T' ||
id > _cur_parameter->
max_value) {
8107 grfmsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
8109 type = buf->ReadByte();
8113 byte langid = buf->ReadByte();
8114 const char *name_string = buf->ReadString();
8117 if (val_name != _cur_parameter->
value_names.End()) {
8125 type = buf->ReadByte();
8150 byte type = buf->ReadByte();
8152 uint32
id = buf->ReadDWord();
8154 grfmsg(2,
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
8156 type = buf->ReadByte();
8168 if (!
HandleNodes(buf, _tags_parameters))
return false;
8169 type = buf->ReadByte();
8206 byte new_type = buf->ReadByte();
8207 while (new_type != 0) {
8210 new_type = buf->ReadByte();
8221 uint16 size = buf->ReadWord();
8245 while ((tag = &subtags[i++])->type != 0) {
8248 default: NOT_REACHED();
8251 byte langid = buf->ReadByte();
8252 return tag->handler.
text(langid, buf->ReadString());
8256 size_t len = buf->ReadWord();
8257 if (buf->Remaining() < len)
return false;
8258 return tag->handler.
data(len, buf);
8263 return tag->handler.u.branch(buf);
8269 grfmsg(2,
"StaticGRFInfo: unknown type/id combination found, type=%c, id=%x", type,
id);
8281 byte type = buf->ReadByte();
8283 uint32
id = buf->ReadDWord();
8284 if (!
HandleNode(type,
id, buf, subtags))
return false;
8285 type = buf->ReadByte();
8406 if (stations ==
nullptr)
continue;
8408 if (stations[i] ==
nullptr)
continue;
8414 if (!statspec->copied_layouts) {
8415 for (uint l = 0; l < statspec->lengths; l++) {
8416 for (uint p = 0; p < statspec->platforms[l]; p++) {
8417 free(statspec->layouts[l][p]);
8419 free(statspec->layouts[l]);
8421 free(statspec->layouts);
8422 free(statspec->platforms);
8439 HouseSpec **&housespec = file->housespec;
8440 if (housespec ==
nullptr)
continue;
8446 housespec =
nullptr;
8455 if (aslist !=
nullptr) {
8459 if (as !=
nullptr) {
8461 for (
int j = 0; j < as->
num_table; j++) {
8473 file->airportspec =
nullptr;
8477 if (airporttilespec !=
nullptr) {
8479 free(airporttilespec[i]);
8481 free(airporttilespec);
8482 airporttilespec =
nullptr;
8496 if (industryspec !=
nullptr) {
8503 industryspec =
nullptr;
8506 if (indtspec ==
nullptr)
continue;
8521 if (objectspec ==
nullptr)
continue;
8523 free(objectspec[i]);
8527 objectspec =
nullptr;
8559 CleanUpGRFTownNames();
8603 ObjectClass::Reset();
8608 StationClass::Reset();
8612 AirportClass::Reset();
8635 _loaded_newgrf_features.
has_2CC =
false;
8643 _grf_id_overrides.clear();
8645 InitializeSoundPool();
8693 if (newfile !=
nullptr) {
8699 newfile =
new GRFFile(config);
8713 this->traininfo_vehicle_pitch = 0;
8714 this->traininfo_vehicle_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
8717 for (
Price i = PR_BEGIN; i < PR_END; i++) {
8718 this->price_base_multipliers[i] = INVALID_PRICE_MODIFIER;
8742 if (this->param_end > 0) {
8749 free(this->filename);
8750 delete[] this->language_map;
8759 'PASS',
'COAL',
'MAIL',
'LVST',
'GOOD',
'GRAI',
'WHEA',
'MAIZ',
'WOOD',
8760 'IORE',
'STEL',
'VALU',
'GOLD',
'DIAM',
'PAPR',
'FOOD',
'FRUT',
'CORE',
8761 'WATR',
'SUGR',
'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
8765 static const CargoLabel _default_refitmasks_road[] = {
8768 static const CargoLabel _default_refitmasks_ships[] = {
8769 'COAL',
'MAIL',
'LVST',
'GOOD',
'GRAI',
'WHEA',
'MAIZ',
'WOOD',
'IORE',
8770 'STEL',
'VALU',
'GOLD',
'DIAM',
'PAPR',
'FOOD',
'FRUT',
'CORE',
'WATR',
8771 'RUBR',
'SUGR',
'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
8775 static const CargoLabel _default_refitmasks_aircraft[] = {
8776 'PASS',
'MAIL',
'GOOD',
'VALU',
'GOLD',
'DIAM',
'FOOD',
'FRUT',
'SUGR',
8777 'TOYS',
'BATT',
'SWET',
'TOFF',
'COLA',
'CTCD',
'BUBL',
'PLST',
'FZDR',
8780 static const CargoLabel *
const _default_refitmasks[] = {
8782 _default_refitmasks_road,
8783 _default_refitmasks_ships,
8784 _default_refitmasks_aircraft,
8796 bool only_defaultcargo;
8800 CargoTypes mask = 0;
8801 CargoTypes not_mask = 0;
8802 CargoTypes xor_mask = ei->refit_mask;
8808 if (_gted[engine].cargo_allowed != 0) {
8811 FOR_ALL_CARGOSPECS(cs) {
8817 ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) &
_cargo_mask;
8823 CargoTypes xor_mask = 0;
8827 const CargoLabel *cl = _default_refitmasks[e->type];
8828 for (uint i = 0;; i++) {
8829 if (cl[i] == 0)
break;
8841 only_defaultcargo = (ei->refit_mask == 0);
8849 if (!only_defaultcargo && (e->type !=
VEH_SHIP || e->u.ship.old_refittable) && ei->cargo_type !=
CT_INVALID && !
HasBit(ei->refit_mask, ei->cargo_type)) {
8855 if (ei->cargo_type ==
CT_INVALID && ei->refit_mask != 0) {
8857 const uint8 *cargo_map_for_first_refittable =
nullptr;
8860 if (file ==
nullptr) file = e->GetGRF();
8861 if (file !=
nullptr && file->grf_version >= 8 && file->
cargo_list.size() != 0) {
8862 cargo_map_for_first_refittable = file->
cargo_map;
8866 if (cargo_map_for_first_refittable !=
nullptr) {
8868 byte best_local_slot = 0xFF;
8870 FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) {
8871 byte local_slot = cargo_map_for_first_refittable[cargo_type];
8872 if (local_slot < best_local_slot) {
8873 best_local_slot = local_slot;
8874 ei->cargo_type = cargo_type;
8887 if (e->type ==
VEH_SHIP && !e->u.ship.old_refittable) {
8896 for (uint i = 0; i < CF_END; i++) {
8908 if (e->GetGRF() ==
nullptr) {
8911 e->info.string_id = STR_NEWGRF_INVALID_ENGINE;
8920 if (e->type ==
VEH_TRAIN && !_gted[e->index].
prop27_set && e->GetGRF() !=
nullptr && is_custom_sprite(e->u.rail.image_index)) {
8946 default: NOT_REACHED();
8960 cs->
quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
8961 cs->
abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
8985 if (filename !=
nullptr)
DEBUG(grf, 1,
"FinaliseHouseArray: %s defines house %d as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
8995 if (filename !=
nullptr)
DEBUG(grf, 1,
"FinaliseHouseArray: %s defines multitile house %d with non-zero population on additional tiles. Disabling house.", filename, hs->
grf_prop.
local_id);
9003 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);
9010 if (filename !=
nullptr)
DEBUG(grf, 1,
"FinaliseHouseArray: %s defines house %d without a size but marked it as available. Disabling house.", filename, hs->
grf_prop.
local_id);
9029 if (hs ==
nullptr || !hs->
enabled)
continue;
9034 if (min_year == 0)
return;
9038 if (hs ==
nullptr || !hs->
enabled)
continue;
9062 HouseSpec **&housespec = file->housespec;
9063 if (housespec ==
nullptr)
continue;
9068 if (hs ==
nullptr)
continue;
9070 const HouseSpec *next1 = (i + 1 < NUM_HOUSES_PER_GRF ? housespec[i + 1] :
nullptr);
9071 const HouseSpec *next2 = (i + 2 < NUM_HOUSES_PER_GRF ? housespec[i + 2] :
nullptr);
9072 const HouseSpec *next3 = (i + 3 < NUM_HOUSES_PER_GRF ? housespec[i + 3] :
nullptr);
9082 const HouseSpec *next1 = (i + 1 < NUM_HOUSES ? HouseSpec::Get(i + 1) :
nullptr);
9083 const HouseSpec *next2 = (i + 2 < NUM_HOUSES ? HouseSpec::Get(i + 2) :
nullptr);
9084 const HouseSpec *next3 = (i + 3 < NUM_HOUSES ? HouseSpec::Get(i + 3) :
nullptr);
9126 if (industryspec !=
nullptr) {
9130 if (indsp !=
nullptr && indsp->
enabled) {
9136 if (strid != STR_UNDEFINED) indsp->
name = strid;
9139 if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
9154 if (strid != STR_UNDEFINED) indsp->
station_name = strid;
9163 if (indtspec !=
nullptr) {
9166 if (indtsp !=
nullptr) {
9167 _industile_mngr.SetEntitySpec(indtsp);
9176 for (uint i = 0; i < 3; i++) {
9181 indsp->
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
9195 if (objectspec !=
nullptr) {
9197 if (objectspec[i] !=
nullptr && objectspec[i]->grf_prop.grffile !=
nullptr && objectspec[i]->
enabled) {
9214 if (airportspec !=
nullptr) {
9216 if (airportspec[i] !=
nullptr && airportspec[i]->enabled) {
9217 _airport_mngr.SetEntitySpec(airportspec[i]);
9223 if (airporttilespec !=
nullptr) {
9225 if (airporttilespec[i] !=
nullptr && airporttilespec[i]->enabled) {
9226 _airporttile_mngr.SetEntitySpec(airporttilespec[i]);
9239 static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage
stage)
9253 static const SpecialSpriteHandler handlers[][GLS_END] = {
9254 {
nullptr, SafeChangeInfo,
nullptr,
nullptr, ReserveChangeInfo, FeatureChangeInfo, },
9255 { SkipAct1, SkipAct1, SkipAct1, SkipAct1, SkipAct1, NewSpriteSet, },
9256 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, NewSpriteGroup, },
9257 {
nullptr,
GRFUnsafe,
nullptr,
nullptr,
nullptr, FeatureMapSpriteGroup, },
9258 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, FeatureNewName, },
9259 { SkipAct5, SkipAct5, SkipAct5, SkipAct5, SkipAct5, GraphicsNew, },
9260 {
nullptr,
nullptr,
nullptr, CfgApply, CfgApply, CfgApply, },
9261 {
nullptr,
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, },
9262 { ScanInfo,
nullptr,
nullptr, GRFInfo, GRFInfo, GRFInfo, },
9263 {
nullptr,
nullptr,
nullptr, SkipIf, SkipIf, SkipIf, },
9264 { SkipActA, SkipActA, SkipActA, SkipActA, SkipActA, SpriteReplace, },
9265 {
nullptr,
nullptr,
nullptr, GRFLoadError, GRFLoadError, GRFLoadError, },
9266 {
nullptr,
nullptr,
nullptr, GRFComment,
nullptr, GRFComment, },
9268 {
nullptr, SafeGRFInhibit,
nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
9271 { SkipAct11,
GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
9274 {
StaticGRFInfo,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
9279 GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
9280 if (it == _grf_line_to_action6_sprite_override.end()) {
9286 buf = _grf_line_to_action6_sprite_override[location];
9287 grfmsg(7,
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
9297 byte action = bufp->ReadByte();
9299 if (action == 0xFF) {
9300 grfmsg(2,
"DecodeSpecialSprite: Unexpected data block, skipping");
9301 }
else if (action == 0xFE) {
9302 grfmsg(2,
"DecodeSpecialSprite: Unexpected import block, skipping");
9303 }
else if (action >=
lengthof(handlers)) {
9304 grfmsg(7,
"DecodeSpecialSprite: Skipping unknown action 0x%02X", action);
9305 }
else if (handlers[action][stage] ==
nullptr) {
9306 grfmsg(7,
"DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage);
9308 grfmsg(7,
"DecodeSpecialSprite: Handling action 0x%02X in stage %d", action, stage);
9309 handlers[action][
stage](bufp);
9312 grfmsg(1,
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
9319 extern const byte
_grf_cont_v2_sig[8] = {
'G',
'R',
'F', 0x82, 0x0D, 0x0A, 0x1A, 0x0A};
9353 const char *filename = config->
filename;
9364 if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
9366 if (_cur.
grffile ==
nullptr)
usererror(
"File '%s' lost in cache.\n", filename);
9372 DEBUG(grf, 0,
"'%s' is not loaded as the maximum number of file slots has been reached", filename);
9374 config->
error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
9384 DEBUG(grf, 2,
"LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
9388 DEBUG(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9392 if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
9404 if (compression != 0) {
9405 DEBUG(grf, 7,
"LoadNewGRFFile: Unsupported compression format");
9417 DEBUG(grf, 7,
"LoadNewGRFFile: Custom .grf has invalid format");
9442 grfmsg(0,
"LoadNewGRFFile: Unexpected sprite, disabling");
9443 DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
9507 DupSprite(SPR_ROAD_DEPOT + 0, SPR_TRAMWAY_DEPOT_NO_TRACK + 0);
9508 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 1, SPR_TRAMWAY_DEPOT_NO_TRACK + 1);
9509 DupSprite(SPR_ROAD_DEPOT + 2, SPR_TRAMWAY_DEPOT_NO_TRACK + 2);
9510 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 3, SPR_TRAMWAY_DEPOT_NO_TRACK + 3);
9511 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 4, SPR_TRAMWAY_DEPOT_NO_TRACK + 4);
9512 DupSprite(SPR_TRAMWAY_DEPOT_WITH_TRACK + 5, SPR_TRAMWAY_DEPOT_NO_TRACK + 5);
9523 static const uint32 override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
9527 int *grf_overrides =
AllocaM(
int, num_grfs);
9528 for (
int i = 0; i < num_grfs; i++) {
9529 grf_overrides[i] = -1;
9532 uint32
override = _grf_id_overrides[source->grfid];
9533 if (
override == 0)
continue;
9536 if (dest ==
nullptr)
continue;
9539 assert(grf_overrides[i] >= 0);
9543 for (
int i = 0; i < num_grfs; i++) {
9544 if (grf_overrides[i] < 0 || grf_overrides[i] >= i)
continue;
9552 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9555 DEBUG(grf, 3,
"'%s' overrides price base multiplier %d of '%s'", source->filename, p, dest->filename);
9561 for (
int i = num_grfs - 1; i >= 0; i--) {
9562 if (grf_overrides[i] < 0 || grf_overrides[i] <= i)
continue;
9570 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9573 DEBUG(grf, 3,
"Price base multiplier %d from '%s' propagated to '%s'", p, source->filename, dest->filename);
9579 for (
int i = 0; i < num_grfs; i++) {
9580 if (grf_overrides[i] < 0)
continue;
9588 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9589 if (!
HasBit(features, _price_base_specs[p].grf_feature))
continue;
9591 DEBUG(grf, 3,
"Price base multiplier %d from '%s' propagated to '%s'", p, dest->filename, source->filename);
9599 if (file->grf_version >= 8)
continue;
9600 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9601 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9603 if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9606 price_base_multipliers[p] = price_base_multipliers[fallback_price];
9612 for (
GRFFile *
const file : _grf_files) {
9613 PriceMultipliers &price_base_multipliers = file->price_base_multipliers;
9614 for (
Price p = PR_BEGIN; p < PR_END; p++) {
9615 if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
9617 price_base_multipliers[p] = 0;
9622 DEBUG(grf, 3,
"'%s' sets global price base multiplier %d", file->filename, p);
9624 price_base_multipliers[p] = 0;
9626 DEBUG(grf, 3,
"'%s' sets local price base multiplier %d", file->filename, p);
9641 _string_to_grf_mapping.clear();
9644 for (GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.begin(); it != _grf_line_to_action6_sprite_override.end(); it++) {
9647 _grf_line_to_action6_sprite_override.clear();
9704 e->u.road.max_speed = _gted[e->index].
rv_max_speed * 4;
9709 const GRFFile *file = e->GetGRF();
9710 if (file ==
nullptr || _gted[e->index].roadtramtype == 0) {
9716 _gted[e->index].roadtramtype--;
9718 const std::vector<RoadTypeLabel> *list = (rtt == RTT_TRAM) ? &file->tramtype_list : &file->
roadtype_list;
9719 if (_gted[e->index].roadtramtype < list->size())
9721 RoadTypeLabel rtl = (*list)[_gted[e->index].roadtramtype];
9724 e->u.road.roadtype = rt;
9730 e->info.climates = 0;
9737 e->info.climates = 0;
9739 e->u.rail.railtype = railtype;
9749 _grm_sprites.clear();
9798 for (GrfLoadingStage
stage = GLS_LABELSCAN;
stage <= GLS_ACTIVATION;
stage++) {
9805 if (
stage == GLS_RESERVE) {
9806 static const uint32 overrides[][2] = {
9807 { 0x44442202, 0x44440111 },
9808 { 0x6D620402, 0x6D620401 },
9809 { 0x4D656f20, 0x4D656F17 },
9811 for (
size_t i = 0; i <
lengthof(overrides); i++) {
9817 uint num_non_static = 0;
9826 DEBUG(grf, 0,
"NewGRF file is missing '%s'; disabling", c->filename);
9835 DEBUG(grf, 0,
"'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->filename);
9837 c->error =
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
9843 if (
stage == GLS_RESERVE) {
9845 }
else if (
stage == GLS_ACTIVATION) {
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 accepted cargoes.
void ResetBridges()
Reset the data been eventually changed by the grf loaded.
bool disable_elrails
when true, the elrails are disabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
const struct GRFFile * grffile
NewGRF where #group belongs to.
Information about a ship vehicle.
Functions related to OTTD's strings.
std::vector< RoadTypeLabel > roadtype_list
Roadtype translation table (road)
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels)
Get the road type for a given label.
VehicleSettings vehicle
options for vehicles
static void FinaliseEngineArray()
Check for invalid engines.
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
void ResetRoadTypes()
Reset all road type information to its default values.
uint32 PaletteID
The number of the palette.
void ClearDataForNextFile()
Clear temporary data before processing the next file in the current loading stage.
Class to read from a NewGRF file.
static ChangeInfoResult IgnoreIndustryTileProperty(int prop, ByteReader *buf)
Ignore an industry tile property.
static const SpriteID SPR_SHORE_BASE
shore tiles - action 05-0D
const SpriteGroup * group[RTSG_END]
Sprite groups for resolving sprites.
uint8 max_heightlevel
maximum allowed heightlevel
RailTypeFlags
Railtype flags.
byte probability
Relative probability of appearing (16 is the standard value)
GameSettings _settings_game
Game settings of a running game or the scenario editor.
GRF was disabled due to error.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
SmallMap< uint32, struct GRFText * > value_names
Names for each value.
const SpriteGroup ** groups
Take the group with appropriate index:
bool _networking
are we in networking mode?
std::vector< Mapping > case_map
Mapping of NewGRF and OpenTTD IDs for cases.
static const uint NUM_STATIONS_PER_GRF
Number of StationSpecs per NewGRF; limited to 255 to allow extending Action3 with an extended byte la...
void SetEntitySpec(ObjectSpec *spec)
Method to install the new object data in its proper slot The slot assignment is internal of this meth...
CargoID cargo_output[INDUSTRY_NUM_OUTPUTS]
Which output cargoes to add to (only cb version 2)
Functions for NewGRF engines.
bool enabled
entity still available (by default true).newgrf can disable it, though
ObjectFlags
Various object behaviours.
Object wants 2CC colour mapping.
void SortIndustryTypes()
Initialize the list of sorted industry types.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Year avail_year
the year where it becomes available
static void ResetCustomObjects()
Reset and clear all NewObjects.
const GRFFile * grffile[RTSG_END]
NewGRF providing the Action3 for the railtype.
ObjectFlags flags
Flags/settings related to the object.
static void FinaliseIndustriesArray()
Add all new industries to the industry array.
struct LanguageMap * language_map
Mappings related to the languages.
Add signed offset to child sprite Y positions from register TileLayoutRegisters::delta.child[1].
int16 subtract_input[INDUSTRY_NUM_INPUTS]
Take this much of the input cargo (can be negative, is indirect in cb version 1+) ...
static void AfterLoadGRFs()
Finish loading NewGRFs and execute needed post-processing.
static const SpriteID SPR_TRACKS_FOR_SLOPES_BASE
Sprites for 'highlighting' tracks on sloped land.
uint32 param_value[2]
Values of GRF parameters to show for message and custom_message.
uint8 weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
CargoTypes _cargo_mask
Bitmask of cargo types available.
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string)
Add the new read string into our structure.
Electrified depot graphics without tram track were loaded.
void AlterVehicleListOrder(EngineID engine, uint target)
Record a vehicle ListOrderChange.
static void ResetCustomAirports()
Reset and clear all NewGRF airports.
LiveryScheme
List of different livery schemes.
The parameter allows a range of numbers, each of which can have a special name.
GRFConfig * _grfconfig
First item in list of current GRF set up.
byte landscape
the landscape we're currently in
void ResetCurrencies(bool preserve_custom)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
byte size_y
size of airport in y direction
Subdirectory
The different kinds of subdirectories OpenTTD uses.
RoadType tramtype_map[ROADTYPE_END]
, Roadtype translation table (tram)
byte map_colour
colour used for the small map
static void ResetNewGRF()
Reset and clear all NewGRFs.
int plural_form
The plural form used for this language.
static AirportSpec * GetWithoutOverride(byte type)
Retrieve airport spec for the given airport.
uint16 triggers
The triggers that trigger animation.
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
GRF file is processed up to GLS_INIT.
uint32 grfid
The GRF ID of the file the entity belongs to.
byte newgrf_id
NewGRF's internal ID for a case/gender.
Action5BlockType block_type
How is this Action5 type processed?
byte _display_opt
What do we want to draw/do?
CargoTypes watched_cargoes
Cargo types watched for acceptance.
EconomySettings economy
settings to change the economy
byte map_colour
Colour on mini-map.
uint8 build_cost_multiplier
Build cost multiplier per tile.
bool is_freight
Cargo type is considered to be freight (affects train freight multiplier).
uint32 nfo_line
Currently processed pseudo sprite number in the GRF.
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)'.
void Allocate(uint num_sprites)
Allocate a spritelayout for num_sprites building sprites.
TileLayoutFlags
Flags to enable register usage in sprite layouts.
byte curve_speed
Multiplier for curve maximum speed advantage.
uint16 max_sprites
If the Action5 contains more sprites, only the first max_sprites sprites will be used.
static void FinaliseObjectsArray()
Add all new objects to the object array.
Max. speed: 1 unit = 1/1.6 mph = 1 km-ish/h.
static Titem * Get(size_t index)
Returns Titem with given index.
const GRFFile * grffile
NewGRF where 'group' belongs to.
static const SpriteID SPR_ONEWAY_BASE
One way road sprites.
byte ocean_speed_frac
Fraction of maximum speed for ocean tiles.
Functions related to dates.
Power in hp (if dualheaded: sum of both vehicles)
CargoID GetCargoIDByLabel(CargoLabel cl)
Get the cargo ID by cargo label.
static ChangeInfoResult LoadTranslationTable(uint gvid, int numinfo, ByteReader *buf, T &translation_table, const char *name)
Load a cargo- or railtype-translation table.
static const Year ORIGINAL_MAX_YEAR
The maximum year of the original TTD.
CurrencySpec _currency_specs[CURRENCY_END]
Array of currencies used by the system.
Functions for NewGRF industries.
Functions to handle different currencies.
const uint8 _engine_offsets[4]
Offset of the first engine of each vehicle type in original engine data.
SpriteID sprite
SpriteID of the first sprite of the set.
GRFParameterType type
The type of this parameter.
void UpdateRefittability(bool non_empty)
Update the summary refittability on setting a refittability property.
RailTypes introduction_required_railtypes
Bitmask of railtypes that are required for this railtype to be introduced at a given introduction_dat...
static uint MapLogX()
Logarithm of the map size along the X side.
uint32 prospecting_chance
Chance prospecting succeeds.
PalSpriteID ** sprite_table
table of sprites for drawing the bridge
static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf)
Define properties for ships.
RailTypeFlags flags
Bit mask of rail type flags.
const byte _grf_cont_v2_sig[8]
Signature of a container version 2 GRF.
static bool ChangeGRFParamMask(size_t len, ByteReader *buf)
Callback function for 'INFO'->'PARAM'->param_num->'MASK' to set the parameter and bits to use...
static ChangeInfoResult IgnoreObjectProperty(uint prop, ByteReader *buf)
Ignore properties for objects.
Free the dynamically allocated sounds table.
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
uint32 grfid
Source NewGRF.
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
Reserves a place in the mapping array for an entity to be installed.
GRFConfig * grfconfig
Config of the currently processed GRF file.
static Engine * GetNewEngine(const GRFFile *file, VehicleType type, uint16 internal_id, bool static_access=false)
Returns the engine associated to a certain internal_id, resp.
char * text
If probability bit 7 is clear.
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
RoadTypeFlags flags
Bit mask of road type flags.
Add signed offset to bounding box X and Y positions from register TileLayoutRegisters::delta.parent[0..1].
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
static void ImportGRFSound(SoundEntry *sound)
Process a sound import from another GRF file.
static void FinaliseCanals()
Set to use the correct action0 properties for each canal feature.
GRFPalette
Information that can/has to be stored about a GRF's palette.
byte flags
bit 0 set: disable drawing of far pillars.
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
char * TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newlines, const char *str, int *olen, StringControlCode byte80)
Translate TTDPatch string codes into something OpenTTD can handle (better).
uint16 FioReadWord()
Read a word (16 bits) from the file (in low endian format).
void Add(uint8 local_id, uint32 grfid, uint entity_type)
Since the entity IDs defined by the GRF file does not necessarily correlate to those used by the game...
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
Properties related the the grf file.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Maximal number of cargo types in a game.
Rail vehicle can be flipped in the depot.
The NewGRF prefers a 32 bpp blitter.
static std::vector< GRFFile * > _grf_files
List of all loaded GRF files.
byte cargo_acceptance[HOUSE_NUM_ACCEPTS]
acceptance level for the cargo slots
GRFFile(const struct GRFConfig *config)
Constructor for GRFFile.
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
Flag for invalid railtype.
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
GRF file has been initialised.
Specification of a cargo type.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
VehicleType
Available vehicle types.
static bool ChangeGRFParamLimits(size_t len, ByteReader *buf)
Callback function for 'INFO'->'PARAM'->param_num->'LIMI' to set the min/max value of a parameter...
CanalFeature
List of different canal 'features'.
static void GRFUnsafe(ByteReader *buf)
Set the current NewGRF as unsafe for static use.
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
Set a variable snow line, as loaded from a newgrf file.
uint32 def_value
Default value of this parameter.
Yearly runningcost (if dualheaded: sum of both vehicles)
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
byte visual_effect
Bitstuffed NewGRF visual effect data.
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
bool IsSnowLineSet()
Has a snow line table already been loaded.
GRFStatus status
NOSAVE: GRFStatus, enum.
uint16 max_palette_offset
Maximum offset to add to the palette. (limited by size of the spriteset)
Functions related to vehicles.
struct GRFText * text
The actual text.
Resolve sprite with a specific value in variable 10.
static void BuildCargoTranslationMap()
Construct the Cargo Mapping.
const HangarTileTable * depot_table
gives the position of the depots on the airports
CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]
input cargo slots
static const uint INVALID_AIRPORTTILE
id for an invalid airport tile
Flags which require resolving the action-1-2-3 chain for the sprite, even if it is no action-1 sprite...
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
Allow replacing any subset by specifiing an offset.
uint32 grf_features
Bitset of GrfSpecFeature the grf uses.
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Price
Enumeration of all base prices for use with Prices.
Combination of a palette sprite and a 'real' sprite.
No profile, special "custom" highscore.
byte removal_cost
cost multiplier for removing it
bool HasValidSpriteSets(byte feature) const
Check whether there are any valid spritesets for a feature.
uint32 removal_cost_multiplier
Base removal cost multiplier.
Purchase cost (if dualheaded: sum of both vehicles)
GRF file is used statically (can be used in any MP game)
Header of Action 0F "universal holder" structure and functions.
bool never_expire_airports
never expire airports
uint8 flags
Flags controlling display.
uint GetNumEnts(byte feature, uint set) const
Returns the number of sprites in a spriteset.
AllowedSubtags _tags_info[]
Action14 tags for the INFO node.
uint8 num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
char * custom_message
Custom message (if present)
Add signed offset to palette from register TileLayoutRegisters::palette.
Flags which do not work for the (first) ground sprite.
RailTypeLabelList alternate_labels
Rail type labels this type provides in addition to the main label.
std::vector< Mapping > gender_map
Mapping of NewGRF and OpenTTD IDs for genders.
Tindex index
Index of this pool item.
static void FinaliseCargoArray()
Check for invalid cargoes.
int8 acceptance[INDUSTRY_NUM_INPUTS]
Level of acceptance per cargo type (signed, may be negative!)
flag for invalid roadtype
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
Looks up an EngineID in the EngineOverrideManager.
EngineClass
Type of rail engine.
static void ConvertTTDBasePrice(uint32 base_pointer, const char *error_location, Price *index)
Converts TTD(P) Base Price pointers into the enum used by OTTD See http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts.
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
void ResetPersistentNewGRFData()
Reset NewGRF data which is stored persistently in savegames.
StringID name_single
Name of a single entity of this type of cargo.
GRFError * error
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
static const uint SNOW_LINE_MONTHS
Number of months in the snow line table.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Add signed offset to sprite from register TileLayoutRegisters::sprite.
RoadTypeFlags
Roadtype flags.
Allow incrementing of ObjectClassID variables.
Functions for Standard In/Out file operations.
Date end_of_life_date
When can't this object be built anymore.
static void ActivateOldShore()
Relocates the old shore sprites at new positions.
A list of all hangar tiles in an airport.
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
The NewGRF provided no information.
static const CargoID CT_PURCHASE_OBJECT
Mapping of purchase for objects.
byte param_nr
GRF parameter to store content in.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Cargo behaves water-like.
StringID abbrev
Two letter abbreviation for this cargo type.
uint16 input_cargo_multiplier[INDUSTRY_NUM_INPUTS][INDUSTRY_NUM_OUTPUTS]
Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes) ...
#define lastof(x)
Get the last element of an fixed size array.
static bool ChangeGRFParamName(byte langid, const char *str)
Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter.
static const SpriteID SPR_AQUEDUCT_BASE
Sprites for the Aqueduct.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
ChangeInfoResult
Possible return values for the FeatureChangeInfo functions.
GRF file was not found in the local cache.
Functions related to world/map generation.
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel ...
No properties assigned. Default refit masks shall be activated.
Number of ticks before carried cargo is aged.
Cargo behaves goods/candy-like.
StringID quantifier
Text for multiple units of cargo of this type.
static uint MapLogY()
Logarithm of the map size along the y side.
Relative position (vehicles only)
static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteReader *buf)
Define properties for railtypes.
Date introduction_date
From when can this object be built.
void AllocateRegisters()
Allocate memory for register modifiers.
uint8 flags
Flags controlling display.
byte num_loaded
Number of loaded groups.
LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v)
Determines the LiveryScheme for a vehicle.
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
TramReplacement tram
In which way tram depots were replaced.
Tractive effort coefficient in 1/256.
Refittability refittability
Did the newgrf set any refittability property? If not, default refittability will be applied...
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, ByteReader *buf)
Define properties for airports.
void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
Load all the NewGRFs.
byte pow_wag_weight
Extra weight applied to consist if wagon should be powered.
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
uint16 callback_mask
Bitmask of house callbacks that have to be called.
RoadType
The different roadtypes we support.
StringID source
Source StringID (GRF local).
Subdirectory for all base data (base sets, intro game)
static uint16 SanitizeSpriteOffset(uint16 &num, uint16 offset, int max_sprites, const char *name)
Sanitize incoming sprite offsets for Action 5 graphics replacements.
static T max(const T a, const T b)
Returns the maximum of two values.
uint16 classes
Classes of this cargo type.
static bool ChangeGRFPalette(size_t len, ByteReader *buf)
Callback function for 'INFO'->'PALS' to set the number of valid parameters.
bool allow_town_roads
towns are allowed to build roads (always allowed when generating world / in SE)
static bool ChangeGRFDescription(byte langid, const char *str)
Callback function for 'INFO'->'DESC' to add a translation to the newgrf description.
byte FioReadByte()
Read a byte from the file.
std::vector< IndustryTileLayout > layouts
List of possible tile layouts for the industry.
GRFLabel * label
Pointer to the first label. This is a linked list, not an array.
uint8 status
Status; 0: no looping, 1: looping, 0xFF: no animation.
bool never_expire_vehicles
never expire vehicles
Year _cur_year
Current year, starting at 0.
Struct containing information about a single bridge type.
uint32 GetParam(uint number) const
Get GRF Parameter with range checking.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
uint tiles
Number of tile layouts.
bool improved_load
improved loading algorithm
static void DefineGotoLabel(ByteReader *buf)
Action 0x10 - Define goto label.
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Year min_year
first year the airport is available
static void LoadGRFSound(size_t offs, SoundEntry *sound)
Load a sound from a file.
Date base_intro
Basic date of engine introduction (without random parts).
static StringID TTDPStringIDToOTTDStringIDMapping(StringID str)
Perform a mapping from TTDPatch's string IDs to OpenTTD's string IDs, but only for the ones we are aw...
GRFParameterType
The possible types of a newgrf parameter.
byte nof_depots
the number of hangar tiles in this airport
Tables with default industry layouts and behaviours.
StringID menu_text
Name of this rail type in the main toolbar dropdown.
StationSettings station
settings related to station management
void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *group)
Add a generic feature callback sprite group to the appropriate feature list.
StringID production_down_text
Message appearing when the industry's production is decreasing.
StringID new_loco
Name of an engine for this type of rail in the engine preview GUI.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
static const ObjectType NUM_OBJECTS_PER_GRF
Number of supported objects per NewGRF; limited to 255 to allow extending Action3 with an extended by...
StringID name
Name of this type of cargo.
uint16 maintenance_cost
maintenance cost multiplier
Year lifelength
Lifetime of a single vehicle.
static const HouseID NUM_HOUSES
Total number of houses.
void InitGRFTownGeneratorNames()
Allocate memory for the NewGRF town names.
Definition of a single Action1 spriteset.
byte grf_container_ver
NewGRF container version if the sound is from a NewGRF.
StringID name
Displayed name of the industry.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
uint num_sprites
Number of sprites in the set.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
const AirportTileTable *const * table
list of the tiles composing the airport
uint16 max_speed
Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
uint16 max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
No shore sprites were replaced.
byte lowest_randbit
Look for this in the per-object randomized bitmask:
Temporary data during loading of GRFs.
BridgeSpec _bridge[MAX_BRIDGES]
The specification of all bridges.
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
size_t GetGRFSpriteOffset(uint32 id)
Get the file offset for a specific sprite in the sprite section of a GRF.
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
SpriteID sprite_base
Load the sprites starting from this sprite.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
This struct contains all the info that is needed to draw and construct tracks.
const LanguageMetadata * GetLanguage(byte newgrflangid)
Get the language with the given NewGRF language ID.
NewGRF handling of airports.
static void FinaliseAirportsArray()
Add all new airports to the airport array.
HouseZones building_availability
where can it be built (climates, zones)
static const LanguageMap * GetLanguageMap(uint32 grfid, uint8 language_id)
Get the language map associated with a given NewGRF and language.
IndustryLifeType
Available types of industry lifetimes.
GRFFile * grffile
Currently processed GRF file.
byte population
population (Zero on other tiles in multi tile house.)
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Functions related to NewGRF objects.
void ResetIndustries()
This function initialize the spec arrays of both industry and industry tiles.
uint16 multiplier
Capacity multiplier for vehicles. (8 fractional bits)
PriceMultipliers price_base_multipliers
Price base multipliers as set by the grf.
StringID replace_text
Text used in the autoreplace GUI.
int16 y
The y value of the coordinate.
static const HouseID NUM_HOUSES_PER_GRF
Number of supported houses per NewGRF; limited to 255 to allow extending Action3 with an extended byt...
uint8 cleanup_flag
flags indicating which data should be freed upon cleaning up
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
byte grf_container_ver
Container format of the current GRF file.
Slope slopes_refused
slope pattern on which this tile cannot be built
static ChangeInfoResult CommonVehicleChangeInfo(EngineInfo *ei, int prop, ByteReader *buf)
Define properties common to all vehicles.
Functions to read fonts from files and cache them.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
const uint8 * random_sounds
array of random sounds.
StringID * target
Destination for mapping result.
static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf)
Define properties for aircraft.
Only draw sprite if value of register TileLayoutRegisters::dodraw is non-zero.
void SetPriceBaseMultiplier(Price price, int factor)
Change a price base by the given factor.
byte symbol_pos
The currency symbol is represented by two possible values, prefix and suffix Usage of one or the othe...
uint16 add_output[INDUSTRY_NUM_OUTPUTS]
Add this much output cargo when successful (unsigned, is indirect in cb version 1+) ...
struct GRFText * desc
The description of this parameter.
Mapping between NewGRF and OpenTTD IDs.
byte catchment
catchment area of this airport
Header of Action 04 "universal holder" structure and functions.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
GrfLoadingStage stage
Current loading stage.
void ResetObjects()
This function initialize the spec arrays of objects.
void ReadGRFSpriteOffsets(byte container_version)
Parse the sprite section of GRFs.
User defined data for vehicle variable 0x42.
static TileLayoutFlags ReadSpriteLayoutSprite(ByteReader *buf, bool read_flags, bool invert_action1_flag, bool use_cur_spritesets, int feature, PalSpriteID *grf_sprite, uint16 *max_sprite_offset=nullptr, uint16 *max_palette_offset=nullptr)
Read a sprite and a palette from the GRF and convert them into a format suitable to OpenTTD...
StringID name
Name of this rail type.
byte noise_level
noise that this airport generates
Struct containing information relating to NewGRF classes for stations and airports.
ShoreReplacement shore
In which way shore sprites were replaced.
Functions related to low-level strings.
byte pylons
Bitmask of base tiles (0 - 7) which should contain elrail pylons.
uint8 freight_trains
value to multiply the weight of cargo by
bool prop27_set
Did the NewGRF set property 27 (misc flags)?
static void ReadSpriteLayoutRegisters(ByteReader *buf, TileLayoutFlags flags, bool is_parent, NewGRFSpriteLayout *dts, uint index)
Preprocess the TileLayoutFlags and read register modifiers from the GRF.
uint8 num_output
How many add_output values are valid.
uint8 palette_var10
Value for variable 10 when resolving the palette.
uint param_end
one more than the highest set parameter
void Clone(const DrawTileSeqStruct *source)
Clone the building sprites of a spritelayout.
First bit used for the type of effect.
int traininfo_vehicle_pitch
Vertical offset for drawing train images in depot GUI and vehicle details.
bool enabled
Is this spec enabled?
Information about a vehicle.
static void FinaliseHouseArray()
Add all new houses to the house array.
uint16 internal_id
The internal ID within the GRF file.
uint8 num_params
Number of used parameters.
static void CalculateRefitMasks()
Precalculate refit masks from cargo classes for all vehicles.
byte mail_generation
mail generation multiplier (tile based, as the acceptances below)
bool(* BranchHandler)(ByteReader *)
Type of callback function for branch nodes.
Functions related to errors.
RailType AllocateRailType(RailTypeLabel label)
Allocate a new rail type label.
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power ...
bool IsTerminator() const
Check whether this is a sequence terminator.
const SpriteGroup ** loaded
List of loaded groups (can be SpriteIDs or Callback results)
byte subtype
Type of aircraft.
uint16 max_sprite_offset
Maximum offset to add to the sprite. (limited by size of the spriteset)
void SetupEngines()
Initialise the engine pool with the data from the original vehicles.
DateFract _date_fract
Fractional part of the day.
static uint32 _grm_engines[256]
Contains the GRF ID of the owner of a vehicle if it has been reserved.
byte train_signal_side
show signals on left / driving / right side
The NewGRF says any palette can be used.
Shore sprites were replaced by Action5.
GRF file is an openttd-internal system grf.
static size_t GetPoolSize()
Returns first unused index.
HouseClassID class_id
defines the class this house has (not grf file based)
Information about GRF, used in the game and (part of it) in savegames.
void SetYearEngineAgingStops()
Compute the value for _year_engine_aging_stops.
int8 retire_early
Number of years early to retire vehicle.
Ground palette sprite of a tile, together with its sprite layout.
byte ReadByte(LoadgameState *ls)
Reads a byte from the buffer and decompress if needed.
Number of the first newgrf airport.
void AddGRFTextToList(GRFText **list, GRFText *text_to_add)
Add a GRFText to a GRFText list.
No tram depot graphics were loaded.
Functions related to engines.
uint16 maintenance_multiplier
Cost multiplier for maintenance of this road type.
byte road_side
the side of the road vehicles drive on
static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, ByteReader *buf)
Define properties for stations.
static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteReader *buf)
Define properties for bridges.
EngineClass engclass
Class of engine for this vehicle.
uint consistent_max_offset
Number of sprites in all referenced spritesets.
static bool ChangeGRFURL(byte langid, const char *str)
Callback function for 'INFO'->'URL_' to set the newgrf url.
const Direction * rotation
the rotation of each tiletable
static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, ByteReader *buf)
Define properties for objects.
uint16 pow_wag_power
Extra power applied to consist if wagon should be powered.
uint16 max_speed
Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Functions related to NewGRF houses.
Bitmask to get only the use palette use states.
bool has_param_defaults
NOSAVE: did this newgrf specify any defaults for it's parameters.
static void DuplicateTileTable(AirportSpec *as)
Create a copy of the tile table so it can be freed later without problems.
void ClearSnowLine()
Clear the variable snow line table and free the memory.
byte callback_mask
Bitmask of vehicle callbacks that have to be called.
simple wagon, not motorized
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
DeterministicSpriteGroupAdjustOperation
Standard non-electric rails.
SoundID GetNewGRFSoundID(const GRFFile *file, SoundID sound_id)
Resolve NewGRF sound ID.
byte num_bit
Number of bits to use for this parameter.
static void ResetAirports()
This function initializes the airportspec array.
AnimationInfo animation
Information about the animation.
Capacity (if dualheaded: for each single vehicle)
static void StaticGRFInfo(ByteReader *buf)
Handle Action 0x14.
Mapping of language data between a NewGRF and OpenTTD.
Definition of base types and functions in a cross-platform compatible way.
static void ResetAirportTiles()
This function initializes the tile array of AirportTileSpec.
static void ResetCustomIndustries()
Reset and clear all NewGRF industries.
The data is copied from a grf in _all_grfs.
Data structure to convert between Date and triplet (year, month, and day).
bool IsValidSpriteSet(byte feature, uint set) const
Check whether a specific set is defined.
byte processing_time
Periodic refresh multiplier.
void SetEntitySpec(const HouseSpec *hs)
Install the specs into the HouseSpecs array It will find itself the proper slot on which it will go...
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
A number of safeguards to prevent using unsafe methods.
int16 x
The x value of the coordinate.
static void FeatureTownName(ByteReader *buf)
Action 0x0F - Define Town names.
static bool ValidateIndustryLayout(const IndustryTileLayout &layout)
Validate the industry layout; e.g.
uint16 callback_mask
Bitmask of requested/allowed callbacks.
uint8 acceleration_type
Acceleration type of this rail type.
void FioSeekTo(size_t pos, int mode)
Seek in the current file.
Information about why GRF had problems during initialisation.
uint32 max_value
The maximal value of this parameter.
Direction
Defines the 8 directions on the map.
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
Map the GRF local type to an industry type.
RailTypes introduces_railtypes
Bitmask of which other railtypes are introduced when this railtype is introduced. ...
Vehicle uses two company colours.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
StringID new_industry_text
Message appearing when the industry is built.
Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h.
const SpriteGroup * group
Sprite group to start resolving.
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
Load a particular NewGRF.
bool dynamic_engines
enable dynamic allocation of engine data
T * Allocate(size_t count)
Get buffer of at least count times T.
static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf)
Define properties for rail vehicles.
StringID MapGRFStringID(uint32 grfid, StringID str)
Used when setting an object's property to map to the GRF's strings while taking in consideration the ...
byte random_colour[4]
4 "random" colours
static const Action5Type _action5_types[]
The information about action 5 types.
uint8 callback_mask
Bitmask of cargo callbacks that have to be called.
byte visual_effect
Bitstuffed NewGRF visual effect data.
int skip_sprites
Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file) ...
byte sorting_order
The sorting order of this railtype for the toolbar dropdown.
Refittability
Summary state of refittability properties.
CargoLabel label
Unique label of the cargo type.
byte num_table
number of elements in the table
static bool ChangeGRFParamValueNames(ByteReader *buf)
Callback function for 'INFO'->'PARA'->param_num->'VALU' to set the names of some parameter values (ty...
static void LoadFontGlyph(ByteReader *buf)
Action 0x12.
uint8 views
The number of views.
bool operator==(const MultiMapIterator< Tmap_iter1, Tlist_iter1, Tkey, Tvalue1, Tcompare > &iter1, const MultiMapIterator< Tmap_iter2, Tlist_iter2, Tkey, Tvalue2, Tcompare > &iter2)
Compare two MultiMap iterators.
void CleanUpStrings()
House cleaning.
StringID menu_text
Name of this rail type in the main toolbar dropdown.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Information about languages and their files.
static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteReader *buf)
Define properties for cargoes.
byte capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
uint8 flags
NOSAVE: GCF_Flags, bitset.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type...
uint8 tractive_effort
Coefficient of tractive effort.
static bool ChangeGRFParamDefault(size_t len, ByteReader *buf)
Callback function for 'INFO'->'PARAM'->param_num->'DFLT' to set the default value.
Number of ticks before carried cargo is aged.
uint8 sprite_var10
Value for variable 10 when resolving the sprite.
uint16 DateFract
The fraction of a date we're in, i.e. the number of ticks since the last date changeover.
static const uint NUM_AIRPORTTILES_PER_GRF
Number of airport tiles per NewGRF; limited to 255 to allow extending Action3 with an extended byte l...
GRF is unusable with this version of OpenTTD.
uint traininfo_vehicle_width
Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details.
byte cost_factor
Purchase cost factor; For multiheaded engines the sum of both engine prices.
StringID name
Tile Subname string, land information on this tile will give you "AirportName (TileSubname)".
static ChangeInfoResult CanalChangeInfo(uint id, int numinfo, int prop, ByteReader *buf)
Define properties for water features.
uint16 max_bridge_length
maximum length of bridges
The NewGRF provided no information or doesn't care about a 32 bpp blitter.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
static bool IsValidNewGRFImageIndex(uint8 image_index)
Helper to check whether an image index is valid for a particular NewGRF vehicle.
byte min_length
the minimum length (not counting start and end tile)
byte misc_flags
Miscellaneous flags.
Set when a sprite originates from an Action 1.
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, ByteReader *buf)
Define properties for industries.
Defines the data structure for constructing industry.
byte shorten_factor
length on main map for this type is 8 - shorten_factor
uint8 sprite
Register specifying a signed offset for the sprite.
Add signed offset to bounding box Z positions from register TileLayoutRegisters::delta.parent[2].
static bool HandleNode(byte type, uint32 id, ByteReader *buf, AllowedSubtags subtags[])
Handle the nodes of an Action14.
A reusable buffer that can be used for places that temporary allocate a bit of memory and do that ver...
static const uint8 MAX_NUM_GENDERS
Maximum number of supported genders.
byte air_drag
Coefficient of air drag.
GRFFileProps grf_prop
properties related to the grf file
static void AddStringForMapping(StringID source, StringID *target)
Record a static StringID for getting translated later.
static const AirportTileSpec * Get(StationGfx gfx)
Retrieve airport tile spec for the given airport tile.
void FioReadBlock(void *ptr, size_t size)
Read a block.
static bool ChangeGRFVersion(size_t len, ByteReader *buf)
Callback function for 'INFO'->'VRSN' to the version of the NewGRF.
bool _palette_remap_grf[]
Whether the given NewGRFs must get a palette remap from windows to DOS or not.
StationGfx gfx
AirportTile to use for this tile.
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
Return the ID of a new engine.
uint8 weight
Weight in 1/4t units.
byte wires
Bitmask of base tiles (0 - 7) which should contain elrail wires.
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
StringID building_name
building name
Basic functions/variables used all over the place.
const SpriteGroup ** loading
List of loading groups (can be SpriteIDs or Callback results)
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
bool Insert(const T &key, const U &data)
Adds new item to this map.
unknown/not-implemented type
byte openttd_id
OpenTTD's internal ID for a case/gender.
Flags which are still required after loading the GRF.
static const uint8 ANIM_STATUS_NO_ANIMATION
There is no animation.
static bool ChangeGRFMinVersion(size_t len, ByteReader *buf)
Callback function for 'INFO'->'MINV' to the minimum compatible version of the NewGRF.
SpriteID GetSprite(byte feature, uint set) const
Returns the first sprite of a spriteset.
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
static CargoTypes TranslateRefitMask(uint32 refit_mask)
Translate the refit mask.
static void SetNewGRFOverride(uint32 source_grfid, uint32 target_grfid)
Set the override for a NewGRF.
#define lengthof(x)
Return the length of an fixed size array.
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
static const uint8 MAX_NUM_CASES
Maximum number of supported cases.
static uint32 _ttdpatch_flags[8]
32 * 8 = 256 flags.
byte appear_ingame[NUM_LANDSCAPE]
Probability of appearance in game.
GRFFileProps grf_prop
properties related to the grf file
StringID message
Default message.
static T min(const T a, const T b)
Returns the minimum of two values.
byte GetNewgrfCurrencyIdConverted(byte grfcurr_id)
Will return the ottd's index correspondence to the ttdpatch's id.
number of bits for the sprite number
RailTypeLabel label
Unique 32 bit rail type identifier.
Element of the linked list.
uint8 plane_speed
divisor for speed of aircraft
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Year max_year
last year it can be built
NewGRF supplied spritelayout.
StringID transport_name[2]
description of the bridge, when built for road or rail
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
static const IndustryGfx NUM_INDUSTRYTILES_PER_GRF
Maximum number of industry tiles per NewGRF; limited to 255 to allow extending Action3 with an extend...
Bitmask of all climate bits.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
const uint8 _engine_counts[4]
Number of engines of each vehicle type in original engine data.
bool build_on_slopes
allow building on slopes
bool SkipSpriteData(byte type, uint16 num)
Skip the given amount of sprite graphics data.
uint16 power
Power of engine (hp); For multiheaded engines the sum of both engine powers.
Flags which require resolving the action-1-2-3 chain for the palette, even if it is no action-1 palet...
Known flags. Any unknown set flag will disable the GRF.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
static bool ChangeGRFBlitter(size_t len, ByteReader *buf)
Callback function for 'INFO'->'BLTR' to set the blitter info.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
static const SpriteGroup * CreateGroupFromGroupID(byte feature, byte setid, byte type, uint16 spriteid)
Helper function to either create a callback or a result sprite group.
static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, ByteReader *buf)
Define properties for industry tiles.
SpriteID spriteid
First available SpriteID for loading realsprites.
byte sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Price fallback_price
Fallback price multiplier for new prices but old grfs.
Year to_euro
Year of switching to the Euro. May also be CF_NOEURO or CF_ISEURO.
bool has_newhouses
Set if there are any newhouses loaded.
WaterFeature _water_feature[CF_END]
Table of canal 'feature' sprite groups.
NewGRF handling of airport tiles.
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
Subdirectory for all NewGRFs.
AllowedSubtags _tags_parameters[]
Action14 parameter tags.
uint16 price
the price multiplier
Information about a rail vehicle.
static bool IsLeapYear(Year yr)
Checks whether the given year is a leap year or not.
The status of this grf file is unknown.
Shore sprites were replaced by ActionA (using grass tiles for the corner-shores). ...
static const SpriteID SPR_RAILTYPE_TUNNEL_BASE
Tunnel sprites with grass only for custom railtype tunnel.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
StringID replace_text
Text used in the autoreplace GUI.
uint32 version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
StringID name
The name for this object.
static void FinalisePriceBaseMultipliers()
Decide whether price base multipliers of grfs shall apply globally or only to the grf specifying them...
#define DEBUG(name, level,...)
Output a line of debugging information.
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
static const uint MAX_LANG
Maximum number of languages supported by the game, and the NewGRF specs.
uint8 callback_mask
Bitmask of industry tile callbacks that have to be called.
uint16 override
id of the entity been replaced by
void FioOpenFile(int slot, const char *filename, Subdirectory subdir)
Open a slotted file.
uint8 callback_mask
Bitmask of canal callbacks that have to be called.
byte flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size...
GRFTextWrapper * url
NOSAVE: URL belonging to this GRF.
void BindAirportSpecs()
Tie all airportspecs to their class.
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
GRF file passed GLS_RESERVE stage.
static void ResetCustomHouses()
Reset and clear all NewGRF houses.
static void ParamSet(ByteReader *buf)
Action 0x0D: Set parameter.
Resolve palette with a specific value in variable 10.
byte num_loading
Number of loading groups.
static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseSpec *next2, const HouseSpec *next3, const char *filename)
Check if a given housespec is valid and disable it if it's not.
Cargo behaves passenger-like.
Additional modifiers for items in sprite layouts.
static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf)
Callback function for 'INFO'->'NPAR' to set the number of valid parameters.
The NewGRF says the Windows palette can be used.
Handling of NewGRF canals.
Describes properties of price bases.
uint32 FioReadDword()
Read a double word (32 bits) from the file (in low endian format).
Flag to disable visual effect.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
void InitRoadTypes()
Resolve sprites of custom road types.
byte first_bit
First bit to use in the GRF parameter.
StringID material
the string that contains the bridge description
uint grf_feature
GRF Feature that decides whether price multipliers apply locally or globally, #GSF_END if none...
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
Cargo accepted by this tile.
uint8 clear_cost_multiplier
Clear cost multiplier per tile.
bool old_refittable
Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
std::vector< IndustryTileLayoutTile > IndustryTileLayout
A complete tile layout for an industry is a list of tiles.
IndustryTileSpecialFlags
Flags for miscellaneous industry tile specialities.
Date introduction_date
Introduction date.
uint16 cost_multiplier
Cost multiplier for building this rail type.
static GRFFile * GetFileByGRFID(uint32 grfid)
Obtain a NewGRF file by its grfID.
PalSpriteID ground
Palette and sprite for the ground.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
uint8 child[2]
Registers for signed offsets for the position of child sprites.
TownEffect town_effect
The effect that delivering this cargo type has on towns. Also affects destination of subsidies...
this bit is set when a recolouring process is in action
bool _generating_world
Whether we are generating the map or not.
1F This is just to englobe all above types at once
Information about a road vehicle.
Header file for NewGRF stations.
uint8 callback_mask
Bitmask of canal callbacks that have to be called.
uint16 max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
RailType
Enumeration for all possible railtypes.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Variable was parsed but unread.
static const WChar NFO_UTF8_IDENTIFIER
This character, the thorn ('þ'), indicates a unicode string to NFO.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
HouseExtraFlags extra_flags
some more flags
bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
byte minimal_cargo
minimum amount of cargo transported to the stations.
byte prob
The relative probability of the following name to appear in the bottom 7 bits.
uint8 cost_multiplier
Base construction cost multiplier.
Information about one grf parameter.
bool station_noise_level
build new airports when the town noise level is still within accepted limits
Base class for all vehicles.
indicates a "standalone" locomotive
byte appear_creation[NUM_LANDSCAPE]
Probability of appearance during map creation.
bool(* TextHandler)(byte, const char *str)
Type of callback function for text nodes.
void ResetMapping()
Resets the mapping, which is used while initializing game.
uint16 max_length
the maximum length (not counting start and end tile)
Maximal number of airports per NewGRF.
static size_t ttd_strnlen(const char *str, size_t maxlen)
Get the length of a string, within a limited buffer.
Temporary engine data used when loading only.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void ResetNewGRFData()
Reset all NewGRF loaded data.
Declarations for savegames operations.
uint16 EngineID
Unique identification number of an engine.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
bool gradual_loading
load vehicles gradually
Number of bits used for the effect type.
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
Disable a static NewGRF when it is influencing another (non-static) NewGRF as this could cause desync...
static void ResetNewGRFErrors()
Clear all NewGRF errors.
RandomizedSpriteGroupCompareMode cmp_mode
Check for these triggers:
uint16 cost_multiplier
Cost multiplier for building this road type.
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
byte tractive_effort
Tractive effort coefficient.
Cargo support for NewGRFs.
uint8 palette
GRFPalette, bitset.
static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop, ByteReader *buf)
Define properties for road vehicles.
Number of ticks before carried cargo is aged.
byte minimum_life
The minimum number of years this house will survive before the town rebuilds it.
StringID name
name of this airport
Canal properties local to the NewGRF.
Information about a aircraft vehicle.
uint16 remove_rating_decrease
rating decrease if removed
bool has_newindustries
Set if there are any newindustries loaded.
GRF file is unsafe for static usage.
byte fallback_railtype
Original railtype number to use when drawing non-newgrf railtypes, or when drawing stations...
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
OrderSettings order
settings related to orders
AnimationInfo animation
Information about the animation.
bool wagon_speed_limits
enable wagon speed limits
static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite)
Map the colour modifiers of TTDPatch to those that Open is using.
static void InitNewGRFFile(const GRFConfig *config)
Prepare loading a NewGRF file with its config.
Add signed offset to child sprite X positions from register TileLayoutRegisters::delta.child[0].
StringID closure_text
Message appearing when the industry closes.
Related object of the resolved one.
GRF defined the vehicle as refittable. If the refitmask is empty after translation (cargotypes not av...
void FioSkipBytes(int n)
Skip n bytes ahead in the file.
Date introduction_date
Introduction date.
Year min_year
introduction year of the house
byte map_colour
Colour on mini-map.
when a sprite is to be displayed transparently, this bit needs to be set.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Action5BlockType
The type of action 5 type.
int8 delta_z
0x80 identifies child sprites
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
static T abs(const T a)
Returns the absolute value of (scalar) variable.
byte size_x
size of airport in x direction
indicates a combination of two locomotives
uint8 power
Power in 10hp units.
void InitializeSortedCargoSpecs()
Initialize the list of sorted cargo specifications.
0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb ...
uint8 rv_max_speed
Temporary storage of RV prop 15, maximum speed in mph/0.8.
void InitRailTypes()
Resolve sprites of custom rail types.
static void ActivateOldTramDepot()
Replocate the old tram depot sprites to the new position, if no new ones were loaded.
static const uint MAX_BRIDGES
Maximal number of available bridge specs.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
uint16 max_range
Maximum range of this aircraft.
Tile-offset / AirportTileID pair.
static bool HandleNodes(ByteReader *buf, AllowedSubtags subtags[])
Handle the contents of a 'C' choice of an Action14.
StringID string_id
Default name of engine.
CanalProperties canal_local_properties[CF_END]
Canal properties as set by this NewGRF.
bool(* DataHandler)(size_t, ByteReader *)
Type of callback function for binary nodes.
FontSize
Available font sizes.
static const SpriteID SPR_AIRPORT_PREVIEW_BASE
Airport preview sprites.
Slope
Enumeration for the slope-type.
static GRFTempEngineData * _gted
Temporary engine data used during NewGRF loading.
void ResetPriceBaseMultipliers()
Reset changes to the price base multipliers.
char * filename
Filename - either with or without full path.
static const CargoLabel _default_refitmasks_rail[]
List of what cargo labels are refittable for the given the vehicle-type.
uint32 CargoLabel
Globally unique label of a cargo type.
uint8 version
Production callback version used, or 0xFF if marked invalid.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Only corner-shores were loaded by Action5 (openttd(w/d).grf only).
static const IndustryType NUM_INDUSTRYTYPES_PER_GRF
maximum number of industry types per NewGRF; limited to 128 because bit 7 has a special meaning in so...
Bitmask to only get the blitter information.
bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id, byte container_version)
Load a real or recolour sprite.
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
static const SpriteID SPR_OPENTTD_BASE
Extra graphic spritenumbers.
uint16 weight
Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
uint16 cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
bool has_2CC
Set if any vehicle is loaded which uses 2cc (two company colours).
uint8 generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Number of ticks before carried cargo is aged.
RailTypes powered_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype generates power ...
Functions related to OTTD's landscape.
Default value to indicate that visual effect should be based on engine class.
void ResetRailTypes()
Reset all rail type information to its default values.
GRFTextWrapper * name
NOSAVE: GRF name (Action 0x08)
void ResetGenericCallbacks()
Reset all generic feature callback sprite groups.
std::vector< RailTypeLabel > railtype_list
Railtype translation table.
uint8 substitute_id
The (original) entity ID to use if this GRF is not available (currently not used) ...
Attempt to modify an invalid ID.
Defines the data structure of each individual tile of an airport.
const GRFFile * defaultcargo_grf
GRF defining the cargo translation table to use if the default cargo is the 'first refittable'...
IndustryBehaviour
Various industry behaviours mostly to represent original TTD specialities.
static void InitializeGRFSpecial()
Initialize the TTDPatch flags.
The NewGRF says the DOS palette can be used.
AnimationInfo animation
information about the animation.
static void ClearTemporaryNewGRFData(GRFFile *gf)
Reset all NewGRFData that was used only while processing data.
CargoID Index() const
Determines index of this cargospec.
static void EnsureEarlyHouse(HouseZones bitmask)
Make sure there is at least one house available in the year 0 for the given climate / housezone combi...
byte GetGRFContainerVersion()
Get the container version of the currently opened GRF file.
uint8 callback_mask
Bitmask telling which grf callback is set.
IndustryType conflicting[3]
Industries this industry cannot be close to.
byte GetSnowLine()
Get the current snow line, either variable or static.
uint16 local_id
id defined by the grf file for this entity
uint32 min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
static ChangeInfoResult IgnoreTownHouseProperty(int prop, ByteReader *buf)
Ignore a house property.
static bool SkipUnknownInfo(ByteReader *buf, byte type)
Try to skip the current node and all subnodes (if it's a branch node).
uint64 used_liveries
Bitmask of LiveryScheme used by the defined engines.
byte shorten_factor
length on main map for this type is 8 - shorten_factor
std::vector< GRFParameterInfo * > param_info
NOSAVE: extra information about the parameters.
static const SpriteID SPR_TRAMWAY_BASE
Tramway sprites.
Cargo behaves food/fizzy-drinks-like.
static const uint TLR_MAX_VAR10
Maximum value for var 10.
Max. speed: 1 unit = 8 mph = 12.8 km-ish/h.
ConstructionSettings construction
construction of things in-game
static const uint SNOW_LINE_DAYS
Number of days in each month in the snow line table.
Variable was parsed and read.
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
static uint32 _grm_cargoes[NUM_CARGO *2]
Contains the GRF ID of the owner of a cargo if it has been reserved.
static const uint MAX_SPRITEGROUP
Maximum GRF-local ID for a spritegroup.
uint8 air_drag
Coefficient of air drag.
uint32 min_value
The minimal value this parameter can have.
const char * GetName() const
Get the name of this grf.
int32 Date
The type to store our dates in.
uint32 grfid
GRF ID (defined by Action 0x08)
char * data
Additional data for message and custom_message.
Tractive effort coefficient in 1/256.
struct GRFText * name
The name of this parameter.
VarSpriteGroupScope var_scope
Take this object:
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
GRF defined vehicle as not-refittable. The vehicle shall only carry the default cargo.
GRFFileProps grf_prop
Properties related the the grf file.
StringID name
Name of this rail type.
uint file_index
File index of currently processed GRF file.
declaration of OTTD revision dependent variables
const struct GRFFile * grffile
grf file that introduced this entity
uint8 number_of_sounds
Number of sounds available in the sounds array.
uint8 bitnum
Cargo bit number, is INVALID_CARGO for a non-used spec.
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
StringID station_name
Default name for nearby station.
std::vector< CargoLabel > cargo_list
Cargo translation table (local ID -> label)
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
uint32 param[0x80]
GRF parameters.
GRF file has been activated.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
StringID units_volume
Name of a single unit of cargo of this type.
bool IsValid() const
Tests for validity of this cargospec.
StringID production_up_text
Message appearing when the industry's production is increasing.
Functions related to NewGRF provided sounds.
byte callback_mask
Bitmask of station callbacks that have to be called.
byte num_groups
must be power of 2
AllowedSubtags _tags_root[]
Action14 root tags.
byte disallowed_lengths
Bitmask of platform lengths available for the station.
byte _misc_grf_features
Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E.
byte check_proc
Index to a procedure to check for conflicting circumstances.
Definition of one tile in an industry tile layout.
static GRFFile * GetFileByFilename(const char *filename)
Obtain a NewGRF file by its filename.
byte id
If probability bit 7 is set.
static GRFParameterInfo * _cur_parameter
The parameter which info is currently changed by the newgrf.
static void ResetCustomStations()
Reset and clear all NewGRF stations.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const uint NEW_AIRPORTTILE_OFFSET
offset of first newgrf airport tile
static bool ChangeGRFParamType(size_t len, ByteReader *buf)
Callback function for 'INFO'->'PARAM'->param_num->'TYPE' to set the typeof a parameter.
byte CargoID
Cargo slots to indicate a cargo type within a game.
uint16 cargo_age_period
Number of ticks before carried cargo is aged.
Defines the data structure of each individual tile of an industry.
static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, ByteReader *buf)
Define properties for global variables.
Bitmask to get only the NewGRF supplied information.
Weight in t (if dualheaded: for each single vehicle)
Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life...
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Road vehicle is a tram/light rail vehicle.
NewGRFSpriteLayout * renderdata
Array of tile layouts.
size_t FioGetPos()
Get position in the current file.
int8 delta_x
0x80 is sequence terminator
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
static void SkipAct12(ByteReader *buf)
Action 0x12 (SKIP)
static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, ByteReader *buf)
Define properties for sound effects.
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced. ...
StringID name
Name of this station.
Maximum catchment for airports with "modified catchment" enabled.
Defines the data structure for an airport.
GRFLoadedFeatures _loaded_newgrf_features
Indicates which are the newgrf features currently loaded ingame.
Use 32 pixels per train vehicle in depot gui and vehicle details. Never set in the global variable;...
static void TranslateGRFStrings(ByteReader *buf)
Action 0x13.
static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, ByteReader *buf)
Define properties for houses.
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
uint16 multipliertowngrowth
Size of the effect.
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
byte parameter
Used for variables between 0x60 and 0x7F inclusive.
CargoTypes ctt_include_mask
Cargo types always included in the refit mask.
byte ai_passenger_only
Bit value to tell AI that this engine is for passenger use only.
uint8 num_input
How many subtract_input values are valid.
RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
Get the rail type for a given label.
SpriteID sprite
The 'real' sprite.
uint8 parent[3]
Registers for signed offsets for the bounding box position of parent sprites.
byte disallowed_platforms
Bitmask of number of platforms available for the station.
uint8 speed
The speed, i.e. the amount of time between frames.
byte running_cost
Running cost of engine; For multiheaded engines the sum of both running costs.
static GRFError * DisableGrf(StringID message=STR_NULL, GRFConfig *config=nullptr)
Disable a GRF.
ObjectClassID cls_id
The class to which this spec belongs.
StationClassID cls_id
The class to which this spec belongs.
uint8 dodraw
Register deciding whether the sprite shall be drawn at all. Non-zero means drawing.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
static bool ChangeGRFParamDescription(byte langid, const char *str)
Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter...
byte climates
Climates supported by the engine.
static void SetUnicodeGlyph(FontSize size, WChar key, SpriteID sprite)
Map a SpriteID to the font size and key.
Date _date
Current date in days (day counter)
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf)
Ignore an industry property.
SpriteID sprite
Icon to display this cargo type, may be 0xFFF (which means to resolve an action123 chain)...
static bool ReadSpriteLayout(ByteReader *buf, uint num_building_sprites, bool use_cur_spritesets, byte feature, bool allow_var10, bool no_z_position, NewGRFSpriteLayout *dts)
Read a spritelayout from the GRF.
uint32 WChar
Type for wide characters, i.e.
TTDPAirportType
Allow incrementing of AirportClassID variables.
Year max_year
last year the airport is available
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Set when a sprite must not ever be displayed transparently.
Palette is from Action 1 (moved to SPRITE_MODIFIER_CUSTOM_SPRITE in palette during loading)...
uint8 climate
In which climates is this object available?
GRFFileProps grf_prop
properties related the the grf file
CargoID cargo_input[INDUSTRY_NUM_INPUTS]
Which input cargoes to take from (only cb version 2)
byte canal_speed_frac
Fraction of maximum speed for canal/river tiles.
static const IndustryGfx INDUSTRYTILE_NOANIM
flag to mark industry tiles as having no animation
void AddSpriteSets(byte feature, SpriteID first_sprite, uint first_set, uint numsets, uint numents)
Records new spritesets.
byte user_def_data
Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles.
uint8 frames
The number of frames.
const char * name
Name for error messages.
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date...
void SetEntitySpec(IndustrySpec *inds)
Method to install the new industry data in its proper slot The slot assignment is internal of this me...
std::map< uint, SpriteSet > spritesets[GSF_END]
Currently referenceable spritesets.
Year starting_year
starting date
static bool ChangeGRFName(byte langid, const char *str)
Callback function for 'INFO'->'NAME' to add a translation to the newgrf name.
struct GRFFileProps grf_prop
Properties related to the grf file.
ObjectOverrideManager _object_mngr
The override manager for our objects.
int find_index(std::vector< T > const &vec, T const &item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Only allow replacing a whole block of sprites. (TTDP compatible)
CargoTypes ctt_exclude_mask
Cargo types always excluded from the refit mask.
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
uint8 palette
Register specifying a signed offset for the palette.
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
TileLayoutFlags flags
Flags defining which members are valid and to be used.
static const SpriteID SPR_FLAGS_BASE
Flags sprites (in same order as enum NetworkLanguage)
uint16 passenger_capacity
Passenger capacity (persons).
byte mail_capacity
Mail capacity (bags).
uint16 min_sprites
If the Action5 contains less sprites, the whole block will be ignored.
virtual void CleanPool()
Virtual method that deletes all items in the pool.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
void ResetToDefaultMapping()
Initializes the EngineOverrideManager with the default engines.
byte visual_effect
Bitstuffed NewGRF visual effect data.
Electrified depot graphics with tram track were loaded.
Dynamic data of a loaded NewGRF.
11 800 can appear in sub-arctic climate above the snow line
uint16 maintenance_multiplier
Cost multiplier for maintenance of this rail type.
Information about a single action 5 type.
Information for mapping static StringIDs.
static bool HandleParameterInfo(ByteReader *buf)
Callback function for 'INFO'->'PARA' to set extra information about the parameters.
GRFTextWrapper * info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
void SetupCargoForClimate(LandscapeID l)
Set up the default cargo types for the given landscape type.
static ChangeInfoResult RoadTypeChangeInfo(uint id, int numinfo, int prop, ByteReader *buf, RoadTramType rtt)
Define properties for roadtypes.
Flags which refer to using multiple action-1-2-3 chains.
PaletteID pal
The palette (use PAL_NONE) if not needed)
StringID name
Name of this class.
void SetEngineGRF(EngineID engine, const GRFFile *file)
Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game...
void BuildIndustriesLegend()
Fills an array for the industries legends.