52 #include "table/strings.h" 
  116     for (uint i = 0; i < GSF_END; i++) {
 
  120     memset(this->spritegroups, 0, 
sizeof(this->spritegroups));
 
  133     assert(feature < GSF_END);
 
  134     for (uint i = 0; i < numsets; i++) {
 
  136       set.sprite = first_sprite + i * numents;
 
  137       set.num_sprites = numents;
 
  149     assert(feature < GSF_END);
 
  162     assert(feature < GSF_END);
 
  175     return this->
spritesets[feature].find(
set)->second.sprite;
 
  187     return this->
spritesets[feature].find(
set)->second.num_sprites;
 
  200 template <VehicleType T>
 
  203   return image_index == 0xFD || IsValidImageIndex<T>(image_index);
 
  215   ByteReader(byte *data, byte *end) : data(data), end(end) { }
 
  217   inline byte ReadByte()
 
  219     if (data < end) 
return *(data)++;
 
  225     uint16 val = ReadByte();
 
  226     return val | (ReadByte() << 8);
 
  229   uint16 ReadExtendedByte()
 
  231     uint16 val = ReadByte();
 
  232     return val == 0xFF ? ReadWord() : val;
 
  237     uint32 val = ReadWord();
 
  238     return val | (ReadWord() << 16);
 
  241   uint32 ReadVarSize(byte size)
 
  244       case 1: 
return ReadByte();
 
  245       case 2: 
return ReadWord();
 
  246       case 4: 
return ReadDWord();
 
  253   const char *ReadString()
 
  255     char *
string = 
reinterpret_cast<char *
>(data);
 
  256     size_t string_length = 
ttd_strnlen(
string, Remaining());
 
  258     if (string_length == Remaining()) {
 
  260       string[string_length - 1] = 
'\0';
 
  261       grfmsg(7, 
"String was not terminated with a zero byte.");
 
  271   inline size_t Remaining()
 const 
  276   inline bool HasData(
size_t count = 1)
 const 
  278     return data + count <= end;
 
  286   inline void Skip(
size_t len)
 
  295 typedef void (*SpecialSpriteHandler)(
ByteReader *buf);
 
  308   uint16 cargo_allowed;
 
  309   uint16 cargo_disallowed;
 
  310   RailTypeLabel railtypelabel;
 
  347   GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { }
 
  351     return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
 
  356     return this->grfid == other.grfid && this->nfoline == other.nfoline;
 
  360 static std::map<GRFLocation, SpriteID> _grm_sprites;
 
  361 typedef std::map<GRFLocation, byte*> GRFLineToSpriteOverride;
 
  362 static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
 
  374 void CDECL 
grfmsg(
int severity, 
const char *str, ...)
 
  393   const GRFFile * 
const *end = _grf_files.
End();
 
  394   for (
GRFFile * 
const *file = _grf_files.
Begin(); file != end; file++) {
 
  395     if ((*file)->grfid == grfid) 
return *file;
 
  407   const GRFFile * 
const *end = _grf_files.
End();
 
  408   for (
GRFFile * 
const *file = _grf_files.
Begin(); file != end; file++) {
 
  409     if (strcmp((*file)->filename, filename) == 0) 
return *file;
 
  435   if (config != NULL) {
 
  446   if (message != STR_NULL) {
 
  447     delete config->error;
 
  448     config->error = 
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, message);
 
  452   return config->error;
 
  473   *target = STR_UNDEFINED;
 
  490   static const StringID units_volume[] = {
 
  491     STR_ITEMS,      STR_PASSENGERS, STR_TONS,       STR_BAGS,
 
  492     STR_LITERS,     STR_ITEMS,      STR_CRATES,     STR_TONS,
 
  493     STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
 
  494     STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
 
  495     STR_TONS,       STR_TONS,       STR_BAGS,       STR_LITERS,
 
  496     STR_TONS,       STR_LITERS,     STR_TONS,       STR_ITEMS,
 
  497     STR_BAGS,       STR_LITERS,     STR_TONS,       STR_ITEMS,
 
  498     STR_TONS,       STR_ITEMS,      STR_LITERS,     STR_ITEMS
 
  504 #define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \ 
  505   assert_compile(stringend - stringid == end - begin); \ 
  506   if (str >= begin && str <= end) return str + (stringid - begin) 
  509   TEXTID_TO_STRINGID(0x000E, 0x002D, STR_CARGO_PLURAL_NOTHING,                      STR_CARGO_PLURAL_FIZZY_DRINKS);
 
  510   TEXTID_TO_STRINGID(0x002E, 0x004D, STR_CARGO_SINGULAR_NOTHING,                    STR_CARGO_SINGULAR_FIZZY_DRINK);
 
  511   if (str >= 0x004E && str <= 0x006D) 
return units_volume[str - 0x004E];
 
  512   TEXTID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING,                          STR_QUANTITY_FIZZY_DRINKS);
 
  513   TEXTID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING,                            STR_ABBREV_FIZZY_DRINKS);
 
  514   TEXTID_TO_STRINGID(0x00D1, 0x00E0, STR_COLOUR_DARK_BLUE,                          STR_COLOUR_WHITE);
 
  519   TEXTID_TO_STRINGID(0x200F, 0x201F, STR_TOWN_BUILDING_NAME_TALL_OFFICE_BLOCK_1,    STR_TOWN_BUILDING_NAME_OLD_HOUSES_1);
 
  520   TEXTID_TO_STRINGID(0x2036, 0x2041, STR_TOWN_BUILDING_NAME_COTTAGES_1,             STR_TOWN_BUILDING_NAME_SHOPPING_MALL_1);
 
  521   TEXTID_TO_STRINGID(0x2059, 0x205C, STR_TOWN_BUILDING_NAME_IGLOO_1,                STR_TOWN_BUILDING_NAME_PIGGY_BANK_1);
 
  524   TEXTID_TO_STRINGID(0x4802, 0x4826, STR_INDUSTRY_NAME_COAL_MINE,                   STR_INDUSTRY_NAME_SUGAR_MINE);
 
  525   TEXTID_TO_STRINGID(0x482D, 0x482E, STR_NEWS_INDUSTRY_CONSTRUCTION,                STR_NEWS_INDUSTRY_PLANTED);
 
  526   TEXTID_TO_STRINGID(0x4832, 0x4834, STR_NEWS_INDUSTRY_CLOSURE_GENERAL,             STR_NEWS_INDUSTRY_CLOSURE_LACK_OF_TREES);
 
  527   TEXTID_TO_STRINGID(0x4835, 0x4838, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_FARM);
 
  528   TEXTID_TO_STRINGID(0x4839, 0x483A, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_GENERAL, STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_FARM);
 
  531     case 0x4830: 
return STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY;
 
  532     case 0x4831: 
return STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED;
 
  533     case 0x483B: 
return STR_ERROR_CAN_ONLY_BE_POSITIONED;
 
  535 #undef TEXTID_TO_STRINGID 
  537   if (str == STR_NULL) 
return STR_EMPTY;
 
  539   DEBUG(grf, 0, 
"Unknown StringID 0x%04X remapped to STR_EMPTY. Please open a Feature Request if you need it", str);
 
  557   switch (
GB(str, 8, 8)) {
 
  558     case 0xD0: 
case 0xD1: 
case 0xD2: 
case 0xD3:
 
  562     case 0xD4: 
case 0xD5: 
case 0xD6: 
case 0xD7:
 
  573 static std::map<uint32, uint32> _grf_id_overrides;
 
  582   _grf_id_overrides[source_grfid] = target_grfid;
 
  583   grfmsg(5, 
"SetNewGRFOverride: Added override of 0x%X to 0x%X", 
BSWAP32(source_grfid), 
BSWAP32(target_grfid));
 
  598   uint32 scope_grfid = INVALID_GRFID; 
 
  601     scope_grfid = file->grfid;
 
  602     uint32 
override = _grf_id_overrides[file->grfid];
 
  604       scope_grfid = 
override;
 
  606       if (grf_match == NULL) {
 
  607         grfmsg(5, 
"Tried mapping from GRFID %x to %x but target is not loaded", 
BSWAP32(file->grfid), 
BSWAP32(
override));
 
  614     EngineID engine = _engine_mngr.
GetID(type, internal_id, scope_grfid);
 
  623   EngineID engine = _engine_mngr.
GetID(type, internal_id, INVALID_GRFID);
 
  629       grfmsg(5, 
"Replaced engine at index %d for GRFID %x, type %d, index %d", e->
index, 
BSWAP32(file->grfid), type, internal_id);
 
  633     if (!static_access) {
 
  635       eid->
grfid           = scope_grfid; 
 
  641   if (static_access) 
return NULL;
 
  644     grfmsg(0, 
"Can't allocate any more engines");
 
  658   eid->grfid           = scope_grfid; 
 
  659   eid->internal_id     = internal_id;
 
  668     memset(_gted + engine_pool_size, 0, len);
 
  674   grfmsg(5, 
"Created new engine at index %d for GRFID %x, type %d, index %d", e->
index, 
BSWAP32(file->grfid), type, internal_id);
 
  691   uint32 scope_grfid = INVALID_GRFID; 
 
  693     scope_grfid = file->grfid;
 
  694     uint32 
override = _grf_id_overrides[file->grfid];
 
  695     if (
override != 0) scope_grfid = 
override;
 
  698   return _engine_mngr.
GetID(type, internal_id, scope_grfid);
 
  738   grf_sprite->
sprite = buf->ReadWord();
 
  739   grf_sprite->
pal = buf->ReadWord();
 
  744   bool custom_sprite = 
HasBit(grf_sprite->
pal, 15) != invert_action1_flag;
 
  748     uint index = 
GB(grf_sprite->
sprite, 0, 14);
 
  750       grfmsg(1, 
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d", index);
 
  751       grf_sprite->
sprite = SPR_IMG_QUERY;
 
  752       grf_sprite->
pal = PAL_NONE;
 
  755       if (max_sprite_offset != NULL) *max_sprite_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
 
  760     grfmsg(1, 
"ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite");
 
  761     DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
 
  767     uint index = 
GB(grf_sprite->
pal, 0, 14);
 
  769       grfmsg(1, 
"ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d for 'palette'", index);
 
  770       grf_sprite->
pal = PAL_NONE;
 
  773       if (max_palette_offset != NULL) *max_palette_offset = use_cur_spritesets ? _cur.
GetNumEnts(feature, index) : UINT16_MAX;
 
  778     grfmsg(1, 
"ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette");
 
  779     DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
 
  808       regs.delta.
parent[0] = buf->ReadByte();
 
  809       regs.delta.
parent[1] = buf->ReadByte();
 
  821       DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
 
  830       DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
 
  849   bool has_flags = 
HasBit(num_building_sprites, 6);
 
  850   ClrBit(num_building_sprites, 6);
 
  853   dts->
Allocate(num_building_sprites); 
 
  855   uint16 *max_sprite_offset = 
AllocaM(uint16, num_building_sprites + 1);
 
  856   uint16 *max_palette_offset = 
AllocaM(uint16, num_building_sprites + 1);
 
  857   MemSetT(max_sprite_offset, 0, num_building_sprites + 1);
 
  858   MemSetT(max_palette_offset, 0, num_building_sprites + 1);
 
  865     grfmsg(1, 
"ReadSpriteLayout: Spritelayout uses invalid flag 0x%x for ground sprite", flags & ~(valid_flags & ~
TLF_NON_GROUND_FLAGS));
 
  866     DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
 
  873   for (uint i = 0; i < num_building_sprites; i++) {
 
  876     flags = 
ReadSpriteLayoutSprite(buf, has_flags, 
false, use_cur_spritesets, feature, &seq->image, max_sprite_offset + i + 1, max_palette_offset + i + 1);
 
  879     if (flags & ~valid_flags) {
 
  880       grfmsg(1, 
"ReadSpriteLayout: Spritelayout uses unknown flag 0x%x", flags & ~valid_flags);
 
  881       DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT);
 
  885     seq->
delta_x = buf->ReadByte();
 
  886     seq->delta_y = buf->ReadByte();
 
  888     if (!no_z_position) seq->
delta_z = buf->ReadByte();
 
  891       seq->size_x = buf->ReadByte();
 
  892       seq->size_y = buf->ReadByte();
 
  893       seq->size_z = buf->ReadByte();
 
  901   bool is_consistent = 
true;
 
  903   for (uint i = 0; i < num_building_sprites + 1; i++) {
 
  904     if (max_sprite_offset[i] > 0) {
 
  908         is_consistent = 
false;
 
  912     if (max_palette_offset[i] > 0) {
 
  916         is_consistent = 
false;
 
  925   if (!is_consistent || dts->registers != NULL) {
 
  929     for (uint i = 0; i < num_building_sprites + 1; i++) {
 
  963   if (base_pointer == 0) {
 
  964     *index = INVALID_PRICE;
 
  968   static const uint32 start = 0x4B34; 
 
  969   static const uint32 size  = 6;      
 
  971   if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) {
 
  972     grfmsg(1, 
"%s: Unsupported running cost base 0x%04X, ignoring", error_location, base_pointer);
 
  976   *index = (
Price)((base_pointer - start) / size);
 
 1005       ei->decay_speed = buf->ReadByte();
 
 1022       ei->load_amount = buf->ReadByte();
 
 1044   for (
int i = 0; i < numinfo; i++) {
 
 1053         uint8 tracktype = buf->ReadByte();
 
 1055         if (tracktype < _cur.grffile->railtype_list.Length()) {
 
 1060         switch (tracktype) {
 
 1061           case 0: _gted[e->
index].railtypelabel = rvi->
engclass >= 2 ? RAILTYPE_ELECTRIC_LABEL : RAILTYPE_RAIL_LABEL; 
break;
 
 1062           case 1: _gted[e->
index].railtypelabel = RAILTYPE_MONO_LABEL; 
break;
 
 1063           case 2: _gted[e->
index].railtypelabel = RAILTYPE_MAGLEV_LABEL; 
break;
 
 1065             grfmsg(1, 
"RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype);
 
 1078         uint16 speed = buf->ReadWord();
 
 1079         if (speed == 0xFFFF) speed = 0;
 
 1086         rvi->
power = buf->ReadWord();
 
 1089         if (rvi->
power != 0) {
 
 1107         uint8 spriteid = buf->ReadByte();
 
 1108         uint8 orig_spriteid = spriteid;
 
 1112         if (spriteid < 0xFD) spriteid >>= 1;
 
 1114         if (IsValidNewGRFImageIndex<VEH_TRAIN>(spriteid)) {
 
 1115           rvi->image_index = spriteid;
 
 1117           grfmsg(1, 
"RailVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
 
 1118           rvi->image_index = 0;
 
 1124         uint8 dual = buf->ReadByte();
 
 1129           rvi->railveh_type = rvi->
power == 0 ?
 
 1141         uint8 ctype = buf->ReadByte();
 
 1143         if (ctype == 0xFF) {
 
 1146         } 
else if (_cur.
grffile->grf_version >= 8) {
 
 1151           ei->cargo_type = ctype;
 
 1154           grfmsg(2, 
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
 
 1160         SB(rvi->
weight, 0, 8, buf->ReadByte());
 
 1168         grfmsg(2, 
"RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored.");
 
 1180         uint8 traction = buf->ReadByte();
 
 1183         if (traction <= 0x07) {
 
 1185         } 
else if (traction <= 0x27) {
 
 1187         } 
else if (traction <= 0x31) {
 
 1189         } 
else if (traction <= 0x37) {
 
 1191         } 
else if (traction <= 0x41) {
 
 1200           if (_gted[e->
index].railtypelabel == RAILTYPE_RAIL_LABEL     && engclass >= 
EC_ELECTRIC) _gted[e->
index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
 
 1201           if (_gted[e->
index].railtypelabel == RAILTYPE_ELECTRIC_LABEL && engclass  < 
EC_ELECTRIC) _gted[e->
index].railtypelabel = RAILTYPE_RAIL_LABEL;
 
 1217         ei->refit_cost = buf->ReadByte();
 
 1221         uint32 mask = buf->ReadDWord();
 
 1259         byte weight = buf->ReadByte();
 
 1262           grfmsg(2, 
"RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8);
 
 1284         _gted[e->
index].cargo_allowed = buf->ReadWord();
 
 1290         _gted[e->
index].cargo_disallowed = buf->ReadWord();
 
 1304         uint8 count = buf->ReadByte();
 
 1338   for (
int i = 0; i < numinfo; i++) {
 
 1351         rvi->running_cost = buf->ReadByte();
 
 1359         uint8 spriteid = buf->ReadByte();
 
 1360         uint8 orig_spriteid = spriteid;
 
 1363         if (spriteid == 0xFF) spriteid = 0xFD;
 
 1365         if (spriteid < 0xFD) spriteid >>= 1;
 
 1367         if (IsValidNewGRFImageIndex<VEH_ROAD>(spriteid)) {
 
 1368           rvi->image_index = spriteid;
 
 1370           grfmsg(1, 
"RoadVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
 
 1371           rvi->image_index = 0;
 
 1377         rvi->capacity = buf->ReadByte();
 
 1382         uint8 ctype = buf->ReadByte();
 
 1384         if (ctype == 0xFF) {
 
 1387         } 
else if (_cur.
grffile->grf_version >= 8) {
 
 1392           ei->cargo_type = ctype;
 
 1395           grfmsg(2, 
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
 
 1401         rvi->cost_factor = buf->ReadByte();
 
 1409         rvi->
power = buf->ReadByte();
 
 1413         rvi->
weight = buf->ReadByte();
 
 1421         uint32 mask = buf->ReadDWord();
 
 1441         ei->refit_cost = buf->ReadByte();
 
 1454         _gted[e->
index].cargo_allowed = buf->ReadWord();
 
 1460         _gted[e->
index].cargo_disallowed = buf->ReadWord();
 
 1492         uint8 count = buf->ReadByte();
 
 1526   for (
int i = 0; i < numinfo; i++) {
 
 1535         uint8 spriteid = buf->ReadByte();
 
 1536         uint8 orig_spriteid = spriteid;
 
 1539         if (spriteid == 0xFF) spriteid = 0xFD;
 
 1541         if (spriteid < 0xFD) spriteid >>= 1;
 
 1543         if (IsValidNewGRFImageIndex<VEH_SHIP>(spriteid)) {
 
 1544           svi->image_index = spriteid;
 
 1546           grfmsg(1, 
"ShipVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
 
 1547           svi->image_index = 0;
 
 1557         svi->cost_factor = buf->ReadByte();
 
 1566         uint8 ctype = buf->ReadByte();
 
 1568         if (ctype == 0xFF) {
 
 1571         } 
else if (_cur.
grffile->grf_version >= 8) {
 
 1576           ei->cargo_type = ctype;
 
 1579           grfmsg(2, 
"RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
 
 1585         svi->capacity = buf->ReadWord();
 
 1589         svi->running_cost = buf->ReadByte();
 
 1597         uint32 mask = buf->ReadDWord();
 
 1609         ei->refit_cost = buf->ReadByte();
 
 1630         _gted[e->
index].cargo_allowed = buf->ReadWord();
 
 1636         _gted[e->
index].cargo_disallowed = buf->ReadWord();
 
 1664         uint8 count = buf->ReadByte();
 
 1698   for (
int i = 0; i < numinfo; i++) {
 
 1707         uint8 spriteid = buf->ReadByte();
 
 1708         uint8 orig_spriteid = spriteid;
 
 1711         if (spriteid == 0xFF) spriteid = 0xFD;
 
 1713         if (spriteid < 0xFD) spriteid >>= 1;
 
 1715         if (IsValidNewGRFImageIndex<VEH_AIRCRAFT>(spriteid)) {
 
 1716           avi->image_index = spriteid;
 
 1718           grfmsg(1, 
"AircraftVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid);
 
 1719           avi->image_index = 0;
 
 1725         if (buf->ReadByte() == 0) {
 
 1733         SB(avi->
subtype, 1, 1, (buf->ReadByte() != 0 ? 1 : 0)); 
 
 1737         avi->cost_factor = buf->ReadByte();
 
 1741         avi->
max_speed = (buf->ReadByte() * 128) / 10;
 
 1745         avi->acceleration = buf->ReadByte();
 
 1749         avi->running_cost = buf->ReadByte();
 
 1765         uint32 mask = buf->ReadDWord();
 
 1777         ei->refit_cost = buf->ReadByte();
 
 1790         _gted[e->
index].cargo_allowed = buf->ReadWord();
 
 1796         _gted[e->
index].cargo_disallowed = buf->ReadWord();
 
 1814         uint8 count = buf->ReadByte();
 
 1860   for (
int i = 0; i < numinfo; i++) {
 
 1864     if (statspec == NULL && prop != 0x08) {
 
 1865       grfmsg(2, 
"StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
 
 1874         if (*spec == NULL) *spec = CallocT<StationSpec>(1);
 
 1877         uint32 classid = buf->ReadDWord();
 
 1878         (*spec)->cls_id = StationClass::Allocate(
BSWAP32(classid));
 
 1883         statspec->
tiles = buf->ReadExtendedByte();
 
 1887         for (uint t = 0; t < statspec->
tiles; t++) {
 
 1891           if (buf->HasData(4) && *(uint32*)buf->Data() == 0) {
 
 1894             dts->
Clone(&_station_display_datas_rail[t % 8]);
 
 1909             dtss->
delta_x = buf->ReadByte();
 
 1911             dtss->delta_y = buf->ReadByte();
 
 1912             dtss->
delta_z = buf->ReadByte();
 
 1913             dtss->size_x = buf->ReadByte();
 
 1914             dtss->size_y = buf->ReadByte();
 
 1915             dtss->size_z = buf->ReadByte();
 
 1926         byte srcid = buf->ReadByte();
 
 1929         if (srcstatspec == NULL) {
 
 1930           grfmsg(1, 
"StationChangeInfo: Station %u is not defined, cannot copy sprite layout to %u.", srcid, stid + i);
 
 1938         for (uint t = 0; t < statspec->
tiles; t++) {
 
 1957         statspec->copied_layouts = 
false;
 
 1959         while (buf->HasData()) {
 
 1960           byte length = buf->ReadByte();
 
 1961           byte number = buf->ReadByte();
 
 1962           StationLayout layout;
 
 1965           if (length == 0 || number == 0) 
break;
 
 1967           if (length > statspec->lengths) {
 
 1968             statspec->platforms = 
ReallocT(statspec->platforms, length);
 
 1969             memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths);
 
 1971             statspec->layouts = 
ReallocT(statspec->layouts, length);
 
 1972             memset(statspec->layouts + statspec->lengths, 0,
 
 1973                    (length - statspec->lengths) * 
sizeof(*statspec->layouts));
 
 1975             statspec->lengths = length;
 
 1979           if (number > statspec->platforms[l]) {
 
 1980             statspec->layouts[l] = 
ReallocT(statspec->layouts[l], number);
 
 1982             memset(statspec->layouts[l] + statspec->platforms[l], 0,
 
 1983                    (number - statspec->platforms[l]) * 
sizeof(**statspec->layouts));
 
 1985             statspec->platforms[l] = number;
 
 1989           layout = MallocT<byte>(length * number);
 
 1991             for (l = 0; l < length; l++) {
 
 1992               for (p = 0; p < number; p++) {
 
 1993                 layout[l * number + p] = buf->ReadByte();
 
 2003           free(statspec->layouts[l][p]);
 
 2004           statspec->layouts[l][p] = layout;
 
 2009         byte srcid = buf->ReadByte();
 
 2012         if (srcstatspec == NULL) {
 
 2013           grfmsg(1, 
"StationChangeInfo: Station %u is not defined, cannot copy tile layout to %u.", srcid, stid + i);
 
 2017         statspec->lengths   = srcstatspec->lengths;
 
 2018         statspec->platforms = srcstatspec->platforms;
 
 2019         statspec->layouts   = srcstatspec->layouts;
 
 2020         statspec->copied_layouts = 
true;
 
 2029         statspec->
pylons = buf->ReadByte();
 
 2034         if (_cur.
grffile->grf_version >= 7) {
 
 2040         statspec->
flags = buf->ReadByte();
 
 2044         statspec->
wires = buf->ReadByte();
 
 2048         statspec->
blocked = buf->ReadByte();
 
 2052         statspec->animation.
frames = buf->ReadByte();
 
 2053         statspec->animation.
status = buf->ReadByte();
 
 2057         statspec->animation.
speed = buf->ReadByte();
 
 2061         statspec->animation.
triggers = buf->ReadWord();
 
 2065         statspec->
tiles = buf->ReadExtendedByte();
 
 2069         for (uint t = 0; t < statspec->
tiles; t++) {
 
 2071           uint num_building_sprites = buf->ReadByte();
 
 2098   if (
id + numinfo > CF_END) {
 
 2099     grfmsg(1, 
"CanalChangeInfo: Canal feature %u is invalid, max %u, ignoring", 
id + numinfo, CF_END);
 
 2103   for (
int i = 0; i < numinfo; i++) {
 
 2112         cp->
flags = buf->ReadByte();
 
 2137     grfmsg(1, 
"BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo, 
MAX_BRIDGES);
 
 2141   for (
int i = 0; i < numinfo; i++) {
 
 2147         byte year = buf->ReadByte();
 
 2162         bridge->
price = buf->ReadByte();
 
 2166         bridge->
speed = buf->ReadWord();
 
 2170         byte tableid = buf->ReadByte();
 
 2171         byte numtables = buf->ReadByte();
 
 2178         for (; numtables-- != 0; tableid++) {
 
 2180             grfmsg(1, 
"BridgeChangeInfo: Table %d >= 7, skipping", tableid);
 
 2181             for (byte sprite = 0; sprite < 32; sprite++) buf->ReadDWord();
 
 2186             bridge->
sprite_table[tableid] = MallocT<PalSpriteID>(32);
 
 2189           for (byte sprite = 0; sprite < 32; sprite++) {
 
 2203         bridge->
flags = buf->ReadByte();
 
 2212         if (newone != STR_UNDEFINED) bridge->
material = newone;
 
 2219         if (newone != STR_UNDEFINED) bridge->
transport_name[prop - 0x11] = newone;
 
 2224         bridge->
price = buf->ReadWord();
 
 2281       for (uint j = 0; j < 4; j++) buf->ReadByte();
 
 2285       byte count = buf->ReadByte();
 
 2286       for (byte j = 0; j < count; j++) buf->ReadByte();
 
 2310     grfmsg(1, 
"TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, 
NUM_HOUSES_PER_GRF);
 
 2315   if (_cur.
grffile->housespec == NULL) {
 
 2319   for (
int i = 0; i < numinfo; i++) {
 
 2322     if (prop != 0x08 && housespec == NULL) {
 
 2325       if (cir > ret) ret = cir;
 
 2332         byte subs_id = buf->ReadByte();
 
 2334         if (subs_id == 0xFF) {
 
 2337           HouseSpec::Get(hid + i)->
enabled = 
false;
 
 2341           grfmsg(2, 
"TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i);
 
 2346         if (*house == NULL) *house = CallocT<HouseSpec>(1);
 
 2350         MemCpyT(housespec, HouseSpec::Get(subs_id));
 
 2352         housespec->enabled = 
true;
 
 2353         housespec->grf_prop.local_id = hid + i;
 
 2354         housespec->grf_prop.subst_id = subs_id;
 
 2355         housespec->grf_prop.grffile = _cur.
grffile;
 
 2356         housespec->random_colour[0] = 0x04;  
 
 2357         housespec->random_colour[1] = 0x08;  
 
 2358         housespec->random_colour[2] = 0x0C;  
 
 2359         housespec->random_colour[3] = 0x06;
 
 2366           housespec->cargo_acceptance[2] = 0;
 
 2378         uint16 years = buf->ReadWord();
 
 2398         int8 goods = buf->ReadByte();
 
 2434         byte 
override = buf->ReadByte();
 
 2438           grfmsg(2, 
"TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", 
override, hid + i);
 
 2442         _house_mngr.
Add(hid + i, _cur.
grffile->grfid, 
override);
 
 2451         for (uint j = 0; j < 4; j++) housespec->
random_colour[j] = buf->ReadByte();
 
 2473         housespec->
class_id = AllocateHouseClassID(buf->ReadByte(), _cur.
grffile->grfid);
 
 2481         uint32 cargotypes = buf->ReadDWord();
 
 2484         if (cargotypes == 0xFFFFFFFF) 
break;
 
 2486         for (uint j = 0; j < 3; j++) {
 
 2488           uint8 cargo_part = 
GB(cargotypes, 8 * j, 8);
 
 2506         byte count = buf->ReadByte();
 
 2507         for (byte j = 0; j < count; j++) {
 
 2515         housespec->
min_year = buf->ReadWord();
 
 2519         housespec->
max_year = buf->ReadWord();
 
 2553 template <
typename T>
 
 2557     grfmsg(1, 
"LoadTranslationTable: %s translation table must start at zero", name);
 
 2561   translation_table.Clear();
 
 2562   for (
int i = 0; i < numinfo; i++) {
 
 2563     uint32 item = buf->ReadDWord();
 
 2564     *translation_table.Append() = 
BSWAP32(item);
 
 2594   for (
int i = 0; i < numinfo; i++) {
 
 2597         int factor = buf->ReadByte();
 
 2598         uint price = gvid + i;
 
 2600         if (price < PR_END) {
 
 2603           grfmsg(1, 
"GlobalVarChangeInfo: Price %d out of range, ignoring", price);
 
 2612         if ((newone != STR_UNDEFINED) && (curidx < 
CURRENCY_END)) {
 
 2620         uint32 rate = buf->ReadDWord();
 
 2628           grfmsg(1, 
"GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx);
 
 2635         uint16 options = buf->ReadWord();
 
 2644           grfmsg(1, 
"GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx);
 
 2651         uint32 tempfix = buf->ReadDWord();
 
 2657           grfmsg(1, 
"GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
 
 2664         uint32 tempfix = buf->ReadDWord();
 
 2670           grfmsg(1, 
"GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
 
 2677         Year year_euro = buf->ReadWord();
 
 2682           grfmsg(1, 
"GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
 
 2689           grfmsg(1, 
"GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
 
 2691           grfmsg(1, 
"GlobalVarChangeInfo: Not enough entries set in the snowline table (" PRINTF_SIZE 
")", buf->Remaining());
 
 2697               table[i][j] = buf->ReadByte();
 
 2698               if (_cur.
grffile->grf_version >= 8) {
 
 2701                 if (table[i][j] >= 128) {
 
 2723         uint curidx = gvid + i; 
 
 2726           grfmsg(1, 
"GlobalVarChangeInfo: Language %d is not known, ignoring", curidx);
 
 2731             while (buf->ReadByte() != 0) {
 
 2741           uint plural_form = buf->ReadByte();
 
 2742           if (plural_form >= LANGUAGE_MAX_PLURAL) {
 
 2743             grfmsg(1, 
"GlobalVarChanceInfo: Plural form %d is out of range, ignoring", plural_form);
 
 2750         byte newgrf_id = buf->ReadByte(); 
 
 2751         while (newgrf_id != 0) {
 
 2752           const char *name = buf->ReadString(); 
 
 2767               grfmsg(1, 
"GlobalVarChangeInfo: Gender name %s is not known, ignoring", name);
 
 2774               grfmsg(1, 
"GlobalVarChangeInfo: Case name %s is not known, ignoring", name);
 
 2779           newgrf_id = buf->ReadByte();
 
 2809   for (
int i = 0; i < numinfo; i++) {
 
 2833         uint32 s = buf->ReadDWord();
 
 2834         uint32 t = buf->ReadDWord();
 
 2841         while (buf->ReadByte() != 0) {
 
 2869     grfmsg(2, 
"CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, 
NUM_CARGO - 1);
 
 2873   for (
int i = 0; i < numinfo; i++) {
 
 2878         cs->
bitnum = buf->ReadByte();
 
 2916         cs->
sprite = buf->ReadWord();
 
 2920         cs->
weight = buf->ReadByte();
 
 2924         cs->transit_days[0] = buf->ReadByte();
 
 2928         cs->transit_days[1] = buf->ReadByte();
 
 2932         cs->initial_payment = buf->ReadDWord();
 
 2936         cs->rating_colour = buf->ReadByte();
 
 2940         cs->legend_colour = buf->ReadByte();
 
 2948         cs->
classes = buf->ReadWord();
 
 2952         cs->
label = buf->ReadDWord();
 
 2957         uint8 substitute_type = buf->ReadByte();
 
 2959         switch (substitute_type) {
 
 2966             grfmsg(1, 
"CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
 
 2982         cs->
multiplier = max<uint16>(1u, buf->ReadWord());
 
 3007   if (_cur.
grffile->sound_offset == 0) {
 
 3008     grfmsg(1, 
"SoundEffectChangeInfo: No effects defined, skipping");
 
 3013     grfmsg(1, 
"SoundEffectChangeInfo: Attempting to change undefined sound effect (%u), max (%u). Ignoring.", sid + numinfo, 
ORIGINAL_SAMPLE_COUNT + _cur.
grffile->num_sounds);
 
 3017   for (
int i = 0; i < numinfo; i++) {
 
 3022         sound->volume = buf->ReadByte();
 
 3026         sound->priority = buf->ReadByte();
 
 3030         SoundID orig_sound = buf->ReadByte();
 
 3035           SoundEntry *old_sound = GetSound(orig_sound);
 
 3038           *old_sound = *sound;
 
 3104   if (_cur.
grffile->indtspec == NULL) {
 
 3108   for (
int i = 0; i < numinfo; i++) {
 
 3111     if (prop != 0x08 && tsp == NULL) {
 
 3113       if (cir > ret) ret = cir;
 
 3120         byte subs_id = buf->ReadByte();
 
 3124           grfmsg(2, 
"IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
 
 3129         if (*tilespec == NULL) {
 
 3130           *tilespec = CallocT<IndustryTileSpec>(1);
 
 3133           memcpy(tsp, &_industry_tile_specs[subs_id], 
sizeof(_industry_tile_specs[subs_id]));
 
 3134           tsp->enabled = 
true;
 
 3142           tsp->grf_prop.local_id = indtid + i;
 
 3143           tsp->grf_prop.subst_id = subs_id;
 
 3144           tsp->grf_prop.grffile = _cur.
grffile;
 
 3151         byte ovrid = buf->ReadByte();
 
 3155           grfmsg(2, 
"IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
 
 3159         _industile_mngr.
Add(indtid + i, _cur.
grffile->grfid, ovrid);
 
 3166         uint16 acctp = buf->ReadWord();
 
 3252       byte num_table = buf->ReadByte();
 
 3253       for (byte j = 0; j < num_table; j++) {
 
 3254         for (uint k = 0;; k++) {
 
 3255           byte x = buf->ReadByte();
 
 3256           if (x == 0xFE && k == 0) {
 
 3262           byte y = buf->ReadByte();
 
 3263           if (x == 0 && y == 0x80) 
break;
 
 3265           byte gfx = buf->ReadByte();
 
 3266           if (gfx == 0xFE) buf->ReadWord();
 
 3273       for (byte j = 0; j < 3; j++) buf->ReadByte();
 
 3277       byte number_of_sounds = buf->ReadByte();
 
 3278       for (uint8 j = 0; j < number_of_sounds; j++) {
 
 3299   for (
int i = 0; i < size - 1; i++) {
 
 3300     for (
int j = i + 1; j < size; j++) {
 
 3301       if (layout[i].ti.x == layout[j].ti.
x &&
 
 3302           layout[i].ti.
y == layout[j].ti.
y) {
 
 3314     for (
int j = 0; j < ind->
num_table; j++) {
 
 3342   if (_cur.
grffile->industryspec == NULL) {
 
 3346   for (
int i = 0; i < numinfo; i++) {
 
 3349     if (prop != 0x08 && indsp == NULL) {
 
 3351       if (cir > ret) ret = cir;
 
 3358         byte subs_id = buf->ReadByte();
 
 3360         if (subs_id == 0xFF) {
 
 3363           _industry_specs[indid + i].
enabled = 
false;
 
 3367           grfmsg(2, 
"_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
 
 3374         if (*indspec == NULL) {
 
 3375           *indspec = CallocT<IndustrySpec>(1);
 
 3378           memcpy(indsp, &_origin_industry_specs[subs_id], 
sizeof(_industry_specs[subs_id]));
 
 3379           indsp->enabled = 
true;
 
 3380           indsp->grf_prop.local_id = indid + i;
 
 3381           indsp->grf_prop.subst_id = subs_id;
 
 3382           indsp->grf_prop.grffile = _cur.
grffile;
 
 3391         byte ovrid = buf->ReadByte();
 
 3395           grfmsg(2, 
"IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
 
 3399         _industry_mngr.
Add(indid + i, _cur.
grffile->grfid, ovrid);
 
 3404         byte new_num_layouts = buf->ReadByte(); 
 
 3410         uint32 def_num_tiles = buf->ReadDWord() / 3 + 1;
 
 3417           for (byte j = 0; j < new_num_layouts; j++) {
 
 3418             for (uint k = 0;; k++) {
 
 3419               if (k >= def_num_tiles) {
 
 3420                 grfmsg(3, 
"IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry %u.", indid);
 
 3423                 itt = ReallocT<IndustryTileTable>(itt, def_num_tiles);
 
 3426               itt[k].ti.x = buf->ReadByte(); 
 
 3428               if (itt[k].ti.x == 0xFE && k == 0) {
 
 3430                 IndustryType type = buf->ReadByte();  
 
 3431                 byte laynbr = buf->ReadByte();        
 
 3433                 copy_from = _origin_industry_specs[type].table[laynbr];
 
 3434                 for (size = 1;; size++) {
 
 3435                   if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.
y == 0) 
break;
 
 3440               itt[k].ti.
y = buf->ReadByte(); 
 
 3442               if (itt[k].ti.x == 0 && itt[k].ti.y == 0x80) {
 
 3445                 itt[k].ti.x = -0x80;
 
 3454               itt[k].gfx = buf->ReadByte();
 
 3456               if (itt[k].gfx == 0xFE) {
 
 3458                 int local_tile_id = buf->ReadWord();
 
 3461                 int tempid = _industile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
 
 3464                   grfmsg(2, 
"IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
 
 3467                   itt[k].gfx = tempid;
 
 3471               } 
else if (itt[k].gfx == 0xFF) {
 
 3472                 itt[k].ti.
x = (int8)
GB(itt[k].ti.x, 0, 8);
 
 3473                 itt[k].ti.y = (int8)
GB(itt[k].ti.y, 0, 8);
 
 3482                 if (_cur.
grffile->grf_version < 8 && itt[k].ti.x < 0) itt[k].ti.y += 1;
 
 3488               grfmsg(1, 
"IndustriesChangeInfo: Invalid industry layout for industry id %u. Ignoring", indid);
 
 3492               tile_table[j] = CallocT<IndustryTileTable>(size);
 
 3493               memcpy(tile_table[j], copy_from, 
sizeof(*copy_from) * size);
 
 3497           for (
int i = 0; i < new_num_layouts; i++) {
 
 3498             free(tile_table[i]);
 
 3509         indsp->
table = tile_table;
 
 3536         for (byte j = 0; j < 2; j++) {
 
 3542         for (byte j = 0; j < 3; j++) {
 
 3550         indsp->production_rate[prop - 0x12] = buf->ReadByte();
 
 3563             sounds[j] = buf->ReadByte();
 
 3579         for (byte j = 0; j < 3; j++) indsp->
conflicting[j] = buf->ReadByte();
 
 3605           uint32 multiples = buf->ReadDWord();
 
 3621         byte aflag = buf->ReadByte();
 
 3631         uint16 str = buf->ReadWord();
 
 3657   for (
int i = 0; i < as->
num_table; i++) {
 
 3662     } 
while ((++it)->ti.x != -0x80);
 
 3663     table_list[i] = MallocT<AirportTileTable>(num_tiles);
 
 3666   as->
table = table_list;
 
 3685     grfmsg(1, 
"AirportChangeInfo: Too many airports, trying id (%u), max (%u). Ignoring.", airport + numinfo, 
NUM_AIRPORTS_PER_GRF);
 
 3690   if (_cur.
grffile->airportspec == NULL) {
 
 3694   for (
int i = 0; i < numinfo; i++) {
 
 3697     if (as == NULL && prop != 0x08 && prop != 0x09) {
 
 3698       grfmsg(2, 
"AirportChangeInfo: Attempt to modify undefined airport %u, ignoring", airport + i);
 
 3704         byte subs_id = buf->ReadByte();
 
 3706         if (subs_id == 0xFF) {
 
 3713           grfmsg(2, 
"AirportChangeInfo: Attempt to use new airport %u as substitute airport for %u. Ignoring.", subs_id, airport + i);
 
 3721         if (*spec == NULL) {
 
 3722           *spec = MallocT<AirportSpec>(1);
 
 3727           as->grf_prop.local_id = airport + i;
 
 3728           as->grf_prop.subst_id = subs_id;
 
 3729           as->grf_prop.grffile = _cur.
grffile;
 
 3731           _airport_mngr.
Add(airport + i, _cur.
grffile->grfid, subs_id);
 
 3741         uint32 defsize = buf->ReadDWord();  
 
 3747           for (byte j = 0; j < as->
num_table; j++) {
 
 3749             for (
int k = 0;; k++) {
 
 3750               att[k].ti.x = buf->ReadByte(); 
 
 3751               att[k].ti.y = buf->ReadByte();
 
 3753               if (att[k].ti.x == 0 && att[k].ti.y == 0x80) {
 
 3756                 att[k].ti.x = -0x80;
 
 3765               att[k].
gfx = buf->ReadByte();
 
 3767               if (att[k].gfx == 0xFE) {
 
 3769                 int local_tile_id = buf->ReadWord();
 
 3772                 uint16 tempid = _airporttile_mngr.
GetID(local_tile_id, _cur.
grffile->grfid);
 
 3775                   grfmsg(2, 
"AirportChangeInfo: Attempt to use airport tile %u with airport id %u, not yet defined. Ignoring.", local_tile_id, airport + i);
 
 3778                   att[k].gfx = tempid;
 
 3782               } 
else if (att[k].gfx == 0xFF) {
 
 3783                 att[k].
ti.
x = (int8)
GB(att[k].ti.x, 0, 8);
 
 3784                 att[k].ti.y = (int8)
GB(att[k].ti.y, 0, 8);
 
 3795             tile_table[j] = CallocT<AirportTileTable>(size);
 
 3796             memcpy(tile_table[j], copy_from, 
sizeof(*copy_from) * size);
 
 3799           as->
table = tile_table;
 
 3802           for (
int i = 0; i < as->
num_table; i++) {
 
 3803             free(tile_table[i]);
 
 3909   if (_cur.
grffile->objectspec == NULL) {
 
 3913   for (
int i = 0; i < numinfo; i++) {
 
 3916     if (prop != 0x08 && spec == NULL) {
 
 3919       if (cir > ret) ret = cir;
 
 3928         if (*ospec == NULL) {
 
 3929           *ospec = CallocT<ObjectSpec>(1);
 
 3930           (*ospec)->
views = 1; 
 
 3934         uint32 classid = buf->ReadDWord();
 
 3935         (*ospec)->cls_id = ObjectClass::Allocate(
BSWAP32(classid));
 
 3936         (*ospec)->enabled = 
true;
 
 3951         spec->
climate = buf->ReadByte();
 
 3955         spec->
size = buf->ReadByte();
 
 3998         spec->
height = buf->ReadByte();
 
 4002         spec->
views = buf->ReadByte();
 
 4004           grfmsg(2, 
"ObjectChangeInfo: Invalid number of views (%u) for object id %u. Ignoring.", spec->
views, 
id + i);
 
 4037     grfmsg(1, 
"RailTypeChangeInfo: Rail type %u is invalid, max %u, ignoring", 
id + numinfo, 
RAILTYPE_END);
 
 4041   for (
int i = 0; i < numinfo; i++) {
 
 4054         uint16 str = buf->ReadWord();
 
 4056         if (_cur.
grffile->grf_version < 8) {
 
 4086         int n = buf->ReadByte();
 
 4087         for (
int j = 0; j != n; j++) {
 
 4088           RailTypeLabel label = buf->ReadDWord();
 
 4148         for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
 
 4167     grfmsg(1, 
"RailTypeReserveInfo: Rail type %u is invalid, max %u, ignoring", 
id + numinfo, 
RAILTYPE_END);
 
 4171   for (
int i = 0; i < numinfo; i++) {
 
 4175         RailTypeLabel rtl = buf->ReadDWord();
 
 4184         _cur.
grffile->railtype_map[
id + i] = rt;
 
 4202           int n = buf->ReadByte();
 
 4203           for (
int j = 0; j != n; j++) {
 
 4208         grfmsg(1, 
"RailTypeReserveInfo: Ignoring property 1D for rail type %u because no label was set", 
id + i);
 
 4215         for (
int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
 
 4250   if (_cur.
grffile->airtspec == NULL) {
 
 4254   for (
int i = 0; i < numinfo; i++) {
 
 4257     if (prop != 0x08 && tsp == NULL) {
 
 4258       grfmsg(2, 
"AirportTileChangeInfo: Attempt to modify undefined airport tile %u. Ignoring.", airtid + i);
 
 4265         byte subs_id = buf->ReadByte();
 
 4269           grfmsg(2, 
"AirportTileChangeInfo: Attempt to use new airport tile %u as substitute airport tile for %u. Ignoring.", subs_id, airtid + i);
 
 4274         if (*tilespec == NULL) {
 
 4275           *tilespec = CallocT<AirportTileSpec>(1);
 
 4279           tsp->enabled = 
true;
 
 4283           tsp->grf_prop.local_id = airtid + i;
 
 4284           tsp->grf_prop.subst_id = subs_id;
 
 4285           tsp->grf_prop.grffile = _cur.
grffile;
 
 4292         byte 
override = buf->ReadByte();
 
 4296           grfmsg(2, 
"AirportTileChangeInfo: Attempt to override new airport tile %u with airport tile id %u. Ignoring.", 
override, airtid + i);
 
 4300         _airporttile_mngr.
Add(airtid + i, _cur.
grffile->grfid, 
override);
 
 4305         tsp->callback_mask = buf->ReadByte();
 
 4309         tsp->animation.frames = buf->ReadByte();
 
 4310         tsp->animation.status = buf->ReadByte();
 
 4314         tsp->animation.speed = buf->ReadByte();
 
 4318         tsp->animation.triggers = buf->ReadByte();
 
 4330 static bool HandleChangeInfoResult(
const char *caller, 
ChangeInfoResult cir, uint8 feature, uint8 property)
 
 4333     default: NOT_REACHED();
 
 4343       grfmsg(1, 
"%s: Ignoring property 0x%02X of feature 0x%02X (not implemented)", caller, property, feature);
 
 4347       grfmsg(0, 
"%s: Unknown property 0x%02X of feature 0x%02X, disabling", caller, property, feature);
 
 4360 static void FeatureChangeInfo(
ByteReader *buf)
 
 4373   static const VCI_Handler handler[] = {
 
 4391       AirportTilesChangeInfo,
 
 4394   uint8 feature  = buf->ReadByte();
 
 4395   uint8 numprops = buf->ReadByte();
 
 4396   uint numinfo  = buf->ReadByte();
 
 4397   uint engine   = buf->ReadExtendedByte();
 
 4399   grfmsg(6, 
"FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d",
 
 4400                  feature, numprops, engine, numinfo);
 
 4402   if (feature >= 
lengthof(handler) || handler[feature] == NULL) {
 
 4403     if (feature != GSF_CARGOES) 
grfmsg(1, 
"FeatureChangeInfo: Unsupported feature %d, skipping", feature);
 
 4410   while (numprops-- && buf->HasData()) {
 
 4411     uint8 prop = buf->ReadByte();
 
 4414     if (HandleChangeInfoResult(
"FeatureChangeInfo", cir, feature, prop)) 
return;
 
 4421   uint8 feature  = buf->ReadByte();
 
 4422   uint8 numprops = buf->ReadByte();
 
 4423   uint numinfo = buf->ReadByte();
 
 4424   buf->ReadExtendedByte(); 
 
 4426   if (feature == GSF_BRIDGES && numprops == 1) {
 
 4427     uint8 prop = buf->ReadByte();
 
 4430     if (prop == 0x0D) 
return;
 
 4431   } 
else if (feature == GSF_GLOBALVAR && numprops == 1) {
 
 4432     uint8 prop = buf->ReadByte();
 
 4435       bool is_safe = 
true;
 
 4436       for (uint i = 0; i < numinfo; i++) {
 
 4437         uint32 s = buf->ReadDWord();
 
 4445       if (is_safe) 
return;
 
 4456 static void ReserveChangeInfo(
ByteReader *buf)
 
 4458   uint8 feature  = buf->ReadByte();
 
 4460   if (feature != GSF_CARGOES && feature != GSF_GLOBALVAR && feature != GSF_RAILTYPES) 
return;
 
 4462   uint8 numprops = buf->ReadByte();
 
 4463   uint8 numinfo  = buf->ReadByte();
 
 4464   uint8 index    = buf->ReadExtendedByte();
 
 4466   while (numprops-- && buf->HasData()) {
 
 4467     uint8 prop = buf->ReadByte();
 
 4471       default: NOT_REACHED();
 
 4477         cir = GlobalVarReserveInfo(index, numinfo, prop, buf);
 
 4481         cir = RailTypeReserveInfo(index, numinfo, prop, buf);
 
 4485     if (HandleChangeInfoResult(
"ReserveChangeInfo", cir, feature, prop)) 
return;
 
 4506   uint8  feature   = buf->ReadByte();
 
 4507   uint16 num_sets  = buf->ReadByte();
 
 4508   uint16 first_set = 0;
 
 4510   if (num_sets == 0 && buf->HasData(3)) {
 
 4513     first_set = buf->ReadExtendedByte();
 
 4514     num_sets = buf->ReadExtendedByte();
 
 4516   uint16 num_ents = buf->ReadExtendedByte();
 
 4520   grfmsg(7, 
"New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d)",
 
 4521     _cur.
spriteid, feature, num_sets, num_ents, num_sets * num_ents
 
 4524   for (
int i = 0; i < num_sets * num_ents; i++) {
 
 4534   uint16 num_sets  = buf->ReadByte();
 
 4536   if (num_sets == 0 && buf->HasData(3)) {
 
 4539     buf->ReadExtendedByte(); 
 
 4540     num_sets = buf->ReadExtendedByte();
 
 4542   uint16 num_ents = buf->ReadExtendedByte();
 
 4551 static const SpriteGroup *GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
 
 4553   if (
HasBit(groupid, 15)) {
 
 4558   if (groupid > 
MAX_SPRITEGROUP || _cur.spritegroups[groupid] == NULL) {
 
 4559     grfmsg(1, 
"GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid);
 
 4563   return _cur.spritegroups[groupid];
 
 4576   if (
HasBit(spriteid, 15)) {
 
 4582     grfmsg(1, 
"CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid", setid, type, spriteid);
 
 4587   uint num_sprites = _cur.
GetNumEnts(feature, spriteid);
 
 4590   assert(spriteset_start + num_sprites <= _cur.
spriteid);
 
 4611   uint8 feature = buf->ReadByte();
 
 4612   uint8 setid   = buf->ReadByte();
 
 4613   uint8 type    = buf->ReadByte();
 
 4636       switch (
GB(type, 2, 2)) {
 
 4637         default: NOT_REACHED();
 
 4638         case 0: group->size = DSG_SIZE_BYTE;  varsize = 1; 
break;
 
 4639         case 1: group->size = DSG_SIZE_WORD;  varsize = 2; 
break;
 
 4640         case 2: group->size = DSG_SIZE_DWORD; varsize = 4; 
break;
 
 4653         adjust->variable  = buf->ReadByte();
 
 4654         if (adjust->variable == 0x7E) {
 
 4656           adjust->subroutine = GetGroupFromGroupID(setid, type, buf->ReadByte());
 
 4661         varadjust = buf->ReadByte();
 
 4662         adjust->shift_num = 
GB(varadjust, 0, 5);
 
 4663         adjust->type      = (DeterministicSpriteGroupAdjustType)
GB(varadjust, 6, 2);
 
 4664         adjust->and_mask  = buf->ReadVarSize(varsize);
 
 4666         if (adjust->type != DSGA_TYPE_NONE) {
 
 4667           adjust->add_val    = buf->ReadVarSize(varsize);
 
 4668           adjust->divmod_val = buf->ReadVarSize(varsize);
 
 4670           adjust->add_val    = 0;
 
 4671           adjust->divmod_val = 0;
 
 4675       } 
while (
HasBit(varadjust, 5));
 
 4677       group->num_adjusts = adjusts.
Length();
 
 4678       group->adjusts = MallocT<DeterministicSpriteGroupAdjust>(group->num_adjusts);
 
 4679       MemCpyT(group->adjusts, adjusts.
Begin(), group->num_adjusts);
 
 4681       group->num_ranges = buf->ReadByte();
 
 4682       if (group->num_ranges > 0) group->ranges = CallocT<DeterministicSpriteGroupRange>(group->num_ranges);
 
 4684       for (uint i = 0; i < group->num_ranges; i++) {
 
 4685         group->ranges[i].group = GetGroupFromGroupID(setid, type, buf->ReadWord());
 
 4686         group->ranges[i].low   = buf->ReadVarSize(varsize);
 
 4687         group->ranges[i].high  = buf->ReadVarSize(varsize);
 
 4690       group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord());
 
 4706         group->count = buf->ReadByte();
 
 4709       uint8 triggers = buf->ReadByte();
 
 4710       group->triggers       = 
GB(triggers, 0, 7);
 
 4711       group->
cmp_mode       = 
HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
 
 4716       for (uint i = 0; i < group->
num_groups; i++) {
 
 4717         group->
groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
 
 4728         case GSF_ROADVEHICLES:
 
 4737           byte num_loaded  = type;
 
 4738           byte num_loading = buf->ReadByte();
 
 4741             grfmsg(0, 
"NewSpriteGroup: No sprite set to work on! Skipping");
 
 4751           if (num_loaded  > 0) group->
loaded = CallocT<const SpriteGroup*>(num_loaded);
 
 4752           if (num_loading > 0) group->
loading = CallocT<const SpriteGroup*>(num_loading);
 
 4754           grfmsg(6, 
"NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
 
 4755               setid, num_loaded, num_loading);
 
 4757           for (uint i = 0; i < num_loaded; i++) {
 
 4758             uint16 spriteid = buf->ReadWord();
 
 4760             grfmsg(8, 
"NewSpriteGroup: + rg->loaded[%i]  = subset %u", i, spriteid);
 
 4763           for (uint i = 0; i < num_loading; i++) {
 
 4764             uint16 spriteid = buf->ReadWord();
 
 4766             grfmsg(8, 
"NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
 
 4773         case GSF_AIRPORTTILES:
 
 4775         case GSF_INDUSTRYTILES: {
 
 4776           byte num_building_sprites = 
max((uint8)1, type);
 
 4783           if (
ReadSpriteLayout(buf, num_building_sprites, 
true, feature, 
false, type == 0, &group->dts)) 
return;
 
 4787         case GSF_INDUSTRIES: {
 
 4789             grfmsg(1, 
"NewSpriteGroup: Unsupported industry production version %d, skipping", type);
 
 4796           group->version = type;
 
 4798             for (uint i = 0; i < 3; i++) {
 
 4799               group->subtract_input[i] = (int16)buf->ReadWord(); 
 
 4801             for (uint i = 0; i < 2; i++) {
 
 4802               group->add_output[i] = buf->ReadWord(); 
 
 4804             group->again = buf->ReadByte();
 
 4806             for (uint i = 0; i < 3; i++) {
 
 4807               group->subtract_input[i] = buf->ReadByte();
 
 4809             for (uint i = 0; i < 2; i++) {
 
 4810               group->add_output[i] = buf->ReadByte();
 
 4812             group->again = buf->ReadByte();
 
 4818         default: 
grfmsg(1, 
"NewSpriteGroup: Unsupported feature %d, skipping", feature);
 
 4823   _cur.spritegroups[setid] = act_group;
 
 4826 static CargoID TranslateCargo(uint8 feature, uint8 ctype)
 
 4828   if (feature == GSF_OBJECTS) {
 
 4833         grfmsg(1, 
"TranslateCargo: Invalid cargo bitnum %d for objects, skipping.", ctype);
 
 4838   if (feature == GSF_STATIONS && ctype == 0xFE) 
return CT_DEFAULT_NA;
 
 4839   if (ctype == 0xFF) 
return CT_PURCHASE;
 
 4844       grfmsg(1, 
"TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
 
 4849     FOR_ALL_CARGOSPECS(cs) {
 
 4850       if (cs->
bitnum == ctype) {
 
 4851         grfmsg(6, 
"TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, cs->
Index());
 
 4856     grfmsg(5, 
"TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
 
 4869     grfmsg(5, 
"TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype);
 
 4875     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));
 
 4879   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);
 
 4884 static bool IsValidGroupID(uint16 groupid, 
const char *
function)
 
 4886   if (groupid > 
MAX_SPRITEGROUP || _cur.spritegroups[groupid] == NULL) {
 
 4887     grfmsg(1, 
"%s: Spritegroup 0x%04X out of range or empty, skipping.", 
function, groupid);
 
 4894 static void VehicleMapSpriteGroup(
ByteReader *buf, byte feature, uint8 idcount)
 
 4897   static uint last_engines_count;
 
 4898   bool wagover = 
false;
 
 4901   if (
HasBit(idcount, 7)) {
 
 4904     idcount = 
GB(idcount, 0, 7);
 
 4906     if (last_engines_count == 0) {
 
 4907       grfmsg(0, 
"VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
 
 4911     grfmsg(6, 
"VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
 
 4912         last_engines_count, idcount);
 
 4914     if (last_engines_count != idcount) {
 
 4915       last_engines = 
ReallocT(last_engines, idcount);
 
 4916       last_engines_count = idcount;
 
 4921   for (uint i = 0; i < idcount; i++) {
 
 4927       HandleChangeInfoResult(
"VehicleMapSpriteGroup", 
CIR_INVALID_ID, 0, 0);
 
 4931     engines[i] = e->
index;
 
 4932     if (!wagover) last_engines[i] = engines[i];
 
 4935   uint8 cidcount = buf->ReadByte();
 
 4936   for (uint c = 0; c < cidcount; c++) {
 
 4937     uint8 ctype = buf->ReadByte();
 
 4938     uint16 groupid = buf->ReadWord();
 
 4939     if (!IsValidGroupID(groupid, 
"VehicleMapSpriteGroup")) 
continue;
 
 4941     grfmsg(8, 
"VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
 
 4943     ctype = TranslateCargo(feature, ctype);
 
 4946     for (uint i = 0; i < idcount; i++) {
 
 4949       grfmsg(7, 
"VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
 
 4952         SetWagonOverrideSprites(engine, ctype, _cur.spritegroups[groupid], last_engines, last_engines_count);
 
 4954         SetCustomEngineSprites(engine, ctype, _cur.spritegroups[groupid]);
 
 4959   uint16 groupid = buf->ReadWord();
 
 4960   if (!IsValidGroupID(groupid, 
"VehicleMapSpriteGroup")) 
return;
 
 4962   grfmsg(8, 
"-- Default group id 0x%04X", groupid);
 
 4964   for (uint i = 0; i < idcount; i++) {
 
 4968       SetWagonOverrideSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid], last_engines, last_engines_count);
 
 4970       SetCustomEngineSprites(engine, CT_DEFAULT, _cur.spritegroups[groupid]);
 
 4977 static void CanalMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 4980   for (uint i = 0; i < idcount; i++) {
 
 4984   uint8 cidcount = buf->ReadByte();
 
 4985   buf->Skip(cidcount * 3);
 
 4987   uint16 groupid = buf->ReadWord();
 
 4988   if (!IsValidGroupID(groupid, 
"CanalMapSpriteGroup")) 
return;
 
 4990   for (uint i = 0; i < idcount; i++) {
 
 4994       grfmsg(1, 
"CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
 
 5004 static void StationMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5006   uint8 *stations = 
AllocaM(uint8, idcount);
 
 5007   for (uint i = 0; i < idcount; i++) {
 
 5008     stations[i] = buf->ReadByte();
 
 5011   uint8 cidcount = buf->ReadByte();
 
 5012   for (uint c = 0; c < cidcount; c++) {
 
 5013     uint8 ctype = buf->ReadByte();
 
 5014     uint16 groupid = buf->ReadWord();
 
 5015     if (!IsValidGroupID(groupid, 
"StationMapSpriteGroup")) 
continue;
 
 5017     ctype = TranslateCargo(GSF_STATIONS, ctype);
 
 5020     for (uint i = 0; i < idcount; i++) {
 
 5023       if (statspec == NULL) {
 
 5024         grfmsg(1, 
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
 
 5032   uint16 groupid = buf->ReadWord();
 
 5033   if (!IsValidGroupID(groupid, 
"StationMapSpriteGroup")) 
return;
 
 5035   for (uint i = 0; i < idcount; i++) {
 
 5038     if (statspec == NULL) {
 
 5039       grfmsg(1, 
"StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
 
 5044       grfmsg(1, 
"StationMapSpriteGroup: Station with ID 0x%02X mapped multiple times, skipping", stations[i]);
 
 5051     StationClass::Assign(statspec);
 
 5056 static void TownHouseMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5058   uint8 *houses = 
AllocaM(uint8, idcount);
 
 5059   for (uint i = 0; i < idcount; i++) {
 
 5060     houses[i] = buf->ReadByte();
 
 5064   uint8 cidcount = buf->ReadByte();
 
 5065   buf->Skip(cidcount * 3);
 
 5067   uint16 groupid = buf->ReadWord();
 
 5068   if (!IsValidGroupID(groupid, 
"TownHouseMapSpriteGroup")) 
return;
 
 5070   if (_cur.
grffile->housespec == NULL) {
 
 5071     grfmsg(1, 
"TownHouseMapSpriteGroup: No houses defined, skipping");
 
 5075   for (uint i = 0; i < idcount; i++) {
 
 5079       grfmsg(1, 
"TownHouseMapSpriteGroup: House %d undefined, skipping.", houses[i]);
 
 5087 static void IndustryMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5089   uint8 *industries = 
AllocaM(uint8, idcount);
 
 5090   for (uint i = 0; i < idcount; i++) {
 
 5091     industries[i] = buf->ReadByte();
 
 5095   uint8 cidcount = buf->ReadByte();
 
 5096   buf->Skip(cidcount * 3);
 
 5098   uint16 groupid = buf->ReadWord();
 
 5099   if (!IsValidGroupID(groupid, 
"IndustryMapSpriteGroup")) 
return;
 
 5101   if (_cur.
grffile->industryspec == NULL) {
 
 5102     grfmsg(1, 
"IndustryMapSpriteGroup: No industries defined, skipping");
 
 5106   for (uint i = 0; i < idcount; i++) {
 
 5109     if (indsp == NULL) {
 
 5110       grfmsg(1, 
"IndustryMapSpriteGroup: Industry %d undefined, skipping", industries[i]);
 
 5118 static void IndustrytileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5120   uint8 *indtiles = 
AllocaM(uint8, idcount);
 
 5121   for (uint i = 0; i < idcount; i++) {
 
 5122     indtiles[i] = buf->ReadByte();
 
 5126   uint8 cidcount = buf->ReadByte();
 
 5127   buf->Skip(cidcount * 3);
 
 5129   uint16 groupid = buf->ReadWord();
 
 5130   if (!IsValidGroupID(groupid, 
"IndustrytileMapSpriteGroup")) 
return;
 
 5132   if (_cur.
grffile->indtspec == NULL) {
 
 5133     grfmsg(1, 
"IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
 
 5137   for (uint i = 0; i < idcount; i++) {
 
 5140     if (indtsp == NULL) {
 
 5141       grfmsg(1, 
"IndustrytileMapSpriteGroup: Industry tile %d undefined, skipping", indtiles[i]);
 
 5149 static void CargoMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5152   for (uint i = 0; i < idcount; i++) {
 
 5153     cargoes[i] = buf->ReadByte();
 
 5157   uint8 cidcount = buf->ReadByte();
 
 5158   buf->Skip(cidcount * 3);
 
 5160   uint16 groupid = buf->ReadWord();
 
 5161   if (!IsValidGroupID(groupid, 
"CargoMapSpriteGroup")) 
return;
 
 5163   for (uint i = 0; i < idcount; i++) {
 
 5167       grfmsg(1, 
"CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid);
 
 5173     cs->group = _cur.spritegroups[groupid];
 
 5177 static void ObjectMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5179   if (_cur.
grffile->objectspec == NULL) {
 
 5180     grfmsg(1, 
"ObjectMapSpriteGroup: No object tiles defined, skipping");
 
 5184   uint8 *objects = 
AllocaM(uint8, idcount);
 
 5185   for (uint i = 0; i < idcount; i++) {
 
 5186     objects[i] = buf->ReadByte();
 
 5189   uint8 cidcount = buf->ReadByte();
 
 5190   for (uint c = 0; c < cidcount; c++) {
 
 5191     uint8 ctype = buf->ReadByte();
 
 5192     uint16 groupid = buf->ReadWord();
 
 5193     if (!IsValidGroupID(groupid, 
"ObjectMapSpriteGroup")) 
continue;
 
 5195     ctype = TranslateCargo(GSF_OBJECTS, ctype);
 
 5198     for (uint i = 0; i < idcount; i++) {
 
 5202         grfmsg(1, 
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
 
 5210   uint16 groupid = buf->ReadWord();
 
 5211   if (!IsValidGroupID(groupid, 
"ObjectMapSpriteGroup")) 
return;
 
 5213   for (uint i = 0; i < idcount; i++) {
 
 5217       grfmsg(1, 
"ObjectMapSpriteGroup: Object with ID 0x%02X undefined, skipping", objects[i]);
 
 5222       grfmsg(1, 
"ObjectMapSpriteGroup: Object with ID 0x%02X mapped multiple times, skipping", objects[i]);
 
 5232 static void RailTypeMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5234   uint8 *railtypes = 
AllocaM(uint8, idcount);
 
 5235   for (uint i = 0; i < idcount; i++) {
 
 5236     railtypes[i] = _cur.
grffile->railtype_map[buf->ReadByte()];
 
 5239   uint8 cidcount = buf->ReadByte();
 
 5240   for (uint c = 0; c < cidcount; c++) {
 
 5241     uint8 ctype = buf->ReadByte();
 
 5242     uint16 groupid = buf->ReadWord();
 
 5243     if (!IsValidGroupID(groupid, 
"RailTypeMapSpriteGroup")) 
continue;
 
 5245     if (ctype >= RTSG_END) 
continue;
 
 5248     for (uint i = 0; i < idcount; i++) {
 
 5253         rti->
group[ctype] = _cur.spritegroups[groupid];
 
 5262 static void AirportMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5264   uint8 *airports = 
AllocaM(uint8, idcount);
 
 5265   for (uint i = 0; i < idcount; i++) {
 
 5266     airports[i] = buf->ReadByte();
 
 5270   uint8 cidcount = buf->ReadByte();
 
 5271   buf->Skip(cidcount * 3);
 
 5273   uint16 groupid = buf->ReadWord();
 
 5274   if (!IsValidGroupID(groupid, 
"AirportMapSpriteGroup")) 
return;
 
 5276   if (_cur.
grffile->airportspec == NULL) {
 
 5277     grfmsg(1, 
"AirportMapSpriteGroup: No airports defined, skipping");
 
 5281   for (uint i = 0; i < idcount; i++) {
 
 5285       grfmsg(1, 
"AirportMapSpriteGroup: Airport %d undefined, skipping", airports[i]);
 
 5293 static void AirportTileMapSpriteGroup(
ByteReader *buf, uint8 idcount)
 
 5295   uint8 *airptiles = 
AllocaM(uint8, idcount);
 
 5296   for (uint i = 0; i < idcount; i++) {
 
 5297     airptiles[i] = buf->ReadByte();
 
 5301   uint8 cidcount = buf->ReadByte();
 
 5302   buf->Skip(cidcount * 3);
 
 5304   uint16 groupid = buf->ReadWord();
 
 5305   if (!IsValidGroupID(groupid, 
"AirportTileMapSpriteGroup")) 
return;
 
 5307   if (_cur.
grffile->airtspec == NULL) {
 
 5308     grfmsg(1, 
"AirportTileMapSpriteGroup: No airport tiles defined, skipping");
 
 5312   for (uint i = 0; i < idcount; i++) {
 
 5315     if (airtsp == NULL) {
 
 5316       grfmsg(1, 
"AirportTileMapSpriteGroup: Airport tile %d undefined, skipping", airptiles[i]);
 
 5326 static void FeatureMapSpriteGroup(
ByteReader *buf)
 
 5342   uint8 feature = buf->ReadByte();
 
 5343   uint8 idcount = buf->ReadByte();
 
 5349     uint16 groupid = buf->ReadWord();
 
 5350     if (!IsValidGroupID(groupid, 
"FeatureMapSpriteGroup")) 
return;
 
 5352     grfmsg(6, 
"FeatureMapSpriteGroup: Adding generic feature callback for feature %d", feature);
 
 5361   grfmsg(6, 
"FeatureMapSpriteGroup: Feature %d, %d ids", feature, idcount);
 
 5365     case GSF_ROADVEHICLES:
 
 5368       VehicleMapSpriteGroup(buf, feature, idcount);
 
 5372       CanalMapSpriteGroup(buf, idcount);
 
 5376       StationMapSpriteGroup(buf, idcount);
 
 5380       TownHouseMapSpriteGroup(buf, idcount);
 
 5383     case GSF_INDUSTRIES:
 
 5384       IndustryMapSpriteGroup(buf, idcount);
 
 5387     case GSF_INDUSTRYTILES:
 
 5388       IndustrytileMapSpriteGroup(buf, idcount);
 
 5392       CargoMapSpriteGroup(buf, idcount);
 
 5396       AirportMapSpriteGroup(buf, idcount);
 
 5400       ObjectMapSpriteGroup(buf, idcount);
 
 5404       RailTypeMapSpriteGroup(buf, idcount);
 
 5407     case GSF_AIRPORTTILES:
 
 5408       AirportTileMapSpriteGroup(buf, idcount);
 
 5412       grfmsg(1, 
"FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
 
 5436   bool new_scheme = _cur.
grffile->grf_version >= 7;
 
 5438   uint8 feature  = buf->ReadByte();
 
 5439   uint8 lang     = buf->ReadByte();
 
 5440   uint8 num      = buf->ReadByte();
 
 5441   bool generic   = 
HasBit(lang, 7);
 
 5444     id = buf->ReadWord();
 
 5445   } 
else if (feature <= GSF_AIRCRAFT) {
 
 5446     id = buf->ReadExtendedByte();
 
 5448     id = buf->ReadByte();
 
 5453   uint16 endid = 
id + num;
 
 5455   grfmsg(6, 
"FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X",
 
 5456                  id, endid, feature, lang);
 
 5458   for (; 
id < endid && buf->HasData(); 
id++) {
 
 5459     const char *name = buf->ReadString();
 
 5460     grfmsg(8, 
"FeatureNewName: 0x%04X <- %s", 
id, name);
 
 5464       case GSF_ROADVEHICLES:
 
 5469           if (e == NULL) 
break;
 
 5477       case GSF_INDUSTRIES: {
 
 5484         switch (
GB(
id, 8, 8)) {
 
 5486             if (_cur.
grffile->stations == NULL || _cur.
grffile->stations[
GB(
id, 0, 8)] == NULL) {
 
 5487               grfmsg(1, 
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring", 
GB(
id, 0, 8));
 
 5495             if (_cur.
grffile->stations == NULL || _cur.
grffile->stations[
GB(
id, 0, 8)] == NULL) {
 
 5496               grfmsg(1, 
"FeatureNewName: Attempt to name undefined station 0x%X, ignoring", 
GB(
id, 0, 8));
 
 5503             if (_cur.
grffile->airtspec == NULL || _cur.
grffile->airtspec[
GB(
id, 0, 8)] == NULL) {
 
 5504               grfmsg(1, 
"FeatureNewName: Attempt to name undefined airport tile 0x%X, ignoring", 
GB(
id, 0, 8));
 
 5511             if (_cur.
grffile->housespec == NULL || _cur.
grffile->housespec[
GB(
id, 0, 8)] == NULL) {
 
 5512               grfmsg(1, 
"FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", 
GB(
id, 0, 8));
 
 5527             grfmsg(7, 
"FeatureNewName: Unsupported ID (0x%04X)", 
id);
 
 5546   if (offset >= max_sprites) {
 
 5547     grfmsg(1, 
"GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
 
 5548     uint orig_num = num;
 
 5553   if (offset + num > max_sprites) {
 
 5554     grfmsg(4, 
"GraphicsNew: %s sprite overflow, truncating...", name);
 
 5555     uint orig_num = num;
 
 5556     num = 
max(max_sprites - offset, 0);
 
 5557     return orig_num - num;
 
 5586    { 
A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE,             1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,    
"Signal graphics"          },
 
 5588    { 
A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE,              1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, 
"Foundation graphics"      },
 
 5619   uint8 type = buf->ReadByte();
 
 5620   uint16 num = buf->ReadExtendedByte();
 
 5621   uint16 offset = 
HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
 
 5624   if ((type == 0x0D) && (num == 10) && _cur.
grffile->is_ottdfile) {
 
 5627     grfmsg(2, 
"GraphicsNew: Loading 10 missing shore sprites from extra grf.");
 
 5644     grfmsg(2, 
"GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
 
 5649   const Action5Type *action5_type = &_action5_types[type];
 
 5655     grfmsg(1, 
"GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->
name, type);
 
 5662     grfmsg(1, 
"GraphicsNew: %s (type 0x%02X) count must be at least %d. Only %d were specified. Skipping.", action5_type->
name, type, action5_type->
min_sprites, num);
 
 5672   grfmsg(2, 
"GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X", offset, offset + num - 1, action5_type->
name, type, replace);
 
 5674   for (; num > 0; num--) {
 
 5705   bool missing = 
false;
 
 5706   for (uint8 i = 0; i < 
lengthof(_action5_types); i++) {
 
 5712         DEBUG(grf, 0, 
"%s sprites are missing", type->
name);
 
 5776       *value = (major << 24) | (minor << 20) | (revision << 16) | build;
 
 5806       *value = _game_mode;
 
 5840         *value = 
Clamp(snowline * (grffile->grf_version >= 8 ? 1 : 
TILE_HEIGHT), 0, 0xFE);
 
 5849       *value = _openttd_newgrf_version;
 
 5864     default: 
return false;
 
 5868 static uint32 GetParamVal(byte param, uint32 *cond_val)
 
 5886       if (cond_val == NULL) {
 
 5905       grfmsg(1, 
"Unsupported in-game variable 0x%02X", param);
 
 5928   byte *preload_sprite = NULL;
 
 5932     preload_sprite = MallocT<byte>(num);
 
 5940     grfmsg(2, 
"CfgApply: Ignoring (next sprite is real, unsupported)");
 
 5941     free(preload_sprite);
 
 5946   GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
 
 5947   if (it != _grf_line_to_action6_sprite_override.end()) {
 
 5948     free(preload_sprite);
 
 5949     preload_sprite = _grf_line_to_action6_sprite_override[location];
 
 5951     _grf_line_to_action6_sprite_override[location] = preload_sprite;
 
 5964     param_num = buf->ReadByte();
 
 5965     if (param_num == 0xFF) 
break;
 
 5969     param_size = buf->ReadByte();
 
 5973     add_value  = 
HasBit(param_size, 7);
 
 5974     param_size = 
GB(param_size, 0, 7);
 
 5977     offset     = buf->ReadExtendedByte();
 
 5981     if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.
grffile->
param_end) {
 
 5982       grfmsg(2, 
"CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
 
 5986     grfmsg(8, 
"CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
 
 5989     for (i = 0; i < param_size && offset + i < num; i++) {
 
 5990       uint32 value = GetParamVal(param_num + i / 4, NULL);
 
 5993       if (i % 4 == 0) carry = 
false;
 
 5996         uint new_value = preload_sprite[offset + i] + 
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
 
 5997         preload_sprite[offset + i] = 
GB(new_value, 0, 8);
 
 5999         carry = new_value >= 256;
 
 6001         preload_sprite[offset + i] = 
GB(value, (i % 4) * 8, 8);
 
 6034   uint32 cond_val = 0;
 
 6038   uint8 param     = buf->ReadByte();
 
 6039   uint8 paramsize = buf->ReadByte();
 
 6040   uint8 condtype  = buf->ReadByte();
 
 6047   switch (paramsize) {
 
 6048     case 8: cond_val = buf->ReadDWord(); mask = buf->ReadDWord(); 
break;
 
 6049     case 4: cond_val = buf->ReadDWord(); mask = 0xFFFFFFFF; 
break;
 
 6050     case 2: cond_val = buf->ReadWord();  mask = 0x0000FFFF; 
break;
 
 6051     case 1: cond_val = buf->ReadByte();  mask = 0x000000FF; 
break;
 
 6055   if (param < 0x80 && _cur.grffile->param_end <= param) {
 
 6056     grfmsg(7, 
"SkipIf: Param %d undefined, skipping test", param);
 
 6060   uint32 param_val = GetParamVal(param, &cond_val);
 
 6062   grfmsg(7, 
"SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
 
 6072   if (param == 0x88 && (condtype < 0x0B || condtype > 0x0E)) {
 
 6082     if (condtype != 10 && c == NULL) {
 
 6083       grfmsg(7, 
"SkipIf: GRFID 0x%08X unknown, skipping test", 
BSWAP32(cond_val));
 
 6110       default: 
grfmsg(1, 
"SkipIf: Unsupported GRF condition type %02X. Ignoring", condtype); 
return;
 
 6115       case 0x00: result = !!(param_val & (1 << cond_val));
 
 6117       case 0x01: result = !(param_val & (1 << cond_val));
 
 6119       case 0x02: result = (param_val & mask) == cond_val;
 
 6121       case 0x03: result = (param_val & mask) != cond_val;
 
 6123       case 0x04: result = (param_val & mask) < cond_val;
 
 6125       case 0x05: result = (param_val & mask) > cond_val;
 
 6136       default: 
grfmsg(1, 
"SkipIf: Unsupported condition type %02X. Ignoring", condtype); 
return;
 
 6141     grfmsg(2, 
"SkipIf: Not skipping sprites, test was false");
 
 6145   uint8 numsprites = buf->ReadByte();
 
 6153     if (label->label != numsprites) 
continue;
 
 6156     if (choice == NULL) choice = label;
 
 6158     if (label->nfo_line > _cur.
nfo_line) {
 
 6164   if (choice != NULL) {
 
 6165     grfmsg(2, 
"SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line);
 
 6171   grfmsg(2, 
"SkipIf: Skipping %d sprites, test was true", numsprites);
 
 6190   uint8 grf_version = buf->ReadByte();
 
 6191   uint32 grfid      = buf->ReadDWord();
 
 6192   const char *name  = buf->ReadString();
 
 6196   if (grf_version < 2 || grf_version > 8) {
 
 6198     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);
 
 6206   if (buf->HasData()) {
 
 6207     const char *info = buf->ReadString();
 
 6225   uint8 version    = buf->ReadByte();
 
 6226   uint32 grfid     = buf->ReadDWord();
 
 6227   const char *name = buf->ReadString();
 
 6230     DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
 
 6234   if (_cur.
grffile->grfid != grfid) {
 
 6235     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));
 
 6239   _cur.
grffile->grf_version = version;
 
 6257   uint8 num_sets = buf->ReadByte();
 
 6259   for (uint i = 0; i < num_sets; i++) {
 
 6260     uint8 num_sprites = buf->ReadByte();
 
 6261     uint16 first_sprite = buf->ReadWord();
 
 6263     grfmsg(2, 
"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
 
 6264       i, num_sprites, first_sprite
 
 6267     for (uint j = 0; j < num_sprites; j++) {
 
 6268       int load_index = first_sprite + j;
 
 6274       if (
IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
 
 6284   uint8 num_sets = buf->ReadByte();
 
 6286   for (uint i = 0; i < num_sets; i++) {
 
 6315     STR_NEWGRF_ERROR_VERSION_NUMBER,
 
 6316     STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
 
 6317     STR_NEWGRF_ERROR_UNSET_SWITCH,
 
 6318     STR_NEWGRF_ERROR_INVALID_PARAMETER,
 
 6319     STR_NEWGRF_ERROR_LOAD_BEFORE,
 
 6320     STR_NEWGRF_ERROR_LOAD_AFTER,
 
 6321     STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
 
 6325     STR_NEWGRF_ERROR_MSG_INFO,
 
 6326     STR_NEWGRF_ERROR_MSG_WARNING,
 
 6327     STR_NEWGRF_ERROR_MSG_ERROR,
 
 6328     STR_NEWGRF_ERROR_MSG_FATAL
 
 6331   byte severity   = buf->ReadByte();
 
 6332   byte lang       = buf->ReadByte();
 
 6333   byte message_id = buf->ReadByte();
 
 6336   if (!CheckGrfLangID(lang, _cur.
grffile->grf_version)) 
return;
 
 6340   if (!
HasBit(severity, 7) && _cur.
stage == GLS_INIT) {
 
 6341     grfmsg(7, 
"GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur.
stage);
 
 6346   if (severity >= 
lengthof(sevstr)) {
 
 6347     grfmsg(7, 
"GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity);
 
 6349   } 
else if (severity == 3) {
 
 6359   if (message_id >= 
lengthof(msgstr) && message_id != 0xFF) {
 
 6360     grfmsg(7, 
"GRFLoadError: Invalid message id.");
 
 6364   if (buf->Remaining() <= 1) {
 
 6365     grfmsg(7, 
"GRFLoadError: No message data supplied.");
 
 6374   if (message_id == 0xFF) {
 
 6376     if (buf->HasData()) {
 
 6377       const char *message = buf->ReadString();
 
 6381       grfmsg(7, 
"GRFLoadError: No custom message supplied.");
 
 6385     error->
message = msgstr[message_id];
 
 6388   if (buf->HasData()) {
 
 6389     const char *data = buf->ReadString();
 
 6393     grfmsg(7, 
"GRFLoadError: No message data supplied.");
 
 6399     uint param_number = buf->ReadByte();
 
 6413   if (!buf->HasData()) 
return;
 
 6415   const char *text = buf->ReadString();
 
 6416   grfmsg(2, 
"GRFComment: %s", text);
 
 6422   uint8 target = buf->ReadByte();
 
 6425   if (target < 0x80 || target == 0x9E) 
return;
 
 6439 static uint32 GetPatchVariable(uint8 param)
 
 6449     case 0x0F: 
return 0;
 
 6465     case 0x11: 
return SPR_2CCMAP_BASE;
 
 6482       byte max_edge = 
max(log_X, log_Y);
 
 6484       if (log_X == log_Y) { 
 
 6487         if (max_edge == log_Y) 
SetBit(map_bits, 1); 
 
 6490       return (map_bits << 24) | (
min(log_X, log_Y) << 20) | (max_edge << 16) |
 
 6491         (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
 
 6500       return SPR_SLOPES_BASE;
 
 6507       grfmsg(2, 
"ParamSet: Unknown Patch variable 0x%02X.", param);
 
 6513 static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, 
const char *type)
 
 6526   for (uint i = start; i < num_ids; i++) {
 
 6530       if (op == 2 || op == 3) 
break;
 
 6535     if (size == count) 
break;
 
 6538   if (size == count) {
 
 6540     if (op == 0 || op == 3) {
 
 6541       grfmsg(2, 
"ParamSet: GRM: Reserving %d %s at %d", count, type, start);
 
 6542       for (uint i = 0; i < count; i++) grm[start + i] = _cur.
grffile->grfid;
 
 6548   if (op != 4 && op != 5) {
 
 6550     grfmsg(0, 
"ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
 
 6555   grfmsg(1, 
"ParamSet: GRM: Unable to allocate %d %s", count, type);
 
 6585   uint8 target = buf->ReadByte();
 
 6586   uint8 oper   = buf->ReadByte();
 
 6587   uint32 src1  = buf->ReadByte();
 
 6588   uint32 src2  = buf->ReadByte();
 
 6591   if (buf->Remaining() >= 4) data = buf->ReadDWord();
 
 6600     if (target < 0x80 && target < _cur.grffile->param_end) {
 
 6601       grfmsg(7, 
"ParamSet: Param %u already defined, skipping", target);
 
 6605     oper = 
GB(oper, 0, 7);
 
 6609     if (
GB(data, 0, 8) == 0xFF) {
 
 6610       if (data == 0x0000FFFF) {
 
 6612         src1 = GetPatchVariable(src1);
 
 6616         uint8  feature = 
GB(data, 8, 8);
 
 6617         uint16 count   = 
GB(data, 16, 16);
 
 6619         if (_cur.
stage == GLS_RESERVE) {
 
 6620           if (feature == 0x08) {
 
 6624               if (_cur.
spriteid + count >= 16384) {
 
 6625                 grfmsg(0, 
"ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
 
 6631               grfmsg(4, 
"ParamSet: GRM: Allocated %d sprites at %d", count, _cur.
spriteid);
 
 6638         } 
else if (_cur.
stage == GLS_ACTIVATION) {
 
 6667                   grfmsg(4, 
"ParamSet: GRM: Using pre-allocated sprites at %d", src1);
 
 6675                   grfmsg(1, 
"ParamSet: GRM: Unsupported operation %d for general sprites", op);
 
 6686             default: 
grfmsg(1, 
"ParamSet: GRM: Unsupported feature 0x%X", feature); 
return;
 
 6703       } 
else if (src1 == 0xFE) {
 
 6715     src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
 
 6716     src2 = (src2 == 0xFF) ? data : GetParamVal(src2, NULL);
 
 6744       res = (int32)src1 * (int32)src2;
 
 6748       if ((int32)src2 < 0) {
 
 6749         res = src1 >> -(int32)src2;
 
 6751         res = src1 << (src2 & 0x1F); 
 
 6756       if ((int32)src2 < 0) {
 
 6757         res = (int32)src1 >> -(int32)src2;
 
 6759         res = (int32)src1 << (src2 & 0x1F); 
 
 6783         res = (int32)src1 / (int32)src2;
 
 6799         res = (int32)src1 % (int32)src2;
 
 6803     default: 
grfmsg(0, 
"ParamSet: Unknown operation %d, skipping", oper); 
return;
 
 6832       grfmsg(7, 
"ParamSet: Skipping unimplemented target 0x%02X", target);
 
 6843         uint32 safe_bits = 0;
 
 6844         SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
 
 6853       grfmsg(7, 
"ParamSet: Skipping unimplemented target 0x%02X", target);
 
 6857       if (target < 0x80) {
 
 6858         _cur.
grffile->param[target] = res;
 
 6862         grfmsg(7, 
"ParamSet: Skipping unknown target 0x%02X", target);
 
 6876   uint8 num = buf->ReadByte();
 
 6878   for (uint i = 0; i < num; i++) {
 
 6879     uint32 grfid = buf->ReadDWord();
 
 6901   uint8 num = buf->ReadByte();
 
 6903   for (uint i = 0; i < num; i++) {
 
 6904     uint32 grfid = buf->ReadDWord();
 
 6908     if (file != NULL && file != _cur.
grfconfig) {
 
 6926   uint32 grfid = _cur.
grffile->grfid;
 
 6930   byte 
id = buf->ReadByte();
 
 6931   grfmsg(6, 
"FeatureTownName: definition 0x%02X", 
id & 0x7F);
 
 6936     bool new_scheme = _cur.
grffile->grf_version >= 7;
 
 6938     byte lang = buf->ReadByte();
 
 6940     byte nb_gen = townname->nb_gen;
 
 6944       const char *name = buf->ReadString();
 
 6947       grfmsg(6, 
"FeatureTownName: lang 0x%X -> '%s'", lang, lang_name);
 
 6950       townname->name[nb_gen] = 
AddGRFString(grfid, 
id, lang, new_scheme, 
false, name, STR_UNDEFINED);
 
 6952       lang = buf->ReadByte();
 
 6953     } 
while (lang != 0);
 
 6954     townname->id[nb_gen] = id;
 
 6958   byte nb = buf->ReadByte();
 
 6959   grfmsg(6, 
"FeatureTownName: %u parts", nb);
 
 6961   townname->nbparts[id] = nb;
 
 6962   townname->partlist[id] = CallocT<NamePartList>(nb);
 
 6964   for (
int i = 0; i < nb; i++) {
 
 6965     byte nbtext =  buf->ReadByte();
 
 6966     townname->partlist[id][i].bitstart  = buf->ReadByte();
 
 6967     townname->partlist[id][i].bitcount  = buf->ReadByte();
 
 6968     townname->partlist[id][i].maxprob   = 0;
 
 6969     townname->partlist[id][i].partcount = nbtext;
 
 6970     townname->partlist[id][i].parts     = CallocT<NamePart>(nbtext);
 
 6971     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);
 
 6973     for (
int j = 0; j < nbtext; j++) {
 
 6974       byte prob = buf->ReadByte();
 
 6977         byte ref_id = buf->ReadByte();
 
 6979         if (townname->nbparts[ref_id] == 0) {
 
 6980           grfmsg(0, 
"FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
 
 6981           DelGRFTownName(grfid);
 
 6986         grfmsg(6, 
"FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
 
 6987         townname->partlist[id][i].parts[j].data.
id = ref_id;
 
 6989         const char *text = buf->ReadString();
 
 6991         grfmsg(6, 
"FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[
id][i].parts[j].data.
text, prob);
 
 6993       townname->partlist[id][i].parts[j].
prob = prob;
 
 6994       townname->partlist[id][i].maxprob += 
GB(prob, 0, 7);
 
 6996     grfmsg(6, 
"FeatureTownName: part %d, total probability %d", i, townname->partlist[
id][i].maxprob);
 
 7008   byte nfo_label = buf->ReadByte();
 
 7010   GRFLabel *label = MallocT<GRFLabel>(1);
 
 7011   label->label    = nfo_label;
 
 7022     for (l = _cur.
grffile->
label; l->next != NULL; l = l->next) {}
 
 7026   grfmsg(2, 
"DefineGotoLabel: GOTO target with label 0x%02X", label->label);
 
 7040   if (file == NULL || file->sound_offset == 0) {
 
 7041     grfmsg(1, 
"ImportGRFSound: Source file not available");
 
 7045   if (sound_id >= file->num_sounds) {
 
 7046     grfmsg(1, 
"ImportGRFSound: Sound effect %d is invalid", sound_id);
 
 7050   grfmsg(2, 
"ImportGRFSound: Copying sound %d (%d) from file %X", sound_id, file->sound_offset + sound_id, grfid);
 
 7052   *sound = *GetSound(file->sound_offset + sound_id);
 
 7055   sound->volume   = 128;
 
 7056   sound->priority = 0;
 
 7067   sound->volume = 0x80;
 
 7068   sound->priority = 0;
 
 7070   if (offs != SIZE_MAX) {
 
 7073     sound->file_offset = offs;
 
 7085   uint16 num = buf->ReadWord();
 
 7086   if (num == 0) 
return;
 
 7089   if (_cur.
grffile->sound_offset == 0) {
 
 7090     _cur.
grffile->sound_offset = GetNumSounds();
 
 7091     _cur.
grffile->num_sounds = num;
 
 7094     sound = GetSound(_cur.
grffile->sound_offset);
 
 7097   for (
int i = 0; i < num; i++) {
 
 7102     bool invalid = i >= _cur.
grffile->num_sounds;
 
 7112         grfmsg(1, 
"GRFSound: Sound index out of range (multiple Action 11?)");
 
 7114       } 
else if (len != 4) {
 
 7115         grfmsg(1, 
"GRFSound: Invalid sprite section import");
 
 7125       grfmsg(1, 
"GRFSound: Unexpected RealSprite found, skipping");
 
 7132       grfmsg(1, 
"GRFSound: Sound index out of range (multiple Action 11?)");
 
 7140         if (_cur.
stage == GLS_INIT) {
 
 7142             grfmsg(1, 
"GRFSound: Inline sounds are not supported for container version >= 2");
 
 7151         if (_cur.
stage == GLS_ACTIVATION) {
 
 7162         grfmsg(1, 
"GRFSound: Unexpected Action %x found, skipping", action);
 
 7191   uint8 num_def = buf->ReadByte();
 
 7193   for (uint i = 0; i < num_def; i++) {
 
 7195     uint8  num_char  = buf->ReadByte();
 
 7196     uint16 base_char = buf->ReadWord();
 
 7198     if (size >= FS_END) {
 
 7199       grfmsg(1, 
"LoadFontGlyph: Size %u is not supported, ignoring", size);
 
 7202     grfmsg(7, 
"LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
 
 7204     for (uint c = 0; c < num_char; c++) {
 
 7222   uint8 num_def = buf->ReadByte();
 
 7224   for (uint i = 0; i < num_def; i++) {
 
 7248   uint32 grfid = buf->ReadDWord();
 
 7251     grfmsg(7, 
"TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13", 
BSWAP32(grfid));
 
 7261     GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, 
lastof(tmp));
 
 7272   byte language = _cur.
grffile->grf_version >= 8 ? buf->ReadByte() : 0x7F;
 
 7273   byte num_strings = buf->ReadByte();
 
 7274   uint16 first_id  = buf->ReadWord();
 
 7276   if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD3FF) || (first_id >= 0xDC00 && first_id + num_strings <= 0xDCFF))) {
 
 7277     grfmsg(7, 
"TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
 
 7281   for (uint i = 0; i < num_strings && buf->HasData(); i++) {
 
 7282     const char *
string = buf->ReadString();
 
 7285       grfmsg(7, 
"TranslateGRFString: Ignoring empty string.");
 
 7289     AddGRFString(grfid, first_id + i, language, 
true, 
true, 
string, STR_UNDEFINED);
 
 7318     grfmsg(2, 
"StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7330     grfmsg(2, 
"StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7333     char data = buf->ReadByte();
 
 7341         grfmsg(2, 
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data);
 
 7356     grfmsg(2, 
"StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7359     char data = buf->ReadByte();
 
 7365         grfmsg(2, 
"StaticGRFInfo: unexpected value '%02x' for 'INFO'->'BLTR', ignoring this field", data);
 
 7378     grfmsg(2, 
"StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7391     grfmsg(2, 
"StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7396       grfmsg(2, 
"StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field");
 
 7427     grfmsg(2, 
"StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7432       _cur_parameter->
type = type;
 
 7434       grfmsg(3, 
"StaticGRFInfo: unknown parameter type %d, ignoring this field", type);
 
 7444     grfmsg(2, 
"StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field");
 
 7446   } 
else if (len != 8) {
 
 7447     grfmsg(2, 
"StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7450     _cur_parameter->
min_value = buf->ReadDWord();
 
 7451     _cur_parameter->
max_value = buf->ReadDWord();
 
 7459   if (len < 1 || len > 3) {
 
 7460     grfmsg(2, 
"StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7463     byte param_nr = buf->ReadByte();
 
 7465       grfmsg(2, 
"StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param %d, ignoring this field", param_nr);
 
 7468       _cur_parameter->
param_nr = param_nr;
 
 7469       if (len >= 2) _cur_parameter->
first_bit = 
min(buf->ReadByte(), 31);
 
 7470       if (len >= 3) _cur_parameter->
num_bit = 
min(buf->ReadByte(), 32 - _cur_parameter->
first_bit);
 
 7481     grfmsg(2, 
"StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got " PRINTF_SIZE 
", ignoring this field", len);
 
 7484     _cur_parameter->
def_value = buf->ReadDWord();
 
 7517     this->handler.data = handler;
 
 7529     this->handler.text = handler;
 
 7541     this->handler.call_handler = 
true;
 
 7542     this->handler.u.branch = handler;
 
 7554     this->handler.call_handler = 
false;
 
 7555     this->handler.u.subtags = 
subtags;
 
 7584   byte type = buf->ReadByte();
 
 7586     uint32 
id = buf->ReadDWord();
 
 7587     if (type != 
'T' || 
id > _cur_parameter->
max_value) {
 
 7588       grfmsg(2, 
"StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id");
 
 7590       type = buf->ReadByte();
 
 7594     byte langid = buf->ReadByte();
 
 7595     const char *name_string = buf->ReadString();
 
 7606     type = buf->ReadByte();
 
 7631   byte type = buf->ReadByte();
 
 7633     uint32 
id = buf->ReadDWord();
 
 7635       grfmsg(2, 
"StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id");
 
 7637       type = buf->ReadByte();
 
 7644       MemSetT<GRFParameterInfo *>(newdata, 0, num_to_add);
 
 7651     if (!
HandleNodes(buf, _tags_parameters)) 
return false;
 
 7652     type = buf->ReadByte();
 
 7689       byte new_type = buf->ReadByte();
 
 7690       while (new_type != 0) {
 
 7693         new_type = buf->ReadByte();
 
 7704       uint16 size = buf->ReadWord();
 
 7728   while ((tag = &subtags[i++])->type != 0) {
 
 7731       default: NOT_REACHED();
 
 7734         byte langid = buf->ReadByte();
 
 7735         return tag->handler.
text(langid, buf->ReadString());
 
 7739         size_t len = buf->ReadWord();
 
 7740         if (buf->Remaining() < len) 
return false;
 
 7741         return tag->handler.
data(len, buf);
 
 7746           return tag->handler.u.branch(buf);
 
 7752   grfmsg(2, 
"StaticGRFInfo: unknown type/id combination found, type=%c, id=%x", type, 
id);
 
 7764   byte type = buf->ReadByte();
 
 7766     uint32 
id = buf->ReadDWord();
 
 7767     if (!
HandleNode(type, 
id, buf, subtags)) 
return false;
 
 7768     type = buf->ReadByte();
 
 7885   const GRFFile * 
const *end = _grf_files.
End();
 
 7886   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 7888     if (stations == NULL) 
continue;
 
 7890       if (stations[i] == NULL) 
continue;
 
 7896       if (!statspec->copied_layouts) {
 
 7897         for (uint l = 0; l < statspec->lengths; l++) {
 
 7898           for (uint p = 0; p < statspec->platforms[l]; p++) {
 
 7899             free(statspec->layouts[l][p]);
 
 7901           free(statspec->layouts[l]);
 
 7903         free(statspec->layouts);
 
 7904         free(statspec->platforms);
 
 7920   const GRFFile * 
const *end = _grf_files.
End();
 
 7921   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 7922     HouseSpec **&housespec = (*file)->housespec;
 
 7923     if (housespec == NULL) 
continue;
 
 7936   const GRFFile * 
const *end = _grf_files.
End();
 
 7937   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 7939     if (aslist != NULL) {
 
 7945           for (
int j = 0; j < as->
num_table; j++) {
 
 7956       (*file)->airportspec = NULL;
 
 7960     if (airporttilespec != NULL) {
 
 7962         free(airporttilespec[i]);
 
 7964       free(airporttilespec);
 
 7965       airporttilespec = NULL;
 
 7973   const GRFFile * 
const *end = _grf_files.
End();
 
 7974   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 7980     if (industryspec != NULL) {
 
 7983         if (ind == NULL) 
continue;
 
 7997       industryspec = NULL;
 
 8000     if (indtspec == NULL) 
continue;
 
 8013   const GRFFile * 
const *end = _grf_files.
End();
 
 8014   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 8015     ObjectSpec **&objectspec = (*file)->objectspec;
 
 8016     if (objectspec == NULL) 
continue;
 
 8018       free(objectspec[i]);
 
 8029   const GRFFile * 
const *end = _grf_files.
End();
 
 8030   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 8056   CleanUpGRFTownNames();
 
 8098   ObjectClass::Reset();
 
 8103   StationClass::Reset();
 
 8107   AirportClass::Reset();
 
 8130   _loaded_newgrf_features.
has_2CC           = 
false;
 
 8137   _grf_id_overrides.clear();
 
 8139   InitializeSoundPool();
 
 8187   if (newfile != NULL) {
 
 8193   newfile = 
new GRFFile(config);
 
 8211   for (
Price i = PR_BEGIN; i < PR_END; i++) {
 
 8235   free(this->filename);
 
 8245   'PASS', 
'COAL', 
'MAIL', 
'LVST', 
'GOOD', 
'GRAI', 
'WHEA', 
'MAIZ', 
'WOOD',
 
 8246   'IORE', 
'STEL', 
'VALU', 
'GOLD', 
'DIAM', 
'PAPR', 
'FOOD', 
'FRUT', 
'CORE',
 
 8247   'WATR', 
'SUGR', 
'TOYS', 
'BATT', 
'SWET', 
'TOFF', 
'COLA', 
'CTCD', 
'BUBL',
 
 8251 static const CargoLabel _default_refitmasks_road[] = {
 
 8254 static const CargoLabel _default_refitmasks_ships[] = {
 
 8255   'COAL', 
'MAIL', 
'LVST', 
'GOOD', 
'GRAI', 
'WHEA', 
'MAIZ', 
'WOOD', 
'IORE',
 
 8256   'STEL', 
'VALU', 
'GOLD', 
'DIAM', 
'PAPR', 
'FOOD', 
'FRUT', 
'CORE', 
'WATR',
 
 8257   'RUBR', 
'SUGR', 
'TOYS', 
'BATT', 
'SWET', 
'TOFF', 
'COLA', 
'CTCD', 
'BUBL',
 
 8261 static const CargoLabel _default_refitmasks_aircraft[] = {
 
 8262   'PASS', 
'MAIL', 
'GOOD', 
'VALU', 
'GOLD', 
'DIAM', 
'FOOD', 
'FRUT', 
'SUGR',
 
 8263   'TOYS', 
'BATT', 
'SWET', 
'TOFF', 
'COLA', 
'CTCD', 
'BUBL', 
'PLST', 
'FZDR',
 
 8266 static const CargoLabel * 
const _default_refitmasks[] = {
 
 8268   _default_refitmasks_road,
 
 8269   _default_refitmasks_ships,
 
 8270   _default_refitmasks_aircraft,
 
 8281   FOR_ALL_ENGINES(e) {
 
 8284     bool only_defaultcargo; 
 
 8289       uint32 not_mask = 0;
 
 8290       uint32 xor_mask = ei->refit_mask;
 
 8296       if (_gted[engine].cargo_allowed != 0) {
 
 8299         FOR_ALL_CARGOSPECS(cs) {
 
 8305       ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) & 
_cargo_mask;
 
 8311       uint32 xor_mask = 0;
 
 8316         for (uint i = 0;; i++) {
 
 8317           if (cl[i] == 0) 
break;
 
 8329       only_defaultcargo = (ei->refit_mask == 0);
 
 8343     if (ei->cargo_type == 
CT_INVALID && ei->refit_mask != 0) {
 
 8345       const uint8 *cargo_map_for_first_refittable = NULL;
 
 8348         if (file == NULL) file = e->
GetGRF();
 
 8349         if (file != NULL && file->grf_version >= 8 && file->
cargo_list.
Length() != 0) {
 
 8350           cargo_map_for_first_refittable = file->
cargo_map;
 
 8354       if (cargo_map_for_first_refittable != NULL) {
 
 8356         byte best_local_slot = 0xFF;
 
 8358         FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) {
 
 8359           byte local_slot = cargo_map_for_first_refittable[cargo_type];
 
 8360           if (local_slot < best_local_slot) {
 
 8361             best_local_slot = local_slot;
 
 8362             ei->cargo_type = cargo_type;
 
 8384   for (uint i = 0; i < CF_END; i++) {
 
 8397   FOR_ALL_ENGINES(e) {
 
 8398     if (e->
GetGRF() == NULL) {
 
 8401         e->info.
string_id = STR_NEWGRF_INVALID_ENGINE;
 
 8434           default: NOT_REACHED();
 
 8448       cs->
quantifier = STR_NEWGRF_INVALID_CARGO_QUANTITY;
 
 8449       cs->
abbrev = STR_NEWGRF_INVALID_CARGO_ABBREV;
 
 8473     if (filename != NULL) 
DEBUG(grf, 1, 
"FinaliseHouseArray: %s defines house %d as multitile, but no suitable tiles follow. Disabling house.", filename, hs->
grf_prop.
local_id);
 
 8483     if (filename != NULL) 
DEBUG(grf, 1, 
"FinaliseHouseArray: %s defines multitile house %d with non-zero population on additional tiles. Disabling house.", filename, hs->
grf_prop.
local_id);
 
 8491     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);
 
 8498     if (filename != NULL) 
DEBUG(grf, 1, 
"FinaliseHouseArray: %s defines house %d without a size but marked it as available. Disabling house.", filename, hs->
grf_prop.
local_id);
 
 8517     if (hs == NULL || !hs->
enabled) 
continue;
 
 8522   if (min_year == 0) 
return;
 
 8526     if (hs == NULL || !hs->
enabled) 
continue;
 
 8549   const GRFFile * 
const *end = _grf_files.
End();
 
 8550   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 8551     HouseSpec **&housespec = (*file)->housespec;
 
 8552     if (housespec == NULL) 
continue;
 
 8557       if (hs == NULL) 
continue;
 
 8559       const HouseSpec *next1 = (i + 1 < NUM_HOUSES_PER_GRF ? housespec[i + 1] : NULL);
 
 8560       const HouseSpec *next2 = (i + 2 < NUM_HOUSES_PER_GRF ? housespec[i + 2] : NULL);
 
 8561       const HouseSpec *next3 = (i + 3 < NUM_HOUSES_PER_GRF ? housespec[i + 3] : NULL);
 
 8563       if (!
IsHouseSpecValid(hs, next1, next2, next3, (*file)->filename)) 
continue;
 
 8571     const HouseSpec *next1 = (i + 1 < NUM_HOUSES ? HouseSpec::Get(i + 1) : NULL);
 
 8572     const HouseSpec *next2 = (i + 2 < NUM_HOUSES ? HouseSpec::Get(i + 2) : NULL);
 
 8573     const HouseSpec *next3 = (i + 3 < NUM_HOUSES ? HouseSpec::Get(i + 3) : NULL);
 
 8612   const GRFFile * 
const *end = _grf_files.
End();
 
 8613   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 8616     if (industryspec != NULL) {
 
 8620         if (indsp != NULL && indsp->
enabled) {
 
 8626           if (strid != STR_UNDEFINED) indsp->
name = strid;
 
 8629           if (strid != STR_UNDEFINED) indsp->
closure_text = strid;
 
 8644             if (strid != STR_UNDEFINED) indsp->
station_name = strid;
 
 8653     if (indtspec != NULL) {
 
 8656         if (indtsp != NULL) {
 
 8657           _industile_mngr.SetEntitySpec(indtsp);
 
 8666       for (uint i = 0; i < 3; i++) {
 
 8671       indsp->
name = STR_NEWGRF_INVALID_INDUSTRYTYPE;
 
 8683   const GRFFile * 
const *end = _grf_files.
End();
 
 8684   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 8685     ObjectSpec **&objectspec = (*file)->objectspec;
 
 8686     if (objectspec != NULL) {
 
 8688         if (objectspec[i] != NULL && objectspec[i]->grf_prop.grffile != NULL && objectspec[i]->
enabled) {
 
 8703   const GRFFile * 
const *end = _grf_files.
End();
 
 8704   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 8705     AirportSpec **&airportspec = (*file)->airportspec;
 
 8706     if (airportspec != NULL) {
 
 8708         if (airportspec[i] != NULL && airportspec[i]->enabled) {
 
 8709           _airport_mngr.SetEntitySpec(airportspec[i]);
 
 8715     if (airporttilespec != NULL) {
 
 8717         if (airporttilespec[i] != NULL && airporttilespec[i]->enabled) {
 
 8718           _airporttile_mngr.SetEntitySpec(airporttilespec[i]);
 
 8731 static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
 
 8745   static const SpecialSpriteHandler handlers[][GLS_END] = {
 
 8746      { NULL,     SafeChangeInfo, NULL,       NULL,           ReserveChangeInfo, FeatureChangeInfo, },
 
 8747      { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
 
 8748      { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
 
 8749      { NULL,     
GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
 
 8750      { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
 
 8751      { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },
 
 8752      { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
 
 8753      { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
 
 8754      { ScanInfo, NULL,      NULL,            GRFInfo,        GRFInfo,           GRFInfo, },
 
 8755      { NULL,     NULL,      NULL,            SkipIf,         SkipIf,            SkipIf, },
 
 8756      { SkipActA, SkipActA,  SkipActA,        SkipActA,       SkipActA,          SpriteReplace, },
 
 8757      { NULL,     NULL,      NULL,            GRFLoadError,   GRFLoadError,      GRFLoadError, },
 
 8758      { NULL,     NULL,      NULL,            GRFComment,     NULL,              GRFComment, },
 
 8760      { NULL,     SafeGRFInhibit, NULL,       GRFInhibit,     GRFInhibit,        GRFInhibit, },
 
 8763      { SkipAct11,
GRFUnsafe, SkipAct11,       GRFSound,       SkipAct11,         GRFSound, },
 
 8771   GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
 
 8772   if (it == _grf_line_to_action6_sprite_override.end()) {
 
 8778     buf = _grf_line_to_action6_sprite_override[location];
 
 8779     grfmsg(7, 
"DecodeSpecialSprite: Using preloaded pseudo sprite data");
 
 8789     byte action = bufp->ReadByte();
 
 8791     if (action == 0xFF) {
 
 8792       grfmsg(2, 
"DecodeSpecialSprite: Unexpected data block, skipping");
 
 8793     } 
else if (action == 0xFE) {
 
 8794       grfmsg(2, 
"DecodeSpecialSprite: Unexpected import block, skipping");
 
 8795     } 
else if (action >= 
lengthof(handlers)) {
 
 8796       grfmsg(7, 
"DecodeSpecialSprite: Skipping unknown action 0x%02X", action);
 
 8797     } 
else if (handlers[action][stage] == NULL) {
 
 8798       grfmsg(7, 
"DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage);
 
 8800       grfmsg(7, 
"DecodeSpecialSprite: Handling action 0x%02X in stage %d", action, stage);
 
 8801       handlers[action][stage](bufp);
 
 8804     grfmsg(1, 
"DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
 
 8811 extern const byte 
_grf_cont_v2_sig[8] = {
'G', 
'R', 
'F', 0x82, 0x0D, 0x0A, 0x1A, 0x0A};
 
 8824     for (uint i = 0; i < 
lengthof(_grf_cont_v2_sig); i++) {
 
 8825       if (
FioReadByte() != _grf_cont_v2_sig[i]) 
return 0; 
 
 8845   const char *filename = config->
filename;
 
 8856   if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
 
 8858     if (_cur.
grffile == NULL) 
usererror(
"File '%s' lost in cache.\n", filename);
 
 8865     DEBUG(grf, 0, 
"'%s' is not loaded as the maximum number of GRFs has been reached", filename);
 
 8867     config->
error  = 
new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
 
 8877   DEBUG(grf, 2, 
"LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
 
 8881     DEBUG(grf, 7, 
"LoadNewGRFFile: Custom .grf has invalid format");
 
 8885   if (stage == GLS_INIT || stage == GLS_ACTIVATION) {
 
 8897     if (compression != 0) {
 
 8898       DEBUG(grf, 7, 
"LoadNewGRFFile: Unsupported compression format");
 
 8910     DEBUG(grf, 7, 
"LoadNewGRFFile: Custom .grf has invalid format");
 
 8924         DecodeSpecialSprite(buf.
Allocate(num), num, stage);
 
 8935         grfmsg(0, 
"LoadNewGRFFile: Unexpected sprite, disabling");
 
 8936         DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
 
 9001   static const uint32 override_features = (1 << GSF_TRAINS) | (1 << GSF_ROADVEHICLES) | (1 << GSF_SHIPS) | (1 << GSF_AIRCRAFT);
 
 9004   int num_grfs = _grf_files.
Length();
 
 9005   int *grf_overrides = 
AllocaM(
int, num_grfs);
 
 9006   for (
int i = 0; i < num_grfs; i++) {
 
 9007     grf_overrides[i] = -1;
 
 9009     GRFFile *source = _grf_files[i];
 
 9010     uint32 
override = _grf_id_overrides[source->grfid];
 
 9011     if (
override == 0) 
continue;
 
 9014     if (dest == NULL) 
continue;
 
 9016     grf_overrides[i] = _grf_files.
FindIndex(dest);
 
 9017     assert(grf_overrides[i] >= 0);
 
 9021   for (
int i = 0; i < num_grfs; i++) {
 
 9022     if (grf_overrides[i] < 0 || grf_overrides[i] >= i) 
continue;
 
 9023     GRFFile *source = _grf_files[i];
 
 9024     GRFFile *dest = _grf_files[grf_overrides[i]];
 
 9030     for (
Price p = PR_BEGIN; p < PR_END; p++) {
 
 9033       DEBUG(grf, 3, 
"'%s' overrides price base multiplier %d of '%s'", source->filename, p, dest->filename);
 
 9039   for (
int i = num_grfs - 1; i >= 0; i--) {
 
 9040     if (grf_overrides[i] < 0 || grf_overrides[i] <= i) 
continue;
 
 9041     GRFFile *source = _grf_files[i];
 
 9042     GRFFile *dest = _grf_files[grf_overrides[i]];
 
 9048     for (
Price p = PR_BEGIN; p < PR_END; p++) {
 
 9051       DEBUG(grf, 3, 
"Price base multiplier %d from '%s' propagated to '%s'", p, source->filename, dest->filename);
 
 9057   for (
int i = 0; i < num_grfs; i++) {
 
 9058     if (grf_overrides[i] < 0) 
continue;
 
 9059     GRFFile *source = _grf_files[i];
 
 9060     GRFFile *dest = _grf_files[grf_overrides[i]];
 
 9066     for (
Price p = PR_BEGIN; p < PR_END; p++) {
 
 9067       if (!
HasBit(features, _price_base_specs[p].grf_feature)) 
continue;
 
 9069         DEBUG(grf, 3, 
"Price base multiplier %d from '%s' propagated to '%s'", p, dest->filename, source->filename);
 
 9076   const GRFFile * 
const *end = _grf_files.
End();
 
 9077   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 9078     if ((*file)->grf_version >= 8) 
continue;
 
 9079     PriceMultipliers &price_base_multipliers = (*file)->price_base_multipliers;
 
 9080     for (
Price p = PR_BEGIN; p < PR_END; p++) {
 
 9082       if (fallback_price != INVALID_PRICE && price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
 
 9085         price_base_multipliers[p] = price_base_multipliers[fallback_price];
 
 9091   for (
GRFFile **file = _grf_files.
Begin(); file != end; file++) {
 
 9092     PriceMultipliers &price_base_multipliers = (*file)->price_base_multipliers;
 
 9093     for (
Price p = PR_BEGIN; p < PR_END; p++) {
 
 9094       if (price_base_multipliers[p] == INVALID_PRICE_MODIFIER) {
 
 9096         price_base_multipliers[p] = 0;
 
 9101           DEBUG(grf, 3, 
"'%s' sets global price base multiplier %d", (*file)->filename, p);
 
 9103           price_base_multipliers[p] = 0;
 
 9105           DEBUG(grf, 3, 
"'%s' sets local price base multiplier %d", (*file)->filename, p);
 
 9120   _string_to_grf_mapping.
Clear();
 
 9123   for (GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.begin(); it != _grf_line_to_action6_sprite_override.end(); it++) {
 
 9126   _grf_line_to_action6_sprite_override.clear();
 
 9177   FOR_ALL_ENGINES_OF_TYPE(e, 
VEH_ROAD) {
 
 9190       e->u.rail.railtype = railtype;
 
 9200   _grm_sprites.clear();
 
 9248   for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
 
 9255     if (stage == GLS_RESERVE) {
 
 9256       static const uint32 overrides[][2] = {
 
 9257         { 0x44442202, 0x44440111 }, 
 
 9258         { 0x6D620402, 0x6D620401 }, 
 
 9259         { 0x4D656f20, 0x4D656F17 }, 
 
 9261       for (
size_t i = 0; i < 
lengthof(overrides); i++) {
 
 9266     uint slot = file_index;
 
 9275         DEBUG(grf, 0, 
"NewGRF file is missing '%s'; disabling", c->
filename);
 
 9282       if (stage == GLS_RESERVE) {
 
 9284       } 
else if (stage == GLS_ACTIVATION) {
 
 9289         DEBUG(sprite, 2, 
"LoadNewGRF: Currently %i sprites are loaded", _cur.
spriteid);