tron@2186: /* $Id$ */ tron@2186: belugas@6674: /** @file newgrf.cpp */ belugas@6674: truelight@0: #include "stdafx.h" truelight@0: truelight@0: #include truelight@0: Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" truelight@0: #include "gfx.h" truelight@0: #include "fileio.h" tron@2163: #include "functions.h" truelight@0: #include "engine.h" tron@2342: #include "spritecache.h" celestar@389: #include "station.h" darkvater@405: #include "sprite.h" dominik@452: #include "newgrf.h" tron@2159: #include "variables.h" Darkvater@3566: #include "string.h" peter1138@3821: #include "table/strings.h" peter1138@2478: #include "bridge.h" maedhros@6658: #include "town.h" peter1138@2506: #include "economy.h" peter1138@2962: #include "newgrf_engine.h" celestar@3577: #include "vehicle.h" belugas@3601: #include "newgrf_text.h" peter1138@3708: #include "table/sprites.h" peter1138@5108: #include "fontcache.h" rubidium@4293: #include "date.h" belugas@4377: #include "currency.h" maedhros@6669: #include "landscape.h" peter1138@4656: #include "sound.h" peter1138@5228: #include "newgrf_config.h" maedhros@6658: #include "newgrf_house.h" peter1138@4656: #include "newgrf_sound.h" peter1138@3595: #include "newgrf_spritegroup.h" rubidium@5838: #include "helpers.hpp" maedhros@6658: #include "table/town_land.h" peter1138@6417: #include "cargotype.h" richk@6719: #include "industry.h" richk@6719: #include "newgrf_canal.h" richk@6719: #include "newgrf_commons.h" peter1138@3595: truelight@0: /* TTDPatch extended GRF format codec truelight@0: * (c) Petr Baudis 2004 (GPL'd) celestar@356: * Changes by Florian octo Forster are (c) by the OpenTTD development team. celestar@356: * truelight@0: * Contains portions of documentation by TTDPatch team. truelight@0: * Thanks especially to Josef Drexler for the documentation as well as a lot truelight@0: * of help at #tycoon. Also thanks to Michael Blunck for is GRF files which truelight@0: * served as subject to the initial testing of this codec. */ truelight@0: dominik@455: tron@2342: static int _skip_sprites; // XXX tron@2342: static uint _file_index; // XXX peter1138@5209: SpriteID _signal_base; peter1138@5210: SpriteID _coast_base; truelight@0: tron@2340: static GRFFile *_cur_grffile; tron@1477: GRFFile *_first_grffile; peter1138@3707: static SpriteID _cur_spriteid; peter1138@5225: static GrfLoadingStage _cur_stage; Darkvater@3561: static uint32 _nfo_line; truelight@0: peter1138@5228: static GRFConfig *_cur_grfconfig; peter1138@5228: peter1138@3814: /* Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E */ peter1138@3814: static byte _misc_grf_features = 0; peter1138@3814: darkvater@363: /* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */ darkvater@363: static uint32 _ttdpatch_flags[8]; darkvater@363: peter1138@3895: /* Used by Action 0x06 to preload a pseudo sprite and modify its content */ peter1138@3895: static byte *_preload_sprite = NULL; peter1138@3895: richk@6719: /* Indicates which are the newgrf features currently loaded ingame */ richk@6719: uint8 _loaded_newgrf_features; darkvater@363: rubidium@6574: enum GrfDataType { peter1138@4656: GDT_SOUND, rubidium@6574: }; peter1138@4656: peter1138@4656: static byte _grf_data_blocks; peter1138@4656: static GrfDataType _grf_data_type; peter1138@4656: peter1138@4656: rubidium@6574: enum grfspec_feature { celestar@373: GSF_TRAIN, celestar@373: GSF_ROAD, celestar@373: GSF_SHIP, celestar@373: GSF_AIRCRAFT, celestar@373: GSF_STATION, peter1138@2438: GSF_CANAL, darkvater@391: GSF_BRIDGE, darkvater@391: GSF_TOWNHOUSE, peter1138@3620: GSF_GLOBALVAR, peter1138@3620: GSF_INDUSTRYTILES, belugas@3601: GSF_INDUSTRIES, peter1138@3620: GSF_CARGOS, peter1138@3620: GSF_SOUNDFX, richk@6719: GSF_FSMPORTS, rubidium@6574: }; celestar@373: celestar@373: truelight@0: typedef void (*SpecialSpriteHandler)(byte *buf, int len); truelight@0: peter1138@6607: static const uint _vehcounts[4] = { celestar@373: /* GSF_TRAIN */ NUM_TRAIN_ENGINES, celestar@373: /* GSF_ROAD */ NUM_ROAD_ENGINES, celestar@373: /* GSF_SHIP */ NUM_SHIP_ENGINES, celestar@373: /* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES celestar@372: }; celestar@372: peter1138@6607: static const uint _vehshifts[4] = { celestar@373: /* GSF_TRAIN */ 0, celestar@373: /* GSF_ROAD */ ROAD_ENGINES_INDEX, celestar@373: /* GSF_SHIP */ SHIP_ENGINES_INDEX, celestar@373: /* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX, truelight@0: }; truelight@0: peter1138@3768: enum { peter1138@3768: MAX_STATIONS = 256, richk@6719: MAX_FSM_PORTS = 256, peter1138@3768: }; peter1138@3768: peter1138@2611: static uint16 cargo_allowed[TOTAL_NUM_ENGINES]; peter1138@2611: static uint16 cargo_disallowed[TOTAL_NUM_ENGINES]; truelight@0: peter1138@4961: /* Contains the GRF ID of the owner of a vehicle if it has been reserved */ peter1138@4961: static uint32 _grm_engines[TOTAL_NUM_ENGINES]; peter1138@4961: richk@6719: /* Contains the GRF ID of the owner of a cargo if it has been reserved */ richk@6719: static uint32 _grm_cargos[NUM_CARGO]; richk@6719: Darkvater@5568: /** DEBUG() function dedicated to newGRF debugging messages Darkvater@5568: * Function is essentialy the same as DEBUG(grf, severity, ...) with the Darkvater@5568: * addition of file:line information when parsing grf files. Darkvater@5568: * NOTE: for the above reason(s) grfmsg() should ONLY be used for Darkvater@5568: * loading/parsing grf files, not for runtime debug messages as there Darkvater@5568: * is no file information available during that time. Darkvater@5568: * @param severity debugging severity level, see debug.h richk@6719: * @param str message in printf() format */ Darkvater@5568: void CDECL grfmsg(int severity, const char *str, ...) truelight@0: { darkvater@65: char buf[1024]; truelight@0: va_list va; truelight@0: truelight@0: va_start(va, str); tron@1477: vsnprintf(buf, sizeof(buf), str, va); truelight@0: va_end(va); celestar@372: Darkvater@5568: DEBUG(grf, severity, "[%s:%d] %s", _cur_grfconfig->filename, _nfo_line, buf); truelight@0: } truelight@0: peter1138@5841: static inline bool check_length(int real, int wanted, const char *str) Darkvater@5567: { peter1138@5841: if (real >= wanted) return true; Darkvater@5567: grfmsg(0, "%s: Invalid pseudo sprite length %d (expected %d)!", str, real, wanted); peter1138@5841: return false; Darkvater@5567: } celestar@357: tron@500: static inline byte grf_load_byte(byte **buf) darkvater@368: { truelight@0: return *(*buf)++; truelight@0: } truelight@0: truelight@0: static uint16 grf_load_word(byte **buf) truelight@0: { Darkvater@3711: uint16 val = grf_load_byte(buf); Darkvater@3711: return val | (grf_load_byte(buf) << 8); truelight@0: } truelight@0: tron@2346: static uint16 grf_load_extended(byte** buf) tron@2346: { tron@2346: uint16 val; tron@2346: val = grf_load_byte(buf); tron@2346: if (val == 0xFF) val = grf_load_word(buf); tron@2346: return val; tron@2346: } tron@2346: miham@2324: static uint32 grf_load_dword(byte **buf) truelight@0: { Darkvater@3711: uint32 val = grf_load_word(buf); Darkvater@3711: return val | (grf_load_word(buf) << 16); truelight@0: } truelight@0: peter1138@3668: static uint32 grf_load_var(byte size, byte **buf) peter1138@3668: { peter1138@3668: switch (size) { peter1138@3668: case 1: return grf_load_byte(buf); peter1138@3668: case 2: return grf_load_word(buf); peter1138@3668: case 4: return grf_load_dword(buf); peter1138@3668: default: peter1138@3668: NOT_REACHED(); peter1138@3668: return 0; peter1138@3668: } peter1138@3668: } celestar@357: maedhros@6416: static const char *grf_load_string(byte **buf, size_t max_len) maedhros@6416: { maedhros@6416: const char *string = *(const char **)buf; maedhros@6416: size_t string_length = ttd_strnlen(string, max_len); maedhros@6416: maedhros@6416: if (string_length == max_len) { maedhros@6416: /* String was not NUL terminated, so make sure it is now. */ maedhros@6416: (*buf)[string_length - 1] = '\0'; maedhros@6416: grfmsg(7, "String was not terminated with a zero byte."); maedhros@6416: } else { maedhros@6416: /* Increase the string length to include the NUL byte. */ maedhros@6416: string_length++; maedhros@6416: } maedhros@6416: *buf += string_length; maedhros@6416: maedhros@6416: return string; maedhros@6416: } maedhros@6416: tron@1477: static GRFFile *GetFileByGRFID(uint32 grfid) darkvater@366: { tron@1477: GRFFile *file; darkvater@366: tron@1477: for (file = _first_grffile; file != NULL; file = file->next) { tron@1477: if (file->grfid == grfid) break; tron@1477: } darkvater@366: return file; darkvater@366: } darkvater@366: tron@1477: static GRFFile *GetFileByFilename(const char *filename) darkvater@366: { tron@1477: GRFFile *file; darkvater@366: tron@1477: for (file = _first_grffile; file != NULL; file = file->next) { tron@1477: if (strcmp(file->filename, filename) == 0) break; tron@1477: } darkvater@366: return file; darkvater@366: } darkvater@366: darkvater@366: maedhros@6658: /** Used when setting an object's property to map to the GRF's strings maedhros@6658: * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one richk@6719: * @param grfid Id of the grf file maedhros@6658: * @param str StringID that we want to have the equivalent in OoenTTD maedhros@6658: * @return the properly adjusted StringID maedhros@6658: */ peter1138@6685: static StringID MapGRFStringID(uint32 grfid, StringID str) maedhros@6658: { maedhros@6658: /* 0xD0 and 0xDC stand for all the TextIDs in the range belugas@6674: * of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts). maedhros@6658: * These strings are unique to each grf file, and thus require to be used with the maedhros@6658: * grfid in which they are declared */ maedhros@6658: if (GB(str, 8, 8) == 0xD0 || GB(str, 8, 8) == 0xDC) { peter1138@6685: return GetGRFStringID(grfid, str); maedhros@6658: } maedhros@6658: peter1138@6685: /* We have some changes in our cargo strings, resulting in some missing. */ peter1138@6685: if (str >= 0x006E && str <= 0x008D) return str - 0x20; peter1138@6685: if (str >= 0x008E && str <= 0x00AD) return str - 0x20; peter1138@6685: maedhros@6658: /* Map building names according to our lang file changes maedhros@6658: * 0x200F = Tall Office Block, first house name in the original data, the one that TTDPatch stil uses maedhros@6658: * 0x201F = Old houses is the last house name. maedhros@6658: * OpenTTD does not have exactly the same order aymore, so, the code below allows maedhros@6658: * to compensate for the difference */ maedhros@6658: if (str >= 0x200F && str <= 0x201F) return str + (STR_200F_TALL_OFFICE_BLOCK - 0x200F); maedhros@6658: maedhros@6658: return str; maedhros@6658: } maedhros@6658: peter1138@6701: static uint8 MapDOSColour(uint8 colour) peter1138@6701: { peter1138@6701: if (_use_dos_palette) return colour; peter1138@6701: peter1138@6701: if (colour < 10) { peter1138@6701: static uint8 dos_to_win_colour_map[] = { 0, 215, 216, 136, 88, 106, 32, 33, 40, 245 }; peter1138@6701: return dos_to_win_colour_map[colour]; peter1138@6701: } peter1138@6701: peter1138@6701: if (colour >= 245 && colour < 254) return colour - 28; peter1138@6701: peter1138@6701: return colour; peter1138@6701: } peter1138@6701: maedhros@6658: darkvater@360: typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len); truelight@0: miham@439: #define FOR_EACH_OBJECT for (i = 0; i < numinfo; i++) truelight@0: truelight@0: static void dewagonize(int condition, int engine) truelight@0: { truelight@0: EngineInfo *ei = &_engine_info[engine]; truelight@0: RailVehicleInfo *rvi = &_rail_vehicle_info[engine]; truelight@0: celestar@372: if (condition != 0) { truelight@0: ei->unk2 &= ~0x80; belugas@6356: if (rvi->railveh_type == RAILVEH_WAGON) belugas@6356: rvi->railveh_type = RAILVEH_SINGLEHEAD; truelight@0: } else { truelight@0: ei->unk2 |= 0x80; belugas@6119: rvi->railveh_type = RAILVEH_WAGON; truelight@0: } truelight@0: } truelight@0: darkvater@360: static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) truelight@0: { truelight@0: EngineInfo *ei = &_engine_info[engine]; truelight@0: RailVehicleInfo *rvi = &_rail_vehicle_info[engine]; truelight@0: byte *buf = *bufp; truelight@0: int i; darkvater@360: bool ret = false; truelight@0: truelight@0: switch (prop) { belugas@6674: case 0x05: // Track type miham@439: FOR_EACH_OBJECT { truelight@0: uint8 tracktype = grf_load_byte(&buf); truelight@0: peter1138@3026: switch (tracktype) { richk@6719: case 0: rvi[i].railtype = rvi[i].engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break; tron@6014: case 1: rvi[i].railtype = RAILTYPE_MONO; break; tron@6014: case 2: rvi[i].railtype = RAILTYPE_MAGLEV; break; peter1138@3026: default: Darkvater@5568: grfmsg(1, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype); peter1138@3026: break; peter1138@3026: } truelight@0: } peter1138@3026: break; peter1138@3026: belugas@6674: case 0x08: // AI passenger service belugas@6674: /* @todo missing feature */ peter1138@3089: FOR_EACH_OBJECT grf_load_byte(&buf); darkvater@360: ret = true; peter1138@3089: break; peter1138@3089: belugas@6674: case 0x09: // Speed (1 unit is 1 kmh) miham@439: FOR_EACH_OBJECT { truelight@0: uint16 speed = grf_load_word(&buf); tron@3033: if (speed == 0xFFFF) speed = 0; truelight@0: truelight@0: rvi[i].max_speed = speed; truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0B: // Power miham@439: FOR_EACH_OBJECT { truelight@0: uint16 power = grf_load_word(&buf); truelight@0: belugas@6119: if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) power /= 2; hackykid@1894: truelight@0: rvi[i].power = power; truelight@0: dewagonize(power, engine + i); truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0D: // Running cost factor miham@439: FOR_EACH_OBJECT { truelight@0: uint8 runcostfact = grf_load_byte(&buf); truelight@0: belugas@6119: if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) runcostfact /= 2; peter1138@2836: truelight@0: rvi[i].running_cost_base = runcostfact; truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0E: // Running cost base miham@439: FOR_EACH_OBJECT { truelight@0: uint32 base = grf_load_dword(&buf); truelight@0: truelight@0: switch (base) { peter1138@2840: case 0x4C30: rvi[i].running_cost_class = 0; break; peter1138@2840: case 0x4C36: rvi[i].running_cost_class = 1; break; peter1138@2840: case 0x4C3C: rvi[i].running_cost_class = 2; break; belugas@6674: case 0: break; // Used by wagons peter1138@5324: default: Darkvater@5568: grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base); peter1138@5324: break; truelight@0: } truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x12: // Sprite ID miham@439: FOR_EACH_OBJECT { truelight@0: uint8 spriteid = grf_load_byte(&buf); truelight@0: peter1138@2895: /* TTD sprite IDs point to a location in a 16bit array, but we use it peter1138@2895: * as an array index, so we need it to be half the original value. */ tron@3033: if (spriteid < 0xFD) spriteid >>= 1; peter1138@2895: truelight@0: rvi[i].image_index = spriteid; truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x13: // Dual-headed miham@439: FOR_EACH_OBJECT { truelight@0: uint8 dual = grf_load_byte(&buf); truelight@0: celestar@372: if (dual != 0) { belugas@6119: if (rvi[i].railveh_type != RAILVEH_MULTIHEAD) { peter1138@2836: // adjust power and running cost if needed hackykid@1894: rvi[i].power /= 2; peter1138@2836: rvi[i].running_cost_base /= 2; peter1138@2836: } belugas@6119: rvi[i].railveh_type = RAILVEH_MULTIHEAD; truelight@0: } else { belugas@6119: if (rvi[i].railveh_type == RAILVEH_MULTIHEAD) { peter1138@2836: // adjust power and running cost if needed hackykid@1894: rvi[i].power *= 2; peter1138@2840: rvi[i].running_cost_base *= 2; peter1138@2836: } peter1138@6126: rvi[i].railveh_type = rvi[i].power == 0 ? peter1138@6126: RAILVEH_WAGON : RAILVEH_SINGLEHEAD; truelight@0: } truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x14: // Cargo capacity peter1138@3089: FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x15: // Cargo type miham@439: FOR_EACH_OBJECT { truelight@0: uint8 ctype = grf_load_byte(&buf); truelight@0: peter1138@6606: if (ctype < NUM_CARGO && HASBIT(_cargo_mask, ctype)) { peter1138@2846: rvi[i].cargo_type = ctype; peter1138@2846: } else { peter1138@6468: rvi[i].cargo_type = CT_INVALID; peter1138@6468: grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype); peter1138@2846: } truelight@0: } peter1138@3023: break; peter1138@3023: belugas@6674: case 0x16: // Weight peter1138@3089: FOR_EACH_OBJECT SB(rvi[i].weight, 0, 8, grf_load_byte(&buf)); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x17: // Cost factor peter1138@3089: FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x18: // AI rank peter1138@3089: FOR_EACH_OBJECT rvi[i].ai_rank = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x19: // Engine traction type peter1138@2838: /* What do the individual numbers mean? peter1138@2838: * 0x00 .. 0x07: Steam peter1138@2838: * 0x08 .. 0x27: Diesel peter1138@2838: * 0x28 .. 0x31: Electric peter1138@2838: * 0x32 .. 0x37: Monorail peter1138@2838: * 0x38 .. 0x41: Maglev peter1138@2838: */ miham@439: FOR_EACH_OBJECT { truelight@0: uint8 traction = grf_load_byte(&buf); richk@6719: EngineClass engclass; truelight@0: tron@3033: if (traction <= 0x07) { richk@6719: engclass = EC_STEAM; tron@3033: } else if (traction <= 0x27) { richk@6719: engclass = EC_DIESEL; celestar@3355: } else if (traction <= 0x31) { richk@6719: engclass = EC_ELECTRIC; richk@6719: } else if (traction <= 0x37) { richk@6719: engclass = EC_MONORAIL; tron@3033: } else if (traction <= 0x41) { richk@6719: engclass = EC_MAGLEV; tron@3033: } else { truelight@0: break; tron@3033: } richk@6719: if (rvi[i].railtype == RAILTYPE_RAIL && engclass >= EC_ELECTRIC) rvi[i].railtype = RAILTYPE_ELECTRIC; richk@6719: if (rvi[i].railtype == RAILTYPE_ELECTRIC && engclass < EC_ELECTRIC) rvi[i].railtype = RAILTYPE_RAIL; truelight@0: truelight@0: rvi[i].engclass = engclass; truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1A: // Alter purchase list sort order peter1138@2971: FOR_EACH_OBJECT { peter1138@2971: EngineID pos = grf_load_byte(&buf); peter1138@2971: peter1138@2971: if (pos < NUM_TRAIN_ENGINES) { peter1138@2971: AlterRailVehListOrder(engine + i, pos); peter1138@2971: } else { Darkvater@5568: grfmsg(2, "RailVehicleChangeInfo: Invalid train engine ID %d, ignoring", pos); peter1138@2971: } peter1138@2971: } peter1138@2971: break; peter1138@2971: belugas@6674: case 0x1B: // Powered wagons power bonus peter1138@3089: FOR_EACH_OBJECT rvi[i].pow_wag_power = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1C: // Refit cost peter1138@3997: FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf); peter1138@3997: break; peter1138@3997: belugas@6674: case 0x1D: // Refit cargo peter1138@3095: FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1E: // Callback peter1138@3956: FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1F: // Tractive effort coefficient peter1138@5588: FOR_EACH_OBJECT rvi[i].tractive_effort = grf_load_byte(&buf); peter1138@5588: break; peter1138@5588: belugas@6674: case 0x21: // Shorter vehicle peter1138@3089: FOR_EACH_OBJECT rvi[i].shorten_factor = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x22: // Visual effect belugas@6674: /* see note in engine.h about rvi->visual_effect */ peter1138@3089: FOR_EACH_OBJECT rvi[i].visual_effect = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x23: // Powered wagons weight bonus peter1138@3089: FOR_EACH_OBJECT rvi[i].pow_wag_weight = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x24: // High byte of vehicle weight peter1138@2542: FOR_EACH_OBJECT { peter1138@2542: byte weight = grf_load_byte(&buf); peter1138@2542: peter1138@2545: if (weight > 4) { Darkvater@5568: grfmsg(2, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8); peter1138@2542: } else { peter1138@2542: SB(rvi[i].weight, 8, 8, weight); peter1138@2542: } peter1138@2542: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x25: // User-defined bit mask to set when checking veh. var. 42 peter1138@3862: FOR_EACH_OBJECT rvi[i].user_def_data = grf_load_byte(&buf); peter1138@3862: break; peter1138@3862: richk@6719: case 0x26: // Retire vehicle early richk@6719: FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf); richk@6719: break; richk@6719: belugas@6674: case 0x27: // Miscellaneous flags peter1138@4742: FOR_EACH_OBJECT { peter1138@4742: ei[i].misc_flags = grf_load_byte(&buf); richk@6719: if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); peter1138@4742: } peter1138@3095: break; peter1138@3095: belugas@6674: case 0x28: // Cargo classes allowed peter1138@3089: FOR_EACH_OBJECT cargo_allowed[engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x29: // Cargo classes disallowed peter1138@3089: FOR_EACH_OBJECT cargo_disallowed[engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x2A: // Long format introduction date (days since year 0) peter1138@5114: FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf); peter1138@5114: break; peter1138@5114: belugas@6674: /* @todo air drag and retire vehicle early belugas@6674: * Fall-through for unimplemented one byte long properties. */ belugas@6674: case 0x20: // Air drag peter1138@3089: FOR_EACH_OBJECT grf_load_byte(&buf); darkvater@360: ret = true; peter1138@3089: break; peter1138@3089: truelight@0: default: darkvater@360: ret = true; peter1138@3089: break; truelight@0: } truelight@0: *bufp = buf; truelight@0: return ret; truelight@0: } truelight@0: celestar@378: static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) celestar@378: { peter1138@3095: EngineInfo *ei = &_engine_info[ROAD_ENGINES_INDEX + engine]; celestar@378: RoadVehicleInfo *rvi = &_road_vehicle_info[engine]; celestar@378: byte *buf = *bufp; celestar@378: int i; celestar@378: bool ret = false; celestar@378: celestar@378: switch (prop) { belugas@6674: case 0x08: // Speed (1 unit is 0.5 kmh) peter1138@3488: FOR_EACH_OBJECT rvi[i].max_speed = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x09: // Running cost factor peter1138@3089: FOR_EACH_OBJECT rvi[i].running_cost = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0A: // Running cost base belugas@6674: /* @todo : I have no idea. --pasky belugas@6674: * I THINK it is used for overriding the base cost of all road vehicle (_price.roadveh_base) --belugas */ peter1138@3089: FOR_EACH_OBJECT grf_load_dword(&buf); celestar@378: ret = true; peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0E: // Sprite ID miham@439: FOR_EACH_OBJECT { celestar@378: uint8 spriteid = grf_load_byte(&buf); celestar@378: belugas@6674: /* cars have different custom id in the GRF file */ tron@3033: if (spriteid == 0xFF) spriteid = 0xFD; tron@3033: tron@3033: if (spriteid < 0xFD) spriteid >>= 1; peter1138@2895: celestar@378: rvi[i].image_index = spriteid; celestar@378: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0F: // Cargo capacity peter1138@3089: FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x10: // Cargo type miham@439: FOR_EACH_OBJECT { celestar@378: uint8 cargo = grf_load_byte(&buf); celestar@378: peter1138@6606: if (cargo < NUM_CARGO && HASBIT(_cargo_mask, cargo)) { peter1138@2846: rvi[i].cargo_type = cargo; peter1138@2846: } else { peter1138@6468: rvi[i].cargo_type = CT_INVALID; peter1138@6468: grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo); peter1138@2846: } celestar@378: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x11: // Cost factor peter1138@3089: FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost? peter1138@3089: break; peter1138@3089: belugas@6674: case 0x12: // SFX rubidium@5838: FOR_EACH_OBJECT rvi[i].sfx = (SoundFx)grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x13: // Power in 10hp belugas@6674: case 0x14: // Weight in 1/4 tons belugas@6674: case 0x15: // Speed in mph*0.8 celestar@378: /* TODO: Support for road vehicles realistic power celestar@378: * computations (called rvpower in TTDPatch) is just celestar@378: * missing in OTTD yet. --pasky */ peter1138@3089: FOR_EACH_OBJECT grf_load_byte(&buf); celestar@378: ret = true; celestar@378: break; peter1138@3089: belugas@6674: case 0x16: // Cargos available for refitting peter1138@3095: FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf); peter1138@3006: break; peter1138@3006: belugas@6674: case 0x17: // Callback mask peter1138@3956: FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1A: // Refit cost peter1138@3997: FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf); peter1138@3997: break; peter1138@3997: richk@6719: case 0x1B: // Retire vehicle early richk@6719: FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf); richk@6719: break; richk@6719: belugas@6674: case 0x1C: // Miscellaneous flags peter1138@4952: FOR_EACH_OBJECT { peter1138@4952: ei[i].misc_flags = grf_load_byte(&buf); richk@6719: if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); peter1138@4952: } peter1138@3095: break; peter1138@3095: belugas@6674: case 0x1D: // Cargo classes allowed peter1138@3089: FOR_EACH_OBJECT cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1E: // Cargo classes disallowed peter1138@3089: FOR_EACH_OBJECT cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1F: // Long format introduction date (days since year 0) peter1138@5114: FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf); peter1138@5114: break; peter1138@5114: belugas@6674: case 0x18: // Tractive effort belugas@6674: case 0x19: // Air drag belugas@6674: /* @todo */ peter1138@3089: FOR_EACH_OBJECT grf_load_byte(&buf); celestar@378: ret = true; celestar@378: break; peter1138@3089: celestar@378: default: celestar@378: ret = true; peter1138@3089: break; celestar@378: } celestar@378: celestar@378: *bufp = buf; celestar@378: return ret; celestar@378: } celestar@378: darkvater@360: static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) truelight@0: { peter1138@3095: EngineInfo *ei = &_engine_info[SHIP_ENGINES_INDEX + engine]; truelight@0: ShipVehicleInfo *svi = &_ship_vehicle_info[engine]; truelight@0: byte *buf = *bufp; truelight@0: int i; darkvater@360: bool ret = false; truelight@0: truelight@0: //printf("e %x prop %x?\n", engine, prop); truelight@0: switch (prop) { belugas@6674: case 0x08: // Sprite ID miham@439: FOR_EACH_OBJECT { truelight@0: uint8 spriteid = grf_load_byte(&buf); truelight@0: belugas@6674: /* ships have different custom id in the GRF file */ tron@3033: if (spriteid == 0xFF) spriteid = 0xFD; tron@3033: tron@3033: if (spriteid < 0xFD) spriteid >>= 1; peter1138@2895: truelight@0: svi[i].image_index = spriteid; truelight@0: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x09: // Refittable rubidium@5838: FOR_EACH_OBJECT svi[i].refittable = (grf_load_byte(&buf) != 0); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0A: // Cost factor peter1138@3089: FOR_EACH_OBJECT svi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost? peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0B: // Speed (1 unit is 0.5 kmh) peter1138@3488: FOR_EACH_OBJECT svi[i].max_speed = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0C: // Cargo type miham@439: FOR_EACH_OBJECT { truelight@0: uint8 cargo = grf_load_byte(&buf); truelight@0: peter1138@6606: if (cargo < NUM_CARGO && HASBIT(_cargo_mask, cargo)) { peter1138@2846: svi[i].cargo_type = cargo; peter1138@2846: } else { peter1138@6468: svi[i].cargo_type = CT_INVALID; peter1138@6468: grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo); peter1138@2846: } truelight@0: } peter1138@3006: break; peter1138@3006: belugas@6674: case 0x0D: // Cargo capacity peter1138@3089: FOR_EACH_OBJECT svi[i].capacity = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0F: // Running cost factor peter1138@3089: FOR_EACH_OBJECT svi[i].running_cost = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x10: // SFX rubidium@5838: FOR_EACH_OBJECT svi[i].sfx = (SoundFx)grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x11: // Cargos available for refitting peter1138@3095: FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x12: // Callback mask peter1138@3956: FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x13: // Refit cost peter1138@3997: FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf); peter1138@3997: break; peter1138@3997: richk@6719: case 0x16: // Retire vehicle early richk@6719: FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf); richk@6719: break; richk@6719: belugas@6674: case 0x17: // Miscellaneous flags peter1138@4952: FOR_EACH_OBJECT { peter1138@4952: ei[i].misc_flags = grf_load_byte(&buf); richk@6719: if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); peter1138@4952: } peter1138@3095: break; peter1138@3095: belugas@6674: case 0x18: // Cargo classes allowed peter1138@3089: FOR_EACH_OBJECT cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x19: // Cargo classes disallowed peter1138@3089: FOR_EACH_OBJECT cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1A: // Long format introduction date (days since year 0) peter1138@5114: FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf); peter1138@5114: break; peter1138@5114: belugas@6674: case 0x14: // Ocean speed fraction belugas@6674: case 0x15: // Canal speed fraction belugas@6674: /* @todo */ peter1138@3089: FOR_EACH_OBJECT grf_load_byte(&buf); darkvater@360: ret = true; peter1138@3089: break; peter1138@3089: truelight@0: default: darkvater@360: ret = true; peter1138@3089: break; truelight@0: } truelight@0: truelight@0: *bufp = buf; truelight@0: return ret; truelight@0: } truelight@0: darkvater@381: static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len) darkvater@381: { peter1138@3095: EngineInfo *ei = &_engine_info[AIRCRAFT_ENGINES_INDEX + engine]; darkvater@381: AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine]; darkvater@381: byte *buf = *bufp; darkvater@381: int i; darkvater@381: bool ret = false; darkvater@381: darkvater@381: //printf("e %x prop %x?\n", engine, prop); darkvater@381: switch (prop) { belugas@6674: case 0x08: // Sprite ID miham@439: FOR_EACH_OBJECT { darkvater@381: uint8 spriteid = grf_load_byte(&buf); darkvater@381: belugas@6674: /* aircraft have different custom id in the GRF file */ tron@3033: if (spriteid == 0xFF) spriteid = 0xFD; tron@3033: tron@3033: if (spriteid < 0xFD) spriteid >>= 1; peter1138@2895: darkvater@381: avi[i].image_index = spriteid; darkvater@381: } peter1138@3006: break; peter1138@3006: belugas@6674: case 0x09: // Helicopter peter1138@4926: FOR_EACH_OBJECT { peter1138@4926: if (grf_load_byte(&buf) == 0) { Darkvater@6106: avi[i].subtype = AIR_HELI; peter1138@4926: } else { Darkvater@6106: SB(avi[i].subtype, 0, 1, 1); // AIR_CTOL peter1138@4926: } peter1138@4926: } peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0A: // Large Darkvater@6106: FOR_EACH_OBJECT SB(avi[i].subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0B: // Cost factor peter1138@3089: FOR_EACH_OBJECT avi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost? peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0C: // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h) celestar@6519: FOR_EACH_OBJECT avi[i].max_speed = (grf_load_byte(&buf) * 129) / 10; peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0D: // Acceleration celestar@6519: FOR_EACH_OBJECT avi[i].acceleration = (grf_load_byte(&buf) * 129) / 10; peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0E: // Running cost factor peter1138@3089: FOR_EACH_OBJECT avi[i].running_cost = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x0F: // Passenger capacity peter1138@3089: FOR_EACH_OBJECT avi[i].passenger_capacity = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x11: // Mail capacity peter1138@3089: FOR_EACH_OBJECT avi[i].mail_capacity = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x12: // SFX rubidium@5838: FOR_EACH_OBJECT avi[i].sfx = (SoundFx)grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x13: // Cargos available for refitting peter1138@3095: FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x14: // Callback mask peter1138@3956: FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x15: // Refit cost peter1138@3997: FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf); peter1138@3997: break; peter1138@3997: richk@6719: case 0x16: // Retire vehicle early richk@6719: FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf); richk@6719: break; richk@6719: belugas@6674: case 0x17: // Miscellaneous flags peter1138@4952: FOR_EACH_OBJECT { peter1138@4952: ei[i].misc_flags = grf_load_byte(&buf); richk@6719: if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC); peter1138@4952: } peter1138@3095: break; peter1138@3095: belugas@6674: case 0x18: // Cargo classes allowed peter1138@3089: FOR_EACH_OBJECT cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x19: // Cargo classes disallowed peter1138@3089: FOR_EACH_OBJECT cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x1A: // Long format introduction date (days since year 0) peter1138@5114: FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf); peter1138@5114: break; peter1138@5114: darkvater@381: default: darkvater@381: ret = true; peter1138@3089: break; darkvater@381: } darkvater@381: darkvater@381: *bufp = buf; darkvater@381: return ret; darkvater@381: } darkvater@381: celestar@389: static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len) celestar@389: { peter1138@3768: StationSpec **statspec; celestar@389: byte *buf = *bufp; celestar@389: int i; peter1138@3505: bool ret = false; celestar@389: peter1138@3768: if (stid + numinfo > MAX_STATIONS) { Darkvater@5568: grfmsg(1, "StationChangeInfo: Station %u is invalid, max %u, ignoring", stid + numinfo, MAX_STATIONS); peter1138@3768: return false; peter1138@3768: } peter1138@3768: peter1138@3501: /* Allocate station specs if necessary */ KUDr@5860: if (_cur_grffile->stations == NULL) _cur_grffile->stations = CallocT(MAX_STATIONS); peter1138@3768: peter1138@3768: statspec = &_cur_grffile->stations[stid]; peter1138@3768: peter1138@3768: if (prop != 0x08) { peter1138@3768: /* Check that all stations we are modifying are defined. */ peter1138@3768: FOR_EACH_OBJECT { peter1138@3768: if (statspec[i] == NULL) { Darkvater@5568: grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i); peter1138@3768: return false; peter1138@3768: } peter1138@3501: } peter1138@3501: } peter1138@3501: celestar@389: switch (prop) { belugas@6674: case 0x08: // Class ID miham@439: FOR_EACH_OBJECT { peter1138@3768: /* Property 0x08 is special; it is where the station is allocated */ KUDr@5860: if (statspec[i] == NULL) statspec[i] = CallocT(1); peter1138@3768: Darkvater@3711: /* Swap classid because we read it in BE meaning WAYP or DFLT */ peter1138@6607: uint32 classid = grf_load_dword(&buf); peter1138@3768: statspec[i]->sclass = AllocateStationClass(BSWAP32(classid)); celestar@389: } celestar@389: break; peter1138@3505: belugas@6674: case 0x09: // Define sprite layout miham@439: FOR_EACH_OBJECT { peter1138@3768: StationSpec *statspec = _cur_grffile->stations[stid + i]; darkvater@398: belugas@3676: statspec->tiles = grf_load_extended(&buf); KUDr@5860: statspec->renderdata = CallocT(statspec->tiles); peter1138@3740: statspec->copied_renderdata = false; peter1138@3740: peter1138@6607: for (uint t = 0; t < statspec->tiles; t++) { belugas@3676: DrawTileSprites *dts = &statspec->renderdata[t]; peter1138@3570: uint seq_count = 0; peter1138@2625: peter1138@3737: dts->seq = NULL; peter1138@5919: dts->ground_sprite = grf_load_word(&buf); peter1138@5919: dts->ground_pal = grf_load_word(&buf); peter1138@3775: if (dts->ground_sprite == 0) continue; peter1138@5919: if (HASBIT(dts->ground_pal, 15)) { peter1138@5919: CLRBIT(dts->ground_pal, 15); peter1138@5919: SETBIT(dts->ground_sprite, SPRITE_MODIFIER_USE_OFFSET); peter1138@5919: } peter1138@2625: celestar@389: while (buf < *bufp + len) { celestar@389: DrawTileSeqStruct *dtss; celestar@389: belugas@6674: /* no relative bounding box support */ KUDr@5860: dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count); celestar@389: dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1]; celestar@389: celestar@389: dtss->delta_x = grf_load_byte(&buf); celestar@389: if ((byte) dtss->delta_x == 0x80) break; celestar@389: dtss->delta_y = grf_load_byte(&buf); celestar@389: dtss->delta_z = grf_load_byte(&buf); tron@4230: dtss->size_x = grf_load_byte(&buf); tron@4230: dtss->size_y = grf_load_byte(&buf); tron@4230: dtss->size_z = grf_load_byte(&buf); peter1138@5919: dtss->image = grf_load_word(&buf); peter1138@5919: dtss->pal = grf_load_word(&buf); peter1138@3771: peter1138@3775: /* Remap flags as ours collide */ peter1138@5919: if (HASBIT(dtss->pal, 15)) { peter1138@5919: CLRBIT(dtss->pal, 15); peter1138@5919: SETBIT(dtss->image, SPRITE_MODIFIER_USE_OFFSET); peter1138@5919: } peter1138@5919: peter1138@5919: if (HASBIT(dtss->image, 15)) { peter1138@5919: CLRBIT(dtss->image, 15); peter1138@5919: SETBIT(dtss->image, PALETTE_MODIFIER_COLOR); peter1138@3775: } peter1138@3771: if (HASBIT(dtss->image, 14)) { peter1138@3771: CLRBIT(dtss->image, 14); peter1138@5919: SETBIT(dtss->image, PALETTE_MODIFIER_TRANSPARENT); peter1138@3771: } celestar@389: } celestar@389: } celestar@389: } celestar@389: break; peter1138@3505: belugas@6674: case 0x0A: // Copy sprite layout miham@439: FOR_EACH_OBJECT { peter1138@3768: StationSpec *statspec = _cur_grffile->stations[stid + i]; darkvater@398: byte srcid = grf_load_byte(&buf); peter1138@3768: const StationSpec *srcstatspec = _cur_grffile->stations[srcid]; darkvater@398: belugas@3676: statspec->tiles = srcstatspec->tiles; peter1138@3738: statspec->renderdata = srcstatspec->renderdata; peter1138@3740: statspec->copied_renderdata = true; celestar@389: } celestar@389: break; peter1138@3505: belugas@6674: case 0x0B: // Callback mask peter1138@3768: FOR_EACH_OBJECT statspec[i]->callbackmask = grf_load_byte(&buf); celestar@389: break; peter1138@3505: belugas@6674: case 0x0C: // Disallowed number of platforms peter1138@3768: FOR_EACH_OBJECT statspec[i]->disallowed_platforms = grf_load_byte(&buf); celestar@389: break; peter1138@3505: belugas@6674: case 0x0D: // Disallowed platform lengths peter1138@3768: FOR_EACH_OBJECT statspec[i]->disallowed_lengths = grf_load_byte(&buf); celestar@389: break; peter1138@3505: belugas@6674: case 0x0E: // Define custom layout miham@439: FOR_EACH_OBJECT { peter1138@3768: StationSpec *statspec = _cur_grffile->stations[stid + i]; tron@449: peter1138@5060: statspec->copied_layouts = false; peter1138@5060: celestar@389: while (buf < *bufp + len) { celestar@389: byte length = grf_load_byte(&buf); celestar@389: byte number = grf_load_byte(&buf); tron@449: StationLayout layout; peter1138@3570: uint l, p; celestar@389: tron@449: if (length == 0 || number == 0) break; tron@449: tron@449: //debug("l %d > %d ?", length, stat->lengths); belugas@3676: if (length > statspec->lengths) { KUDr@5860: statspec->platforms = ReallocT(statspec->platforms, length); belugas@3676: memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths); belugas@3676: KUDr@5860: statspec->layouts = ReallocT(statspec->layouts, length); belugas@3676: memset(statspec->layouts + statspec->lengths, 0, belugas@3676: (length - statspec->lengths) * sizeof(*statspec->layouts)); belugas@3676: belugas@3676: statspec->lengths = length; tron@449: } tron@449: l = length - 1; // index is zero-based tron@449: tron@449: //debug("p %d > %d ?", number, stat->platforms[l]); belugas@3676: if (number > statspec->platforms[l]) { KUDr@5860: statspec->layouts[l] = ReallocT(statspec->layouts[l], number); belugas@6674: /* We expect NULL being 0 here, but C99 guarantees that. */ belugas@3676: memset(statspec->layouts[l] + statspec->platforms[l], 0, belugas@3676: (number - statspec->platforms[l]) * sizeof(**statspec->layouts)); belugas@3676: belugas@3676: statspec->platforms[l] = number; tron@449: } tron@449: truelight@542: p = 0; KUDr@5860: layout = MallocT(length * number); tron@3033: for (l = 0; l < length; l++) { tron@3033: for (p = 0; p < number; p++) { tron@449: layout[l * number + p] = grf_load_byte(&buf); tron@3033: } tron@3033: } tron@449: tron@449: l--; tron@449: p--; belugas@3676: free(statspec->layouts[l][p]); belugas@3676: statspec->layouts[l][p] = layout; celestar@389: } celestar@389: } celestar@389: break; peter1138@3505: belugas@6674: case 0x0F: // Copy custom layout miham@439: FOR_EACH_OBJECT { peter1138@5060: StationSpec *statspec = _cur_grffile->stations[stid + i]; peter1138@5060: byte srcid = grf_load_byte(&buf); peter1138@5060: const StationSpec *srcstatspec = _cur_grffile->stations[srcid]; peter1138@5060: peter1138@5060: statspec->lengths = srcstatspec->lengths; peter1138@5060: statspec->platforms = srcstatspec->platforms; peter1138@5060: statspec->layouts = srcstatspec->layouts; peter1138@5060: statspec->copied_layouts = true; celestar@389: } celestar@389: break; peter1138@3505: belugas@6674: case 0x10: // Little/lots cargo threshold peter1138@3768: FOR_EACH_OBJECT statspec[i]->cargo_threshold = grf_load_word(&buf); miham@439: break; peter1138@3505: belugas@6674: case 0x11: // Pylon placement peter1138@3768: FOR_EACH_OBJECT statspec[i]->pylons = grf_load_byte(&buf); miham@439: break; peter1138@3505: belugas@6674: case 0x12: // Cargo types for random triggers peter1138@3768: FOR_EACH_OBJECT statspec[i]->cargo_triggers = grf_load_dword(&buf); peter1138@3505: break; peter1138@3505: belugas@6674: case 0x13: // General flags peter1138@3768: FOR_EACH_OBJECT statspec[i]->flags = grf_load_byte(&buf); peter1138@3505: break; peter1138@3505: belugas@6674: case 0x14: // Overhead wire placement peter1138@3768: FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf); peter1138@3505: break; peter1138@3505: belugas@6674: case 0x15: // Blocked tiles peter1138@3768: FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf); peter1138@3505: break; peter1138@3505: belugas@6674: case 0x16: // @todo Animation info peter1138@6154: FOR_EACH_OBJECT grf_load_word(&buf); peter1138@6154: ret = true; peter1138@6154: break; peter1138@6154: belugas@6674: case 0x17: // @todo Animation speed peter1138@6154: FOR_EACH_OBJECT grf_load_byte(&buf); peter1138@6154: ret = true; peter1138@6154: break; peter1138@6154: belugas@6674: case 0x18: // @todo Animation triggers peter1138@6154: FOR_EACH_OBJECT grf_load_word(&buf); peter1138@6154: ret = true; peter1138@6154: break; peter1138@6154: celestar@389: default: peter1138@3505: ret = true; celestar@389: break; celestar@389: } celestar@389: celestar@389: *bufp = buf; celestar@389: return ret; celestar@389: } celestar@389: peter1138@2478: static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int len) peter1138@2478: { peter1138@2478: byte *buf = *bufp; peter1138@2478: int i; peter1138@3504: bool ret = false; peter1138@2478: peter1138@2478: switch (prop) { belugas@6674: case 0x08: // Year of availability rubidium@4322: FOR_EACH_OBJECT _bridge[brid + i].avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf); peter1138@2478: break; peter1138@2478: belugas@6674: case 0x09: // Minimum length peter1138@3089: FOR_EACH_OBJECT _bridge[brid + i].min_length = grf_load_byte(&buf); peter1138@2478: break; peter1138@2478: belugas@6674: case 0x0A: // Maximum length peter1138@3089: FOR_EACH_OBJECT _bridge[brid + i].max_length = grf_load_byte(&buf); peter1138@2478: break; peter1138@2478: belugas@6674: case 0x0B: // Cost factor peter1138@3089: FOR_EACH_OBJECT _bridge[brid + i].price = grf_load_byte(&buf); peter1138@2478: break; peter1138@2478: belugas@6674: case 0x0C: // Maximum speed peter1138@3089: FOR_EACH_OBJECT _bridge[brid + i].speed = grf_load_word(&buf); peter1138@2478: break; peter1138@2478: belugas@6674: case 0x0D: // Bridge sprite tables peter1138@2478: FOR_EACH_OBJECT { peter1138@2478: Bridge *bridge = &_bridge[brid + i]; peter1138@2478: byte tableid = grf_load_byte(&buf); peter1138@2478: byte numtables = grf_load_byte(&buf); peter1138@2478: peter1138@2478: if (bridge->sprite_table == NULL) { Darkvater@3555: /* Allocate memory for sprite table pointers and zero out */ KUDr@5860: bridge->sprite_table = CallocT(7); peter1138@2478: } peter1138@2478: Darkvater@3555: for (; numtables-- != 0; tableid++) { Darkvater@3555: if (tableid >= 7) { // skip invalid data Darkvater@5568: grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid); peter1138@6607: for (byte sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf); Darkvater@3555: continue; peter1138@2478: } Darkvater@3555: Darkvater@3555: if (bridge->sprite_table[tableid] == NULL) { KUDr@5860: bridge->sprite_table[tableid] = MallocT(32); Darkvater@3555: } Darkvater@3555: peter1138@6607: for (byte sprite = 0; sprite < 32; sprite++) { peter1138@5919: SpriteID image = grf_load_word(&buf); peter1138@5919: SpriteID pal = grf_load_word(&buf); peter1138@5919: peter1138@5919: if (HASBIT(pal, 15)) { peter1138@5919: SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); peter1138@5919: } peter1138@5919: peter1138@5919: /* Clear old color modifer bit */ peter1138@5919: CLRBIT(image, 15); peter1138@5919: peter1138@5919: bridge->sprite_table[tableid][sprite].sprite = image; peter1138@5919: bridge->sprite_table[tableid][sprite].pal = pal; peter1138@5919: } peter1138@2478: } peter1138@2478: } peter1138@2478: break; peter1138@2478: belugas@6674: case 0x0E: // Flags; bit 0 - disable far pillars peter1138@3089: FOR_EACH_OBJECT _bridge[brid + i].flags = grf_load_byte(&buf); peter1138@2478: break; peter1138@2478: belugas@6674: case 0x0F: // Long format year of availability (year since year 0) peter1138@5114: FOR_EACH_OBJECT _bridge[brid + i].avail_year = clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR); peter1138@5114: break; peter1138@5114: peter1138@2478: default: peter1138@3504: ret = true; peter1138@2478: } peter1138@2478: peter1138@2478: *bufp = buf; peter1138@2478: return ret; peter1138@2478: } celestar@389: maedhros@6658: static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, int len) maedhros@6658: { maedhros@6658: HouseSpec **housespec; maedhros@6658: byte *buf = *bufp; maedhros@6658: int i; maedhros@6658: bool ret = false; maedhros@6658: maedhros@6658: if (hid + numinfo >= HOUSE_MAX) { maedhros@6658: grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, HOUSE_MAX-1); maedhros@6658: return false; maedhros@6658: } maedhros@6658: maedhros@6658: /* Allocate house specs if they haven't been allocated already. */ maedhros@6658: if (_cur_grffile->housespec == NULL) { maedhros@6658: _cur_grffile->housespec = CallocT(HOUSE_MAX); maedhros@6658: maedhros@6658: /* Reset any overrides that have been set. */ richk@6719: _house_mngr.ResetOverride(); maedhros@6658: } maedhros@6658: maedhros@6658: housespec = &_cur_grffile->housespec[hid]; maedhros@6658: maedhros@6658: if (prop != 0x08) { maedhros@6658: /* Check that all the houses being modified have been defined. */ maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: if (housespec[i] == NULL) { maedhros@6658: grfmsg(2, "TownHouseChangeInfo: Attempt to modify undefined house %u. Ignoring.", hid + i); maedhros@6658: return false; maedhros@6658: } maedhros@6658: } maedhros@6658: } maedhros@6658: maedhros@6658: switch (prop) { maedhros@6658: case 0x08: // Substitute building type, and definition of a new house maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: byte subs_id = grf_load_byte(&buf); maedhros@6658: maedhros@6658: if (subs_id == 0xFF) { maedhros@6658: /* Instead of defining a new house, a substitute house id maedhros@6658: * of 0xFF disables the old house with the current id. */ maedhros@6658: _house_specs[hid + i].enabled = false; maedhros@6658: continue; maedhros@6658: } else if (subs_id >= NEW_HOUSE_OFFSET) { maedhros@6658: /* The substitute id must be one of the original houses. */ maedhros@6658: grfmsg(2, "TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i); maedhros@6658: return false; maedhros@6658: } maedhros@6658: maedhros@6658: /* Allocate space for this house. */ maedhros@6658: if (housespec[i] == NULL) housespec[i] = CallocT(1); maedhros@6658: maedhros@6658: memcpy(housespec[i], &_house_specs[subs_id], sizeof(_house_specs[subs_id])); maedhros@6658: maedhros@6658: housespec[i]->enabled = true; maedhros@6658: housespec[i]->local_id = hid + i; maedhros@6658: housespec[i]->substitute_id = subs_id; maedhros@6668: housespec[i]->grffile = _cur_grffile; maedhros@6658: housespec[i]->random_colour[0] = 0x04; // those 4 random colours are the base colour maedhros@6658: housespec[i]->random_colour[1] = 0x08; // for all new houses maedhros@6658: housespec[i]->random_colour[2] = 0x0C; // they stand for red, blue, orange and green maedhros@6658: housespec[i]->random_colour[3] = 0x06; maedhros@6658: maedhros@6658: /* New houses do not (currently) expect to have a default start maedhros@6658: * date before 1930, as this breaks the build date stuff. See maedhros@6658: * FinaliseHouseArray() for more details. */ maedhros@6658: if (housespec[i]->min_date < 1930) housespec[i]->min_date = 1930; maedhros@6658: } richk@6719: SETBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x09: // Building flags maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: byte state = grf_load_byte(&buf); maedhros@6658: housespec[i]->building_flags = (BuildingFlags)state; maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x0A: // Availability years maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: uint16 years = grf_load_word(&buf); maedhros@6658: housespec[i]->min_date = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8); maedhros@6658: housespec[i]->max_date = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8); maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x0B: // Population maedhros@6658: FOR_EACH_OBJECT housespec[i]->population = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x0C: // Mail generation multiplier maedhros@6658: FOR_EACH_OBJECT housespec[i]->mail_generation = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x0D: // Passenger acceptance maedhros@6658: case 0x0E: // Mail acceptance belugas@6667: FOR_EACH_OBJECT housespec[i]->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf); maedhros@6658: break; belugas@6667: case 0x0F: // Goods/candy, food/fizzy drinks acceptance maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: int8 goods = grf_load_byte(&buf); belugas@6667: belugas@6667: /* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance. belugas@6667: * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */ belugas@6683: housespec[i]->accepts_cargo[2] = (goods >= 0) ? ((_opt.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) : belugas@6683: ((_opt.landscape == LT_TOYLAND) ? CT_FIZZY_DRINKS : CT_FOOD); belugas@6667: belugas@6667: housespec[i]->cargo_acceptance[2] = abs(goods); // but we do need positive value here maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x10: // Local authority rating decrease on removal maedhros@6658: FOR_EACH_OBJECT housespec[i]->remove_rating_decrease = grf_load_word(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x11: // Removal cost multiplier maedhros@6658: FOR_EACH_OBJECT housespec[i]->removal_cost = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x12: // Building name ID peter1138@6685: FOR_EACH_OBJECT housespec[i]->building_name = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf)); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x13: // Building availability mask maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: uint16 avail = grf_load_word(&buf); maedhros@6658: housespec[i]->building_availability = (HouseZones)avail; maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x14: // House callback flags maedhros@6658: FOR_EACH_OBJECT housespec[i]->callback_mask = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x15: // House override byte maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: byte override = grf_load_byte(&buf); maedhros@6658: maedhros@6658: /* The house being overridden must be an original house. */ maedhros@6658: if (override >= NEW_HOUSE_OFFSET) { maedhros@6658: grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid); maedhros@6658: return false; maedhros@6658: } maedhros@6658: richk@6719: _house_mngr.Add(hid, override); maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x16: // Periodic refresh multiplier maedhros@6658: FOR_EACH_OBJECT housespec[i]->processing_time = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x17: // Four random colours to use maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: uint j; richk@6719: for (j = 0; j < 4; j++) housespec[i]->random_colour[j] = grf_load_byte(&buf); maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x18: // Relative probability of appearing maedhros@6658: FOR_EACH_OBJECT housespec[i]->probability = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x19: // Extra flags maedhros@6658: FOR_EACH_OBJECT { maedhros@6658: byte flags = grf_load_byte(&buf); maedhros@6658: housespec[i]->extra_flags = (HouseExtraFlags)flags; maedhros@6658: } maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x1A: // Animation frames maedhros@6658: FOR_EACH_OBJECT housespec[i]->animation_frames = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x1B: // Animation speed maedhros@6658: FOR_EACH_OBJECT housespec[i]->animation_speed = clamp(grf_load_byte(&buf), 2, 16); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x1C: // Class of the building type maedhros@6658: FOR_EACH_OBJECT housespec[i]->class_id = AllocateHouseClassID(grf_load_byte(&buf), _cur_grffile->grfid); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x1D: // Callback flags 2 maedhros@6658: FOR_EACH_OBJECT housespec[i]->callback_mask |= (grf_load_byte(&buf) << 8); maedhros@6658: break; maedhros@6658: maedhros@6658: case 0x1E: // Accepted cargo types richk@6719: FOR_EACH_OBJECT { richk@6719: uint32 cargotypes = grf_load_dword(&buf); richk@6719: richk@6719: /* Check if the cargo types should not be changed */ richk@6719: if (cargotypes == 0xFFFFFFFF) break; richk@6719: richk@6719: for (uint j = 0; j < 3; j++) { richk@6719: /* Get the cargo number from the 'list' */ richk@6719: uint8 cargo_part = GB(cargotypes, 8 * j, 8); richk@6719: CargoID cargo = GetCargoTranslation(cargo_part, _cur_grffile); richk@6719: richk@6719: if (cargo == CT_INVALID) { richk@6719: /* Disable acceptance of invalid cargo type */ richk@6719: housespec[i]->cargo_acceptance[j] = 0; richk@6719: } else { richk@6719: housespec[i]->accepts_cargo[j] = cargo; richk@6719: } richk@6719: } richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0x1F: // Minimum life span richk@6719: FOR_EACH_OBJECT housespec[i]->minimum_life = grf_load_byte(&buf); maedhros@6658: break; maedhros@6658: maedhros@6658: default: maedhros@6658: ret = true; maedhros@6658: break; maedhros@6658: } maedhros@6658: maedhros@6658: *bufp = buf; maedhros@6658: return ret; maedhros@6658: } maedhros@6658: peter1138@2506: static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, int len) peter1138@2506: { peter1138@2506: byte *buf = *bufp; peter1138@2506: int i; peter1138@2506: bool ret = false; peter1138@2506: peter1138@2506: switch (prop) { peter1138@3504: case 0x08: /* Cost base factor */ peter1138@2506: FOR_EACH_OBJECT { peter1138@2506: byte factor = grf_load_byte(&buf); peter1138@2508: uint price = gvid + i; peter1138@2506: peter1138@2508: if (price < NUM_PRICES) { peter1138@2508: SetPriceBaseMultiplier(price, factor); peter1138@2508: } else { Darkvater@5568: grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price); peter1138@2508: } peter1138@2506: } peter1138@3504: break; peter1138@3504: peter1138@6469: case 0x09: /* Cargo translation table */ peter1138@6469: /* This is loaded during the initialisation stage, so just skip it here. */ peter1138@6469: /* Each entry is 4 bytes. */ peter1138@6469: buf += numinfo * 4; peter1138@6469: break; peter1138@6469: belugas@4377: case 0x0A: // Currency display names belugas@4377: FOR_EACH_OBJECT { belugas@4625: uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); belugas@4625: StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf)); belugas@4377: belugas@4504: if ((newone != STR_UNDEFINED) && (curidx < NUM_CURRENCY)) { belugas@4504: _currency_specs[curidx].name = newone; belugas@4377: } belugas@4377: } belugas@4377: break; belugas@4377: belugas@4377: case 0x0B: // Currency multipliers belugas@4377: FOR_EACH_OBJECT { belugas@4625: uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); belugas@4377: uint32 rate = grf_load_dword(&buf); belugas@4377: belugas@4377: if (curidx < NUM_CURRENCY) { belugas@4602: /* TTDPatch uses a multiple of 1000 for its conversion calculations, belugas@4602: * which OTTD does not. For this reason, divide grf value by 1000, belugas@4602: * to be compatible */ belugas@4602: _currency_specs[curidx].rate = rate / 1000; belugas@4377: } else { Darkvater@5568: grfmsg(1, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx); belugas@4377: } belugas@4377: } belugas@4377: break; belugas@4377: belugas@4377: case 0x0C: // Currency options belugas@4377: FOR_EACH_OBJECT { belugas@4625: uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); belugas@4377: uint16 options = grf_load_word(&buf); belugas@4377: belugas@4377: if (curidx < NUM_CURRENCY) { belugas@4377: _currency_specs[curidx].separator = GB(options, 0, 8); belugas@4602: /* By specifying only one bit, we prevent errors, belugas@4602: * since newgrf specs said that only 0 and 1 can be set for symbol_pos */ belugas@4602: _currency_specs[curidx].symbol_pos = GB(options, 8, 1); belugas@4377: } else { Darkvater@5568: grfmsg(1, "GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx); belugas@4377: } belugas@4377: } belugas@4377: break; belugas@4377: belugas@4602: case 0x0D: // Currency prefix symbol belugas@4377: FOR_EACH_OBJECT { belugas@4625: uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); belugas@4377: uint32 tempfix = grf_load_dword(&buf); belugas@4377: belugas@4377: if (curidx < NUM_CURRENCY) { belugas@4377: memcpy(_currency_specs[curidx].prefix,&tempfix,4); belugas@4377: _currency_specs[curidx].prefix[4] = 0; belugas@4377: } else { Darkvater@5568: grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx); belugas@4377: } belugas@4377: } belugas@4377: break; belugas@4377: belugas@4602: case 0x0E: // Currency suffix symbol belugas@4377: FOR_EACH_OBJECT { belugas@4625: uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); belugas@4377: uint32 tempfix = grf_load_dword(&buf); belugas@4377: belugas@4377: if (curidx < NUM_CURRENCY) { richk@6719: memcpy(&_currency_specs[curidx].suffix, &tempfix, 4); belugas@4377: _currency_specs[curidx].suffix[4] = 0; belugas@4377: } else { Darkvater@5568: grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx); belugas@4377: } belugas@4377: } belugas@4377: break; belugas@4377: belugas@4504: case 0x0F: // Euro introduction dates belugas@4377: FOR_EACH_OBJECT { belugas@4625: uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); belugas@4377: Year year_euro = grf_load_word(&buf); belugas@4377: belugas@4377: if (curidx < NUM_CURRENCY) { belugas@4377: _currency_specs[curidx].to_euro = year_euro; belugas@4377: } else { Darkvater@5568: grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx); belugas@4377: } belugas@4377: } belugas@4377: break; belugas@4377: belugas@4377: case 0x10: // 12 * 32 * B Snow line height table maedhros@6669: if (numinfo > 1 || IsSnowLineSet()) { maedhros@6669: grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo); maedhros@6669: } else if (len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) { maedhros@6669: grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (%d)", len); maedhros@6669: } else { maedhros@6669: byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]; maedhros@6669: maedhros@6669: for (uint i = 0; i < SNOW_LINE_MONTHS; i++) { maedhros@6669: for (uint j = 0; j < SNOW_LINE_DAYS; j++) { maedhros@6669: table[i][j] = grf_load_byte(&buf); maedhros@6669: } maedhros@6669: } maedhros@6669: SetSnowLine(table); maedhros@6669: } maedhros@6669: break; maedhros@6669: peter1138@2506: default: peter1138@2506: ret = true; peter1138@2506: } peter1138@3504: peter1138@2506: *bufp = buf; peter1138@2506: return ret; peter1138@2506: } peter1138@2506: peter1138@6685: static bool CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int len) peter1138@6685: { peter1138@6685: if (cid + numinfo > NUM_CARGO) { peter1138@6685: grfmsg(2, "CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, NUM_CARGO - 1); peter1138@6685: return false; peter1138@6685: } peter1138@6685: peter1138@6685: CargoSpec *cs = &_cargo[cid]; peter1138@6685: byte *buf = *bufp; peter1138@6685: int i; peter1138@6685: bool ret = false; peter1138@6685: peter1138@6685: switch (prop) { peter1138@6685: case 0x08: /* Bit number of cargo */ peter1138@6685: FOR_EACH_OBJECT { peter1138@6685: cs[i].bitnum = grf_load_byte(&buf); peter1138@6685: cs[i].grfid = _cur_grffile->grfid; peter1138@6685: if (cs->IsValid()) { peter1138@6685: SETBIT(_cargo_mask, cid + i); peter1138@6685: } else { peter1138@6685: CLRBIT(_cargo_mask, cid + i); peter1138@6685: } peter1138@6685: } peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x09: /* String ID for cargo type name */ peter1138@6685: FOR_EACH_OBJECT cs[i].name = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x0A: /* String for cargo name, plural */ peter1138@6685: FOR_EACH_OBJECT cs[i].name_plural = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x0B: peter1138@6685: /* String for units of cargo. This is different in OpenTTD to TTDPatch peter1138@6685: * (e.g. 10 tonnes of coal) */ peter1138@6685: FOR_EACH_OBJECT cs[i].units_volume = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */ peter1138@6685: FOR_EACH_OBJECT cs[i].quantifier = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x0D: /* String for two letter cargo abbreviation */ peter1138@6685: FOR_EACH_OBJECT cs[i].abbrev = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x0E: /* Sprite ID for cargo icon */ peter1138@6685: FOR_EACH_OBJECT cs[i].sprite = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x0F: /* Weight of one unit of cargo */ peter1138@6685: FOR_EACH_OBJECT cs[i].weight = grf_load_byte(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x10: /* Used for payment calculation */ peter1138@6685: FOR_EACH_OBJECT cs[i].transit_days[0] = grf_load_byte(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x11: /* Used for payment calculation */ peter1138@6685: FOR_EACH_OBJECT cs[i].transit_days[1] = grf_load_byte(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x12: /* Base cargo price */ peter1138@6685: FOR_EACH_OBJECT cs[i].initial_payment = grf_load_dword(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x13: /* Colour for station rating bars */ peter1138@6701: FOR_EACH_OBJECT cs[i].rating_colour = MapDOSColour(grf_load_byte(&buf)); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x14: /* Colour for cargo graph */ peter1138@6701: FOR_EACH_OBJECT cs[i].legend_colour = MapDOSColour(grf_load_byte(&buf)); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x15: /* Freight status */ peter1138@6685: FOR_EACH_OBJECT cs[i].is_freight = grf_load_byte(&buf) != 0; peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x16: /* Cargo classes */ peter1138@6685: FOR_EACH_OBJECT cs[i].classes = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x17: /* Cargo label */ peter1138@6685: FOR_EACH_OBJECT { peter1138@6685: cs[i].label = grf_load_dword(&buf); peter1138@6685: cs[i].label = BSWAP32(cs[i].label); peter1138@6685: } peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x18: /* Town growth substitute type */ peter1138@6685: FOR_EACH_OBJECT { peter1138@6685: uint8 substitute_type = grf_load_byte(&buf); peter1138@6685: switch (substitute_type) { peter1138@6685: case 0x00: cs[i].town_effect = TE_PASSENGERS; break; peter1138@6685: case 0x02: cs[i].town_effect = TE_MAIL; break; peter1138@6685: case 0x05: cs[i].town_effect = TE_GOODS; break; peter1138@6685: case 0x09: cs[i].town_effect = TE_WATER; break; peter1138@6685: case 0x0B: cs[i].town_effect = TE_FOOD; break; peter1138@6685: default: peter1138@6685: grfmsg(1, "CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type); peter1138@6685: case 0xFF: cs[i].town_effect = TE_NONE; break; peter1138@6685: } peter1138@6685: } peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x19: /* Town growth coefficient */ peter1138@6685: FOR_EACH_OBJECT cs[i].multipliertowngrowth = grf_load_word(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: case 0x1A: /* Bitmask of callbacks to use */ peter1138@6685: FOR_EACH_OBJECT cs[i].callback_mask = grf_load_byte(&buf); peter1138@6685: break; peter1138@6685: peter1138@6685: default: peter1138@6685: ret = true; peter1138@6685: } peter1138@6685: peter1138@6685: *bufp = buf; peter1138@6685: return ret; peter1138@6685: } peter1138@6685: peter1138@6685: peter1138@4656: static bool SoundEffectChangeInfo(uint sid, int numinfo, int prop, byte **bufp, int len) peter1138@4656: { peter1138@4656: byte *buf = *bufp; peter1138@4656: int i; peter1138@4656: bool ret = false; peter1138@4656: peter1138@4656: if (_cur_grffile->sound_offset == 0) { Darkvater@5568: grfmsg(1, "SoundEffectChangeInfo: No effects defined, skipping"); peter1138@4656: return false; peter1138@4656: } peter1138@4656: peter1138@4656: switch (prop) { belugas@6674: case 0x08: // Relative volume peter1138@4656: FOR_EACH_OBJECT { peter1138@4656: uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds(); peter1138@4656: peter1138@4656: if (sound >= GetNumSounds()) { Darkvater@5568: grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds()); peter1138@4656: } else { peter1138@4656: GetSound(sound)->volume = grf_load_byte(&buf); peter1138@4656: } peter1138@4656: } peter1138@4656: break; peter1138@4656: belugas@6674: case 0x09: // Priority peter1138@4656: FOR_EACH_OBJECT { peter1138@4656: uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds(); peter1138@4656: peter1138@4656: if (sound >= GetNumSounds()) { Darkvater@5568: grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds()); peter1138@4656: } else { peter1138@4656: GetSound(sound)->priority = grf_load_byte(&buf); peter1138@4656: } peter1138@4656: } peter1138@4656: break; peter1138@4656: belugas@6674: case 0x0A: // Override old sound peter1138@4656: FOR_EACH_OBJECT { peter1138@4656: uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds(); peter1138@4656: uint orig_sound = grf_load_byte(&buf); peter1138@4656: peter1138@4656: if (sound >= GetNumSounds() || orig_sound >= GetNumSounds()) { Darkvater@5568: grfmsg(1, "SoundEffectChangeInfo: Sound %d or %d not defined (max %d)", sound, orig_sound, GetNumSounds()); peter1138@4656: } else { peter1138@4656: FileEntry *newfe = GetSound(sound); peter1138@4656: FileEntry *oldfe = GetSound(orig_sound); peter1138@4656: peter1138@4656: /* Literally copy the data of the new sound over the original */ tron@5024: *oldfe = *newfe; peter1138@4656: } peter1138@4656: } peter1138@4656: break; peter1138@4656: peter1138@4656: default: peter1138@4656: ret = true; peter1138@4656: } peter1138@4656: peter1138@4656: *bufp = buf; peter1138@4656: return ret; peter1138@4656: } peter1138@4656: richk@6719: static bool FSMPortChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len) richk@6719: { richk@6719: StationSpec **statspec; richk@6719: byte *buf = *bufp; richk@6719: int i; richk@6719: bool ret = false; richk@6719: richk@6719: if (stid + numinfo > MAX_FSM_PORTS) { richk@6719: grfmsg(1, "StationChangeInfo: Station %u is invalid, max %u, ignoring", stid + numinfo, MAX_FSM_PORTS); richk@6719: return false; richk@6719: } richk@6719: richk@6719: /* Allocate station specs if necessary */ richk@6719: if (_cur_grffile->stations == NULL) _cur_grffile->stations = CallocT(MAX_FSM_PORTS); richk@6719: richk@6719: statspec = &_cur_grffile->stations[stid]; richk@6719: richk@6719: if (prop != 0x08) { richk@6719: /* Check that all stations we are modifying are defined. */ richk@6719: FOR_EACH_OBJECT { richk@6719: if (statspec[i] == NULL) { richk@6719: grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i); richk@6719: return false; richk@6719: } richk@6719: } richk@6719: } richk@6719: richk@6719: switch (prop) { richk@6719: case 0x08: // Class ID richk@6719: FOR_EACH_OBJECT { richk@6719: /* Property 0x08 is special; it is where the station is allocated */ richk@6719: if (statspec[i] == NULL) statspec[i] = CallocT(1); richk@6719: richk@6719: /* Swap classid because we read it in BE meaning WAYP or DFLT */ richk@6719: uint32 classid = grf_load_dword(&buf); richk@6719: statspec[i]->sclass = AllocateStationClass(BSWAP32(classid)); richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0x09: // Define sprite layout richk@6719: FOR_EACH_OBJECT { richk@6719: StationSpec *statspec = _cur_grffile->stations[stid + i]; richk@6719: richk@6719: statspec->tiles = grf_load_extended(&buf); richk@6719: statspec->renderdata = CallocT(statspec->tiles); richk@6719: statspec->copied_renderdata = false; richk@6719: richk@6719: for (uint t = 0; t < statspec->tiles; t++) { richk@6719: DrawTileSprites *dts = &statspec->renderdata[t]; richk@6719: uint seq_count = 0; richk@6719: richk@6719: dts->seq = NULL; richk@6719: dts->ground_sprite = grf_load_word(&buf); richk@6719: dts->ground_pal = grf_load_word(&buf); richk@6719: if (dts->ground_sprite == 0) continue; richk@6719: if (HASBIT(dts->ground_pal, 15)) { richk@6719: CLRBIT(dts->ground_pal, 15); richk@6719: SETBIT(dts->ground_sprite, SPRITE_MODIFIER_USE_OFFSET); richk@6719: } richk@6719: richk@6719: while (buf < *bufp + len) { richk@6719: DrawTileSeqStruct *dtss; richk@6719: richk@6719: /* no relative bounding box support */ richk@6719: dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count); richk@6719: dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1]; richk@6719: richk@6719: dtss->delta_x = grf_load_byte(&buf); richk@6719: if ((byte) dtss->delta_x == 0x80) break; richk@6719: dtss->delta_y = grf_load_byte(&buf); richk@6719: dtss->delta_z = grf_load_byte(&buf); richk@6719: dtss->size_x = grf_load_byte(&buf); richk@6719: dtss->size_y = grf_load_byte(&buf); richk@6719: dtss->size_z = grf_load_byte(&buf); richk@6719: dtss->image = grf_load_word(&buf); richk@6719: dtss->pal = grf_load_word(&buf); richk@6719: richk@6719: /* Remap flags as ours collide */ richk@6719: if (HASBIT(dtss->pal, 15)) { richk@6719: CLRBIT(dtss->pal, 15); richk@6719: SETBIT(dtss->image, SPRITE_MODIFIER_USE_OFFSET); richk@6719: } richk@6719: richk@6719: if (HASBIT(dtss->image, 15)) { richk@6719: CLRBIT(dtss->image, 15); richk@6719: SETBIT(dtss->image, PALETTE_MODIFIER_COLOR); richk@6719: } richk@6719: if (HASBIT(dtss->image, 14)) { richk@6719: CLRBIT(dtss->image, 14); richk@6719: SETBIT(dtss->image, PALETTE_MODIFIER_TRANSPARENT); richk@6719: } richk@6719: } richk@6719: } richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0x0A: // Copy sprite layout richk@6719: FOR_EACH_OBJECT { richk@6719: StationSpec *statspec = _cur_grffile->stations[stid + i]; richk@6719: byte srcid = grf_load_byte(&buf); richk@6719: const StationSpec *srcstatspec = _cur_grffile->stations[srcid]; richk@6719: richk@6719: statspec->tiles = srcstatspec->tiles; richk@6719: statspec->renderdata = srcstatspec->renderdata; richk@6719: statspec->copied_renderdata = true; richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0x0B: // Callback mask richk@6719: FOR_EACH_OBJECT statspec[i]->callbackmask = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x0C: // Disallowed number of platforms richk@6719: FOR_EACH_OBJECT statspec[i]->disallowed_platforms = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x0D: // Disallowed platform lengths richk@6719: FOR_EACH_OBJECT statspec[i]->disallowed_lengths = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x0E: // Define custom layout richk@6719: FOR_EACH_OBJECT { richk@6719: StationSpec *statspec = _cur_grffile->stations[stid + i]; richk@6719: richk@6719: statspec->copied_layouts = false; richk@6719: richk@6719: while (buf < *bufp + len) { richk@6719: byte length = grf_load_byte(&buf); richk@6719: byte number = grf_load_byte(&buf); richk@6719: StationLayout layout; richk@6719: uint l, p; richk@6719: richk@6719: if (length == 0 || number == 0) break; richk@6719: richk@6719: //debug("l %d > %d ?", length, stat->lengths); richk@6719: if (length > statspec->lengths) { richk@6719: statspec->platforms = ReallocT(statspec->platforms, length); richk@6719: memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths); richk@6719: richk@6719: statspec->layouts = ReallocT(statspec->layouts, length); richk@6719: memset(statspec->layouts + statspec->lengths, 0, richk@6719: (length - statspec->lengths) * sizeof(*statspec->layouts)); richk@6719: richk@6719: statspec->lengths = length; richk@6719: } richk@6719: l = length - 1; // index is zero-based richk@6719: richk@6719: //debug("p %d > %d ?", number, stat->platforms[l]); richk@6719: if (number > statspec->platforms[l]) { richk@6719: statspec->layouts[l] = ReallocT(statspec->layouts[l], number); richk@6719: /* We expect NULL being 0 here, but C99 guarantees that. */ richk@6719: memset(statspec->layouts[l] + statspec->platforms[l], 0, richk@6719: (number - statspec->platforms[l]) * sizeof(**statspec->layouts)); richk@6719: richk@6719: statspec->platforms[l] = number; richk@6719: } richk@6719: richk@6719: p = 0; richk@6719: layout = MallocT(length * number); richk@6719: for (l = 0; l < length; l++) { richk@6719: for (p = 0; p < number; p++) { richk@6719: layout[l * number + p] = grf_load_byte(&buf); richk@6719: } richk@6719: } richk@6719: richk@6719: l--; richk@6719: p--; richk@6719: free(statspec->layouts[l][p]); richk@6719: statspec->layouts[l][p] = layout; richk@6719: } richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0x0F: // Copy custom layout richk@6719: FOR_EACH_OBJECT { richk@6719: StationSpec *statspec = _cur_grffile->stations[stid + i]; richk@6719: byte srcid = grf_load_byte(&buf); richk@6719: const StationSpec *srcstatspec = _cur_grffile->stations[srcid]; richk@6719: richk@6719: statspec->lengths = srcstatspec->lengths; richk@6719: statspec->platforms = srcstatspec->platforms; richk@6719: statspec->layouts = srcstatspec->layouts; richk@6719: statspec->copied_layouts = true; richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0x10: // Little/lots cargo threshold richk@6719: FOR_EACH_OBJECT statspec[i]->cargo_threshold = grf_load_word(&buf); richk@6719: break; richk@6719: richk@6719: case 0x11: // Pylon placement richk@6719: FOR_EACH_OBJECT statspec[i]->pylons = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x12: // Cargo types for random triggers richk@6719: FOR_EACH_OBJECT statspec[i]->cargo_triggers = grf_load_dword(&buf); richk@6719: break; richk@6719: richk@6719: case 0x13: // General flags richk@6719: FOR_EACH_OBJECT statspec[i]->flags = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x14: // Overhead wire placement richk@6719: FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x15: // Blocked tiles richk@6719: FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf); richk@6719: break; richk@6719: richk@6719: case 0x16: // @todo Animation info richk@6719: FOR_EACH_OBJECT grf_load_word(&buf); richk@6719: ret = true; richk@6719: break; richk@6719: richk@6719: case 0x17: // @todo Animation speed richk@6719: FOR_EACH_OBJECT grf_load_byte(&buf); richk@6719: ret = true; richk@6719: break; richk@6719: richk@6719: case 0x18: // @todo Animation triggers richk@6719: FOR_EACH_OBJECT grf_load_word(&buf); richk@6719: ret = true; richk@6719: break; richk@6719: richk@6719: default: richk@6719: ret = true; richk@6719: break; richk@6719: } richk@6719: richk@6719: *bufp = buf; richk@6719: return ret; richk@6719: } richk@6719: celestar@356: /* Action 0x00 */ belugas@3879: static void FeatureChangeInfo(byte *buf, int len) truelight@0: { truelight@0: byte *bufend = buf + len; belugas@6614: uint i; truelight@0: truelight@0: /* <00> ()... truelight@0: * truelight@0: * B feature 0, 1, 2 or 3 for trains, road vehicles, ships or planes truelight@0: * 4 for defining new train station sets truelight@0: * B num-props how many properties to change per vehicle/station truelight@0: * B num-info how many vehicles/stations to change truelight@0: * B id ID of first vehicle/station to change, if num-info is truelight@0: * greater than one, this one and the following truelight@0: * vehicles/stations will be changed truelight@0: * B property what property to change, depends on the feature truelight@0: * V new-info new bytes of info (variable size; depends on properties) */ darkvater@391: /* TODO: Bridges, town houses. */ truelight@0: peter1138@2438: static const VCI_Handler handler[] = { belugas@3825: /* GSF_TRAIN */ RailVehicleChangeInfo, belugas@3825: /* GSF_ROAD */ RoadVehicleChangeInfo, belugas@3825: /* GSF_SHIP */ ShipVehicleChangeInfo, belugas@3825: /* GSF_AIRCRAFT */ AircraftVehicleChangeInfo, belugas@3825: /* GSF_STATION */ StationChangeInfo, belugas@3825: /* GSF_CANAL */ NULL, belugas@3825: /* GSF_BRIDGE */ BridgeChangeInfo, maedhros@6658: /* GSF_TOWNHOUSE */ TownHouseChangeInfo, belugas@3825: /* GSF_GLOBALVAR */ GlobalVarChangeInfo, belugas@3825: /* GSF_INDUSTRYTILES */NULL, belugas@3825: /* GSF_INDUSTRIES */ NULL, peter1138@6685: /* GSF_CARGOS */ NULL, /* Cargo is handled during reservation */ peter1138@4656: /* GSF_SOUNDFX */ SoundEffectChangeInfo, richk@6719: /* GSF_FSMPORTS */ FSMPortChangeInfo, truelight@0: }; darkvater@360: truelight@542: EngineInfo *ei = NULL; truelight@0: peter1138@5841: if (!check_length(len, 6, "FeatureChangeInfo")) return; peter1138@3714: buf++; peter1138@6607: uint8 feature = grf_load_byte(&buf); peter1138@6607: uint8 numprops = grf_load_byte(&buf); belugas@6614: uint numinfo = grf_load_byte(&buf); belugas@6614: uint engine = grf_load_byte(&buf); truelight@193: Darkvater@5568: grfmsg(6, "FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d", celestar@378: feature, numprops, engine, numinfo); celestar@378: peter1138@2440: if (feature >= lengthof(handler) || handler[feature] == NULL) { Darkvater@5568: grfmsg(1, "FeatureChangeInfo: Unsupported feature %d, skipping", feature); darkvater@391: return; darkvater@391: } darkvater@391: peter1138@2439: if (feature <= GSF_AIRCRAFT) { peter1138@2439: if (engine + numinfo > _vehcounts[feature]) { Darkvater@5568: grfmsg(0, "FeatureChangeInfo: Last engine ID %d out of bounds (max %d), skipping", engine + numinfo, _vehcounts[feature]); peter1138@2439: return; peter1138@2439: } celestar@389: ei = &_engine_info[engine + _vehshifts[feature]]; peter1138@2439: } celestar@357: celestar@357: while (numprops-- && buf < bufend) { celestar@357: uint8 prop = grf_load_byte(&buf); tron@2421: bool ignoring = false; celestar@357: tron@2421: switch (feature) { tron@2421: case GSF_TRAIN: tron@2421: case GSF_ROAD: tron@2421: case GSF_SHIP: tron@2421: case GSF_AIRCRAFT: tron@2421: /* Common properties for vehicles */ tron@2421: switch (prop) { belugas@6674: case 0x00: // Introduction date rubidium@4322: FOR_EACH_OBJECT ei[i].base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR; peter1138@3089: break; peter1138@3089: belugas@6674: case 0x02: // Decay speed peter1138@3089: FOR_EACH_OBJECT SB(ei[i].unk2, 0, 7, grf_load_byte(&buf) & 0x7F); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x03: // Vehicle life peter1138@3089: FOR_EACH_OBJECT ei[i].lifelength = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x04: // Model life peter1138@3089: FOR_EACH_OBJECT ei[i].base_life = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x06: // Climates available peter1138@3089: FOR_EACH_OBJECT ei[i].climates = grf_load_byte(&buf); peter1138@3089: break; peter1138@3089: belugas@6674: case 0x07: // Loading speed tron@2421: /* Hyronymus explained me what does tron@2421: * this mean and insists on having a tron@2421: * credit ;-). --pasky */ peter1138@5211: FOR_EACH_OBJECT ei[i].load_amount = grf_load_byte(&buf); tron@2421: break; tron@2421: tron@2421: default: peter1138@6607: if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) { tron@2421: ignoring = true; peter1138@6607: } tron@2421: break; tron@2421: } tron@2421: break; tron@2421: tron@2421: default: peter1138@6607: if (handler[feature](engine, numinfo, prop, &buf, bufend - buf)) { tron@2421: ignoring = true; peter1138@6607: } tron@2421: break; celestar@357: } tron@2421: Darkvater@5568: if (ignoring) grfmsg(2, "FeatureChangeInfo: Ignoring property 0x%02X (not implemented)", prop); truelight@0: } truelight@0: } truelight@0: peter1138@5776: /* Action 0x00 (GLS_SAFETYSCAN) */ peter1138@5776: static void SafeChangeInfo(byte *buf, int len) peter1138@5776: { peter1138@5841: if (!check_length(len, 6, "SafeChangeInfo")) return; peter1138@5776: buf++; peter1138@6607: uint8 feature = grf_load_byte(&buf); peter1138@6607: uint8 numprops = grf_load_byte(&buf); peter1138@6607: grf_load_byte(&buf); peter1138@6607: grf_load_byte(&buf); peter1138@5776: peter1138@5776: if (feature == GSF_BRIDGE && numprops == 1) { peter1138@5776: uint8 prop = grf_load_byte(&buf); peter1138@5776: /* Bridge property 0x0D is redefinition of sprite layout tables, which peter1138@5776: * is considered safe. */ peter1138@5776: if (prop == 0x0D) return; peter1138@5776: } peter1138@5776: peter1138@5776: SETBIT(_cur_grfconfig->flags, GCF_UNSAFE); peter1138@5776: peter1138@5776: /* Skip remainder of GRF */ peter1138@5776: _skip_sprites = -1; peter1138@5776: } peter1138@5776: peter1138@6469: /* Action 0x00 (GLS_INIT) */ peter1138@6469: static void InitChangeInfo(byte *buf, int len) peter1138@6469: { peter1138@6469: byte *bufend = buf + len; peter1138@6469: peter1138@6469: if (!check_length(len, 6, "InitChangeInfo")) return; peter1138@6469: buf++; peter1138@6607: uint8 feature = grf_load_byte(&buf); peter1138@6607: uint8 numprops = grf_load_byte(&buf); peter1138@6607: uint8 numinfo = grf_load_byte(&buf); peter1138@6607: uint8 index = grf_load_byte(&buf); peter1138@6469: peter1138@6469: while (numprops-- && buf < bufend) { peter1138@6469: uint8 prop = grf_load_byte(&buf); peter1138@6469: peter1138@6469: switch (feature) { peter1138@6469: case GSF_GLOBALVAR: peter1138@6469: switch (prop) { belugas@6674: case 0x09: // Cargo Translation Table peter1138@6469: if (index != 0) { peter1138@6469: grfmsg(1, "InitChangeInfo: Cargo translation table must start at zero"); peter1138@6469: return; peter1138@6469: } peter1138@6469: peter1138@6469: free(_cur_grffile->cargo_list); peter1138@6469: _cur_grffile->cargo_max = numinfo; peter1138@6469: _cur_grffile->cargo_list = MallocT(numinfo); peter1138@6469: peter1138@6469: int i; peter1138@6469: FOR_EACH_OBJECT { peter1138@6469: CargoLabel cl = grf_load_dword(&buf); peter1138@6469: _cur_grffile->cargo_list[i] = BSWAP32(cl); peter1138@6469: } peter1138@6469: break; peter1138@6469: } peter1138@6469: break; peter1138@6469: } peter1138@6469: } peter1138@6469: } peter1138@6469: peter1138@6685: /* Action 0x00 (GLS_RESERVE) */ peter1138@6685: static void ReserveChangeInfo(byte *buf, int len) peter1138@6685: { peter1138@6685: byte *bufend = buf + len; peter1138@6685: peter1138@6685: if (!check_length(len, 6, "InitChangeInfo")) return; peter1138@6685: buf++; peter1138@6685: uint8 feature = grf_load_byte(&buf); peter1138@6685: peter1138@6685: if (feature != GSF_CARGOS) return; peter1138@6685: peter1138@6685: uint8 numprops = grf_load_byte(&buf); peter1138@6685: uint8 numinfo = grf_load_byte(&buf); peter1138@6685: uint8 index = grf_load_byte(&buf); peter1138@6685: peter1138@6685: while (numprops-- && buf < bufend) { peter1138@6685: uint8 prop = grf_load_byte(&buf); peter1138@6685: peter1138@6685: if (CargoChangeInfo(index, numinfo, prop, &buf, bufend - buf)) { richk@6719: grfmsg(2, "ReserveChangeInfo: Ignoring property 0x%02X (not implemented)", prop); peter1138@6685: } peter1138@6685: } peter1138@6685: } peter1138@6685: miham@439: #undef FOR_EACH_OBJECT miham@439: hackykid@1883: /** hackykid@1883: * Creates a spritegroup representing a callback result hackykid@1883: * @param value The value that was used to represent this callback result hackykid@1883: * @return A spritegroup representing that callback result hackykid@1883: */ peter1138@4893: static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value) hackykid@1883: { peter1138@3595: SpriteGroup *group = AllocateSpriteGroup(); hackykid@1883: peter1138@2488: group->type = SGT_CALLBACK; hackykid@1883: belugas@6674: /* Old style callback results have the highest byte 0xFF so signify it is a callback result belugas@6674: * New style ones only have the highest bit set (allows 15-bit results, instead of just 8) */ tron@3033: if ((value >> 8) == 0xFF) { tron@3033: value &= ~0xFF00; tron@3033: } else { hackykid@1883: value &= ~0x8000; tron@3033: } hackykid@1883: peter1138@2488: group->g.callback.result = value; hackykid@1883: hackykid@1883: return group; hackykid@1883: } truelight@0: peter1138@2489: /** peter1138@2489: * Creates a spritegroup representing a sprite number result. richk@6719: * @param sprite The sprite number. richk@6719: * @param num_sprites The number of sprites per set. peter1138@2489: * @return A spritegroup representing the sprite number result. peter1138@2489: */ peter1138@4893: static const SpriteGroup* NewResultSpriteGroup(SpriteID sprite, byte num_sprites) peter1138@2489: { peter1138@3595: SpriteGroup *group = AllocateSpriteGroup(); peter1138@2489: group->type = SGT_RESULT; peter1138@3668: group->g.result.sprite = sprite; peter1138@3668: group->g.result.num_sprites = num_sprites; peter1138@2489: return group; peter1138@2489: } peter1138@2489: celestar@356: /* Action 0x01 */ darkvater@369: static void NewSpriteSet(byte *buf, int len) truelight@0: { truelight@0: /* <01> truelight@0: * truelight@0: * B feature feature to define sprites for truelight@0: * 0, 1, 2, 3: veh-type, 4: train stations truelight@0: * B num-sets number of sprite sets tron@2346: * E num-ent how many entries per sprite set truelight@0: * For vehicles, this is the number of different truelight@0: * vehicle directions in each sprite set truelight@0: * Set num-dirs=8, unless your sprites are symmetric. truelight@0: * In that case, use num-dirs=4. peter1138@6607: */ truelight@0: peter1138@5841: if (!check_length(len, 4, "NewSpriteSet")) return; tron@2346: buf++; peter1138@6607: uint8 feature = grf_load_byte(&buf); peter1138@6607: uint8 num_sets = grf_load_byte(&buf); peter1138@6607: uint16 num_ents = grf_load_extended(&buf); truelight@0: tron@2342: _cur_grffile->spriteset_start = _cur_spriteid; celestar@389: _cur_grffile->spriteset_feature = feature; tron@2342: _cur_grffile->spriteset_numsets = num_sets; tron@2342: _cur_grffile->spriteset_numents = num_ents; tron@2342: Darkvater@5568: grfmsg(7, "New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d)", tron@2342: _cur_spriteid, feature, num_sets, num_ents, num_sets * num_ents tron@2342: ); tron@2342: belugas@6614: for (uint16 i = 0; i < num_sets * num_ents; i++) { tron@2342: LoadNextSprite(_cur_spriteid++, _file_index); peter1138@3557: _nfo_line++; tron@2342: } truelight@0: } truelight@0: richk@6719: /* Action 0x01 (SKIP) */ richk@6719: static void SkipAct1(byte *buf, int len) richk@6719: { richk@6719: if (!check_length(len, 4, "SkipAct1")) return; richk@6719: buf++; richk@6719: grf_load_byte(&buf); richk@6719: uint8 num_sets = grf_load_byte(&buf); richk@6719: uint16 num_ents = grf_load_extended(&buf); richk@6719: richk@6719: _skip_sprites = num_sets * num_ents; richk@6719: richk@6719: grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites); richk@6719: } richk@6719: peter1138@3666: /* Helper function to either create a callback or link to a previously peter1138@3666: * defined spritegroup. */ peter1138@4893: static const SpriteGroup* GetGroupFromGroupID(byte setid, byte type, uint16 groupid) peter1138@3666: { peter1138@3666: if (HASBIT(groupid, 15)) return NewCallBackResultSpriteGroup(groupid); peter1138@3666: peter1138@3666: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid); peter1138@3666: return NULL; peter1138@3666: } peter1138@3666: peter1138@3666: return _cur_grffile->spritegroups[groupid]; peter1138@3666: } peter1138@3666: peter1138@3666: /* Helper function to either create a callback or a result sprite group. */ peter1138@4893: static const SpriteGroup* CreateGroupFromGroupID(byte feature, byte setid, byte type, uint16 spriteid, uint16 num_sprites) peter1138@3666: { peter1138@3666: if (HASBIT(spriteid, 15)) return NewCallBackResultSpriteGroup(spriteid); peter1138@3666: peter1138@3667: if (spriteid >= _cur_grffile->spriteset_numsets) { richk@6719: grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid, max %u", setid, type, spriteid, _cur_grffile->spriteset_numsets); peter1138@3667: return NULL; peter1138@3667: } peter1138@3667: peter1138@3666: /* Check if the sprite is within range. This can fail if the Action 0x01 peter1138@3666: * is skipped, as TTDPatch mandates that Action 0x02s must be processed. peter1138@3666: * We don't have that rule, but must live by the Patch... */ peter1138@3666: if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) { richk@6719: grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Real Sprite IDs 0x%04X - 0x%04X do not (all) exist (max 0x%04X), leaving empty", peter1138@3666: setid, type, peter1138@3666: _cur_grffile->spriteset_start + spriteid * num_sprites, peter1138@3666: _cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites - 1, _cur_spriteid - 1); peter1138@3666: return NULL; peter1138@3666: } peter1138@3666: peter1138@3803: if (feature != _cur_grffile->spriteset_feature) { richk@6719: grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping", peter1138@3803: _cur_grffile->spriteset_feature, feature); peter1138@3803: return NULL; peter1138@3803: } peter1138@3803: peter1138@3666: return NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteid * num_sprites, num_sprites); peter1138@3666: } peter1138@3666: celestar@356: /* Action 0x02 */ darkvater@369: static void NewSpriteGroup(byte *buf, int len) truelight@0: { truelight@0: /* <02> truelight@0: * truelight@0: * B feature see action 1 truelight@0: * B set-id ID of this particular definition truelight@0: * B type/num-entries truelight@0: * if 80 or greater, this is a randomized or variational truelight@0: * list definition, see below truelight@0: * otherwise it specifies a number of entries, the exact truelight@0: * meaning depends on the feature truelight@0: * V feature-specific-data (huge mess, don't even look it up --pasky) */ peter1138@3633: SpriteGroup *group = NULL; peter1138@3633: byte *bufend = buf + len; truelight@193: peter1138@5841: if (!check_length(len, 5, "NewSpriteGroup")) return; peter1138@3633: buf++; peter1138@3633: peter1138@6607: uint8 feature = grf_load_byte(&buf); peter1138@6607: uint8 setid = grf_load_byte(&buf); peter1138@6607: uint8 type = grf_load_byte(&buf); truelight@0: peter1138@2444: if (setid >= _cur_grffile->spritegroups_count) { belugas@6674: /* Allocate memory for new sprite group references. */ KUDr@5860: _cur_grffile->spritegroups = ReallocT(_cur_grffile->spritegroups, setid + 1); belugas@6674: /* Initialise new space to NULL */ peter1138@2488: for (; _cur_grffile->spritegroups_count < (setid + 1); _cur_grffile->spritegroups_count++) peter1138@2488: _cur_grffile->spritegroups[_cur_grffile->spritegroups_count] = NULL; peter1138@2444: } peter1138@2444: peter1138@3633: switch (type) { peter1138@3633: /* Deterministic Sprite Group */ peter1138@3633: case 0x81: // Self scope, byte peter1138@3633: case 0x82: // Parent scope, byte peter1138@3668: case 0x85: // Self scope, word peter1138@3668: case 0x86: // Parent scope, word peter1138@3668: case 0x89: // Self scope, dword peter1138@3668: case 0x8A: // Parent scope, dword peter1138@3633: { peter1138@3668: byte varadjust; peter1138@3668: byte varsize; peter1138@3668: peter1138@3668: /* Check we can load the var size parameter */ peter1138@5841: if (!check_length(bufend - buf, 1, "NewSpriteGroup (Deterministic) (1)")) return; peter1138@3633: peter1138@3633: group = AllocateSpriteGroup(); peter1138@3633: group->type = SGT_DETERMINISTIC; peter1138@3668: group->g.determ.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF; peter1138@3668: peter1138@3668: switch (GB(type, 2, 2)) { peter1138@3672: default: NOT_REACHED(); peter1138@3668: case 0: group->g.determ.size = DSG_SIZE_BYTE; varsize = 1; break; peter1138@3668: case 1: group->g.determ.size = DSG_SIZE_WORD; varsize = 2; break; peter1138@3668: case 2: group->g.determ.size = DSG_SIZE_DWORD; varsize = 4; break; peter1138@3633: } peter1138@3633: peter1138@5841: if (!check_length(bufend - buf, 5 + varsize, "NewSpriteGroup (Deterministic) (2)")) return; peter1138@3668: peter1138@3668: /* Loop through the var adjusts. Unfortunately we don't know how many we have peter1138@3668: * from the outset, so we shall have to keep reallocing. */ peter1138@3668: do { peter1138@3668: DeterministicSpriteGroupAdjust *adjust; peter1138@3668: peter1138@3668: if (group->g.determ.num_adjusts > 0) { peter1138@5841: if (!check_length(bufend - buf, 2 + varsize + 3, "NewSpriteGroup (Deterministic) (3)")) return; peter1138@3668: } peter1138@3668: peter1138@3668: group->g.determ.num_adjusts++; KUDr@5860: group->g.determ.adjusts = ReallocT(group->g.determ.adjusts, group->g.determ.num_adjusts); peter1138@3668: peter1138@3668: adjust = &group->g.determ.adjusts[group->g.determ.num_adjusts - 1]; peter1138@3668: peter1138@3668: /* The first var adjust doesn't have an operation specified, so we set it to add. */ rubidium@5838: adjust->operation = group->g.determ.num_adjusts == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)grf_load_byte(&buf); peter1138@3668: adjust->variable = grf_load_byte(&buf); maedhros@5868: if (adjust->variable == 0x7E) { maedhros@5868: /* Link subroutine group */ maedhros@5868: adjust->subroutine = GetGroupFromGroupID(setid, type, grf_load_byte(&buf)); maedhros@5868: } else { maedhros@5868: adjust->parameter = IS_BYTE_INSIDE(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0; maedhros@5868: } peter1138@3668: peter1138@3668: varadjust = grf_load_byte(&buf); peter1138@3668: adjust->shift_num = GB(varadjust, 0, 5); rubidium@5838: adjust->type = (DeterministicSpriteGroupAdjustType)GB(varadjust, 6, 2); peter1138@3668: adjust->and_mask = grf_load_var(varsize, &buf); peter1138@3668: peter1138@3668: if (adjust->type != DSGA_TYPE_NONE) { peter1138@3668: adjust->add_val = grf_load_var(varsize, &buf); peter1138@3668: adjust->divmod_val = grf_load_var(varsize, &buf); peter1138@3668: } else { peter1138@3668: adjust->add_val = 0; peter1138@3668: adjust->divmod_val = 0; peter1138@3668: } peter1138@3668: peter1138@3668: /* Continue reading var adjusts while bit 5 is set. */ peter1138@3668: } while (HASBIT(varadjust, 5)); peter1138@3668: peter1138@3668: group->g.determ.num_ranges = grf_load_byte(&buf); richk@6719: if (group->g.determ.num_ranges > 0) group->g.determ.ranges = CallocT(group->g.determ.num_ranges); peter1138@3668: peter1138@5841: if (!check_length(bufend - buf, 2 + (2 + 2 * varsize) * group->g.determ.num_ranges, "NewSpriteGroup (Deterministic)")) return; peter1138@3668: peter1138@6607: for (uint i = 0; i < group->g.determ.num_ranges; i++) { peter1138@3668: group->g.determ.ranges[i].group = GetGroupFromGroupID(setid, type, grf_load_word(&buf)); peter1138@3668: group->g.determ.ranges[i].low = grf_load_var(varsize, &buf); peter1138@3668: group->g.determ.ranges[i].high = grf_load_var(varsize, &buf); peter1138@3633: } peter1138@3633: peter1138@3668: group->g.determ.default_group = GetGroupFromGroupID(setid, type, grf_load_word(&buf)); peter1138@3633: break; tron@445: } tron@445: peter1138@3633: /* Randomized Sprite Group */ peter1138@3633: case 0x80: // Self scope peter1138@3633: case 0x83: // Parent scope peter1138@3633: { peter1138@5841: if (!check_length(bufend - buf, 7, "NewSpriteGroup (Randomized) (1)")) return; peter1138@3633: peter1138@3633: group = AllocateSpriteGroup(); peter1138@3633: group->type = SGT_RANDOMIZED; peter1138@3668: group->g.random.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF; peter1138@3668: peter1138@6607: uint8 triggers = grf_load_byte(&buf); peter1138@3668: group->g.random.triggers = GB(triggers, 0, 7); peter1138@3668: group->g.random.cmp_mode = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY; peter1138@3668: group->g.random.lowest_randbit = grf_load_byte(&buf); peter1138@3668: group->g.random.num_groups = grf_load_byte(&buf); KUDr@5860: group->g.random.groups = CallocT(group->g.random.num_groups); peter1138@3668: peter1138@5841: if (!check_length(bufend - buf, 2 * group->g.random.num_groups, "NewSpriteGroup (Randomized) (2)")) return; peter1138@3668: peter1138@6607: for (uint i = 0; i < group->g.random.num_groups; i++) { peter1138@3668: group->g.random.groups[i] = GetGroupFromGroupID(setid, type, grf_load_word(&buf)); peter1138@3633: } peter1138@3633: peter1138@3633: break; peter1138@2489: } peter1138@3633: peter1138@3668: /* Neither a variable or randomized sprite group... must be a real group */ peter1138@3633: default: peter1138@3633: { peter1138@3803: peter1138@3803: peter1138@3668: switch (feature) { peter1138@3668: case GSF_TRAIN: peter1138@3668: case GSF_ROAD: peter1138@3668: case GSF_SHIP: peter1138@3668: case GSF_AIRCRAFT: peter1138@3668: case GSF_STATION: richk@6719: case GSF_CANAL: peter1138@6691: case GSF_CARGOS: peter1138@3668: { peter1138@3668: byte sprites = _cur_grffile->spriteset_numents; peter1138@3668: byte num_loaded = type; peter1138@3668: byte num_loading = grf_load_byte(&buf); peter1138@3668: peter1138@3668: if (_cur_grffile->spriteset_start == 0) { Darkvater@5568: grfmsg(0, "NewSpriteGroup: No sprite set to work on! Skipping"); peter1138@3668: return; peter1138@3668: } peter1138@3668: peter1138@5841: if (!check_length(bufend - buf, 2 * num_loaded + 2 * num_loading, "NewSpriteGroup (Real) (1)")) return; peter1138@3668: peter1138@3668: group = AllocateSpriteGroup(); peter1138@3668: group->type = SGT_REAL; peter1138@3668: peter1138@3668: group->g.real.num_loaded = num_loaded; peter1138@3668: group->g.real.num_loading = num_loading; KUDr@5860: if (num_loaded > 0) group->g.real.loaded = CallocT(num_loaded); KUDr@5860: if (num_loading > 0) group->g.real.loading = CallocT(num_loading); peter1138@3668: Darkvater@5568: grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading", peter1138@3668: setid, sprites, num_loaded, num_loading); peter1138@3668: peter1138@6607: for (uint i = 0; i < num_loaded; i++) { peter1138@3668: uint16 spriteid = grf_load_word(&buf); peter1138@3803: group->g.real.loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites); Darkvater@5568: grfmsg(8, "NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid); peter1138@3668: } peter1138@3668: peter1138@6607: for (uint i = 0; i < num_loading; i++) { peter1138@3668: uint16 spriteid = grf_load_word(&buf); peter1138@3803: group->g.real.loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites); Darkvater@5568: grfmsg(8, "NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid); peter1138@3668: } peter1138@3668: peter1138@3668: break; peter1138@3668: } peter1138@3668: maedhros@6658: case GSF_TOWNHOUSE: { maedhros@6658: byte sprites = _cur_grffile->spriteset_numents; maedhros@6658: byte num_sprites = max((uint8)1, type); maedhros@6658: uint i; maedhros@6658: maedhros@6658: group = AllocateSpriteGroup(); maedhros@6658: group->type = SGT_TILELAYOUT; maedhros@6658: group->g.layout.num_sprites = sprites; maedhros@6658: group->g.layout.dts = CallocT(1); maedhros@6658: maedhros@6658: /* Groundsprite */ maedhros@6658: group->g.layout.dts->ground_sprite = grf_load_word(&buf); maedhros@6658: group->g.layout.dts->ground_pal = grf_load_word(&buf); maedhros@6658: /* Remap transparent/colour modifier bits */ maedhros@6658: if (HASBIT(group->g.layout.dts->ground_sprite, 14)) { maedhros@6658: CLRBIT(group->g.layout.dts->ground_sprite, 14); maedhros@6658: SETBIT(group->g.layout.dts->ground_sprite, PALETTE_MODIFIER_TRANSPARENT); maedhros@6658: } maedhros@6658: if (HASBIT(group->g.layout.dts->ground_sprite, 15)) { maedhros@6658: CLRBIT(group->g.layout.dts->ground_sprite, 15); maedhros@6658: SETBIT(group->g.layout.dts->ground_sprite, PALETTE_MODIFIER_COLOR); maedhros@6658: } maedhros@6658: if (HASBIT(group->g.layout.dts->ground_pal, 14)) { maedhros@6658: CLRBIT(group->g.layout.dts->ground_pal, 14); maedhros@6658: SETBIT(group->g.layout.dts->ground_sprite, SPRITE_MODIFIER_OPAQUE); maedhros@6658: } maedhros@6658: if (HASBIT(group->g.layout.dts->ground_pal, 15)) { maedhros@6658: /* Bit 31 set means this is a custom sprite, so rewrite it to the maedhros@6658: * last spriteset defined. */ maedhros@6658: SpriteID sprite = _cur_grffile->spriteset_start + GB(group->g.layout.dts->ground_sprite, 0, 14) * sprites; maedhros@6658: SB(group->g.layout.dts->ground_sprite, 0, SPRITE_WIDTH, sprite); maedhros@6658: CLRBIT(group->g.layout.dts->ground_pal, 15); maedhros@6658: } maedhros@6658: maedhros@6658: group->g.layout.dts->seq = CallocT(num_sprites + 1); maedhros@6658: maedhros@6658: for (i = 0; i < num_sprites; i++) { maedhros@6658: DrawTileSeqStruct *seq = (DrawTileSeqStruct*)&group->g.layout.dts->seq[i]; maedhros@6658: maedhros@6658: seq->image = grf_load_word(&buf); maedhros@6658: seq->pal = grf_load_word(&buf); maedhros@6658: seq->delta_x = grf_load_byte(&buf); maedhros@6658: seq->delta_y = grf_load_byte(&buf); maedhros@6658: maedhros@6658: if (HASBIT(seq->image, 14)) { maedhros@6658: CLRBIT(seq->image, 14); maedhros@6658: SETBIT(seq->image, PALETTE_MODIFIER_TRANSPARENT); maedhros@6658: } maedhros@6658: if (HASBIT(seq->image, 15)) { maedhros@6658: CLRBIT(seq->image, 15); maedhros@6658: SETBIT(seq->image, PALETTE_MODIFIER_COLOR); maedhros@6658: } maedhros@6658: if (HASBIT(seq->pal, 14)) { maedhros@6658: CLRBIT(seq->pal, 14); maedhros@6658: SETBIT(seq->image, SPRITE_MODIFIER_OPAQUE); maedhros@6658: } maedhros@6658: if (HASBIT(seq->pal, 15)) { maedhros@6658: /* Bit 31 set means this is a custom sprite, so rewrite it to the maedhros@6658: * last spriteset defined. */ maedhros@6658: SpriteID sprite = _cur_grffile->spriteset_start + GB(seq->image, 0, 14) * sprites; maedhros@6658: SB(seq->image, 0, SPRITE_WIDTH, sprite); maedhros@6658: CLRBIT(seq->pal, 15); maedhros@6658: } maedhros@6658: maedhros@6658: if (type > 0) { maedhros@6658: seq->delta_z = grf_load_byte(&buf); maedhros@6658: if ((byte)seq->delta_z == 0x80) continue; maedhros@6658: } maedhros@6658: maedhros@6658: seq->size_x = grf_load_byte(&buf); maedhros@6658: seq->size_y = grf_load_byte(&buf); maedhros@6658: seq->size_z = grf_load_byte(&buf); maedhros@6658: } maedhros@6658: maedhros@6658: /* Set the terminator value. */ maedhros@6658: ((DrawTileSeqStruct*)group->g.layout.dts->seq)[i].delta_x = (byte)0x80; maedhros@6658: maedhros@6658: break; maedhros@6658: } maedhros@6658: peter1138@3668: /* Loading of Tile Layout and Production Callback groups would happen here */ Darkvater@5568: default: grfmsg(1, "NewSpriteGroup: Unsupported feature %d, skipping", feature); peter1138@3633: } peter1138@2489: } truelight@0: } peter1138@2444: peter1138@2444: _cur_grffile->spritegroups[setid] = group; truelight@0: } truelight@0: peter1138@6469: static CargoID TranslateCargo(uint8 feature, uint8 ctype) peter1138@6469: { peter1138@6469: /* Special cargo types for purchase list and stations */ peter1138@6474: if (feature == GSF_STATION && ctype == 0xFE) return CT_DEFAULT_NA; peter1138@6474: if (ctype == 0xFF) return CT_PURCHASE; peter1138@6469: peter1138@6687: if (_cur_grffile->cargo_max == 0) { peter1138@6687: /* No cargo table, so use bitnum values */ peter1138@6687: if (ctype >= 32) { richk@6719: grfmsg(1, "TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype); peter1138@6687: return CT_INVALID; peter1138@6687: } peter1138@6687: peter1138@6687: for (CargoID c = 0; c < NUM_CARGO; c++) { peter1138@6687: const CargoSpec *cs = GetCargo(c); peter1138@6687: if (!cs->IsValid()) continue; peter1138@6687: peter1138@6687: if (cs->bitnum == ctype) { richk@6719: grfmsg(6, "TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, c); peter1138@6687: return c; peter1138@6687: } peter1138@6687: } peter1138@6687: richk@6719: grfmsg(5, "TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype); peter1138@6687: return CT_INVALID; peter1138@6687: } peter1138@6687: peter1138@6469: /* Check if the cargo type is out of bounds of the cargo translation table */ peter1138@6687: if (ctype >= _cur_grffile->cargo_max) { richk@6719: grfmsg(1, "TranslateCargo: Cargo type %d out of range (max %d), skipping.", ctype, _cur_grffile->cargo_max - 1); peter1138@6469: return CT_INVALID; peter1138@6469: } peter1138@6469: peter1138@6469: /* Look up the cargo label from the translation table */ peter1138@6687: CargoLabel cl = _cur_grffile->cargo_list[ctype]; peter1138@6469: if (cl == 0) { richk@6719: grfmsg(5, "TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype); peter1138@6469: return CT_INVALID; peter1138@6469: } peter1138@6469: peter1138@6469: ctype = GetCargoIDByLabel(cl); peter1138@6469: if (ctype == CT_INVALID) { richk@6719: 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)); peter1138@6469: return CT_INVALID; peter1138@6469: } peter1138@6469: richk@6719: 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); peter1138@6469: return ctype; peter1138@6469: } peter1138@6469: peter1138@6689: peter1138@6689: static void VehicleMapSpriteGroup(byte *buf, byte feature, uint8 idcount, uint8 cidcount, bool wagover) truelight@0: { truelight@0: static byte *last_engines; truelight@0: static int last_engines_count; truelight@0: peter1138@6689: if (!wagover) { peter1138@6689: if (last_engines_count != idcount) { peter1138@6689: last_engines = ReallocT(last_engines, idcount); peter1138@6689: last_engines_count = idcount; darkvater@403: } peter1138@6689: } else { celestar@372: if (last_engines_count == 0) { richk@6719: grfmsg(0, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with"); celestar@372: return; celestar@372: } peter1138@6689: richk@6719: grfmsg(6, "VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons", celestar@379: last_engines_count, idcount); celestar@372: } darkvater@398: peter1138@6607: for (uint i = 0; i < idcount; i++) { celestar@372: uint8 engine_id = buf[3 + i]; celestar@372: uint8 engine = engine_id + _vehshifts[feature]; celestar@357: byte *bp = &buf[4 + idcount]; celestar@357: celestar@372: if (engine_id > _vehcounts[feature]) { Darkvater@5568: grfmsg(0, "Id %u for feature 0x%02X is out of bounds", engine_id, feature); celestar@372: return; celestar@372: } celestar@372: richk@6719: grfmsg(7, "VehicleMapSpriteGroup: [%d] Engine %d...", i, engine); celestar@379: peter1138@6607: for (uint c = 0; c < cidcount; c++) { celestar@357: uint8 ctype = grf_load_byte(&bp); darkvater@369: uint16 groupid = grf_load_word(&bp); celestar@357: richk@6719: grfmsg(8, "VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid); celestar@379: peter1138@2516: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "VehicleMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", groupid, _cur_grffile->spritegroups_count); peter1138@6689: continue; celestar@357: } celestar@357: peter1138@6469: ctype = TranslateCargo(feature, ctype); peter1138@6469: if (ctype == CT_INVALID) continue; peter1138@5338: celestar@379: if (wagover) { peter1138@4869: SetWagonOverrideSprites(engine, ctype, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); celestar@357: } else { peter1138@2444: SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]); celestar@357: last_engines[i] = engine; celestar@357: } truelight@0: } celestar@357: } truelight@0: celestar@357: { peter1138@6689: byte *bp = &buf[4 + idcount + cidcount * 3]; darkvater@369: uint16 groupid = grf_load_word(&bp); truelight@0: Darkvater@5568: grfmsg(8, "-- Default group id 0x%04X", groupid); celestar@379: peter1138@6607: for (uint i = 0; i < idcount; i++) { truelight@0: uint8 engine = buf[3 + i] + _vehshifts[feature]; truelight@0: belugas@6674: /* Don't tell me you don't love duplicated code! */ peter1138@2516: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { peter1138@6689: grfmsg(1, "FeatureMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", peter1138@6689: groupid, _cur_grffile->spritegroups_count); peter1138@6689: continue; truelight@0: } truelight@0: celestar@379: if (wagover) { peter1138@3695: /* If the ID for this action 3 is the same as the vehicle ID, peter1138@6689: * this indicates we have a helicopter rotor override. */ peter1138@3695: if (feature == GSF_AIRCRAFT && engine == last_engines[i]) { peter1138@3695: SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]); peter1138@3695: } else { belugas@6674: /* TODO: No multiple cargo types per vehicle yet. --pasky */ peter1138@6474: SetWagonOverrideSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); peter1138@3695: } celestar@357: } else { peter1138@6474: SetCustomEngineSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid]); peter1138@3924: SetEngineGRF(engine, _cur_grffile); celestar@357: last_engines[i] = engine; truelight@0: } truelight@0: } truelight@0: } truelight@0: } truelight@0: peter1138@6689: richk@6719: static void CanalMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount) richk@6719: { richk@6719: byte *bp = &buf[4 + idcount + cidcount * 3]; richk@6719: uint16 groupid = grf_load_word(&bp); richk@6719: richk@6719: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "CanalMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.", richk@6719: groupid, _cur_grffile->spritegroups_count); richk@6719: return; richk@6719: } richk@6719: richk@6719: for (uint i = 0; i < idcount; i++) { richk@6719: CanalFeature cf = (CanalFeature)buf[3 + i]; richk@6719: richk@6719: if (cf >= CF_END) { richk@6719: grfmsg(1, "CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf); richk@6719: continue; richk@6719: } richk@6719: richk@6719: _canal_sg[cf] = _cur_grffile->spritegroups[groupid]; richk@6719: } richk@6719: } richk@6719: richk@6719: peter1138@6689: static void StationMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount) peter1138@6689: { peter1138@6689: for (uint i = 0; i < idcount; i++) { peter1138@6689: uint8 stid = buf[3 + i]; peter1138@6689: StationSpec *statspec = _cur_grffile->stations[stid]; peter1138@6689: byte *bp = &buf[4 + idcount]; peter1138@6689: peter1138@6689: for (uint c = 0; c < cidcount; c++) { peter1138@6689: uint8 ctype = grf_load_byte(&bp); peter1138@6689: uint16 groupid = grf_load_word(&bp); peter1138@6689: peter1138@6689: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "StationMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", peter1138@6689: groupid, _cur_grffile->spritegroups_count); peter1138@6689: continue; peter1138@6689: } peter1138@6689: peter1138@6689: ctype = TranslateCargo(GSF_STATION, ctype); peter1138@6689: if (ctype == CT_INVALID) continue; peter1138@6689: peter1138@6689: statspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid]; peter1138@6689: } peter1138@6689: } peter1138@6689: peter1138@6689: { peter1138@6689: byte *bp = &buf[4 + idcount + cidcount * 3]; peter1138@6689: uint16 groupid = grf_load_word(&bp); peter1138@6689: peter1138@6689: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "StationMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", peter1138@6689: groupid, _cur_grffile->spritegroups_count); peter1138@6689: return; peter1138@6689: } peter1138@6689: peter1138@6689: for (uint i = 0; i < idcount; i++) { peter1138@6689: uint8 stid = buf[3 + i]; peter1138@6689: StationSpec *statspec = _cur_grffile->stations[stid]; peter1138@6689: peter1138@6689: statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid]; richk@6719: statspec->grffile = _cur_grffile; peter1138@6689: statspec->localidx = stid; peter1138@6689: SetCustomStationSpec(statspec); peter1138@6689: } peter1138@6689: } peter1138@6689: } peter1138@6689: peter1138@6689: peter1138@6689: static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount) peter1138@6689: { peter1138@6689: byte *bp = &buf[4 + idcount + cidcount * 3]; peter1138@6689: uint16 groupid = grf_load_word(&bp); peter1138@6689: peter1138@6689: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "TownHouseMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.", peter1138@6689: groupid, _cur_grffile->spritegroups_count); peter1138@6689: return; peter1138@6689: } peter1138@6689: peter1138@6689: for (uint i = 0; i < idcount; i++) { peter1138@6689: uint8 hid = buf[3 + i]; peter1138@6689: HouseSpec *hs = _cur_grffile->housespec[hid]; peter1138@6689: peter1138@6689: if (hs == NULL) { richk@6719: grfmsg(1, "TownHouseMapSpriteGroup: Too many houses defined, skipping"); peter1138@6689: return; peter1138@6689: } peter1138@6689: peter1138@6689: hs->spritegroup = _cur_grffile->spritegroups[groupid]; peter1138@6689: } peter1138@6689: } peter1138@6689: peter1138@6691: peter1138@6691: static void CargoMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount) peter1138@6691: { peter1138@6691: byte *bp = &buf[4 + idcount + cidcount * 3]; peter1138@6691: uint16 groupid = grf_load_word(&bp); peter1138@6691: peter1138@6691: if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) { richk@6719: grfmsg(1, "CargoMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.", peter1138@6691: groupid, _cur_grffile->spritegroups_count); peter1138@6691: return; peter1138@6691: } peter1138@6691: peter1138@6691: for (uint i = 0; i < idcount; i++) { peter1138@6691: CargoID cid = buf[3 + i]; peter1138@6691: peter1138@6691: if (cid >= NUM_CARGO) { richk@6719: grfmsg(1, "CargoMapSpriteGroup: Cargo ID %d out of range, skipping"); peter1138@6691: continue; peter1138@6691: } peter1138@6691: peter1138@6691: CargoSpec *cs = &_cargo[cid]; peter1138@6691: cs->grfid = _cur_grffile->grfid; peter1138@6691: cs->group = _cur_grffile->spritegroups[groupid]; peter1138@6691: } peter1138@6691: } peter1138@6691: peter1138@6691: peter1138@6689: /* Action 0x03 */ peter1138@6689: static void FeatureMapSpriteGroup(byte *buf, int len) peter1138@6689: { peter1138@6689: /* <03> ... [ ]... peter1138@6689: * id-list := [] [id-list] peter1138@6689: * cargo-list := [cargo-list] peter1138@6689: * peter1138@6689: * B feature see action 0 peter1138@6689: * B n-id bits 0-6: how many IDs this definition applies to peter1138@6689: * bit 7: if set, this is a wagon override definition (see below) peter1138@6689: * B ids the IDs for which this definition applies peter1138@6689: * B num-cid number of cargo IDs (sprite group IDs) in this definition peter1138@6689: * can be zero, in that case the def-cid is used always peter1138@6689: * B cargo-type type of this cargo type (e.g. mail=2, wood=7, see below) peter1138@6689: * W cid cargo ID (sprite group ID) for this type of cargo peter1138@6689: * W def-cid default cargo ID (sprite group ID) */ peter1138@6689: peter1138@6689: if (!check_length(len, 6, "FeatureMapSpriteGroup")) return; peter1138@6689: peter1138@6689: uint8 feature = buf[1]; peter1138@6689: uint8 idcount = buf[2] & 0x7F; peter1138@6689: bool wagover = (buf[2] & 0x80) == 0x80; peter1138@6689: peter1138@6689: if (!check_length(len, 3 + idcount, "FeatureMapSpriteGroup")) return; peter1138@6689: peter1138@6689: /* If idcount is zero, this is a feature callback */ peter1138@6689: if (idcount == 0) { peter1138@6689: grfmsg(2, "FeatureMapSpriteGroup: Feature callbacks not implemented yet"); peter1138@6689: return; peter1138@6689: } peter1138@6689: peter1138@6689: uint8 cidcount = buf[3 + idcount]; peter1138@6689: if (!check_length(len, 4 + idcount + cidcount * 3, "FeatureMapSpriteGroup")) return; peter1138@6689: peter1138@6689: grfmsg(6, "FeatureMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d", peter1138@6689: feature, idcount, cidcount, wagover); peter1138@6689: peter1138@6689: if (_cur_grffile->spriteset_start == 0 || _cur_grffile->spritegroups == 0) { peter1138@6689: grfmsg(1, "FeatureMapSpriteGroup: No sprite set to work on! Skipping"); peter1138@6689: return; peter1138@6689: } peter1138@6689: peter1138@6689: switch (feature) { peter1138@6689: case GSF_TRAIN: peter1138@6689: case GSF_ROAD: peter1138@6689: case GSF_SHIP: peter1138@6689: case GSF_AIRCRAFT: peter1138@6689: VehicleMapSpriteGroup(buf, feature, idcount, cidcount, wagover); peter1138@6689: return; peter1138@6689: richk@6719: case GSF_CANAL: richk@6719: CanalMapSpriteGroup(buf, idcount, cidcount); richk@6719: return; richk@6719: peter1138@6689: case GSF_STATION: peter1138@6689: StationMapSpriteGroup(buf, idcount, cidcount); peter1138@6689: return; peter1138@6689: peter1138@6689: case GSF_TOWNHOUSE: peter1138@6689: TownHouseMapSpriteGroup(buf, idcount, cidcount); peter1138@6689: return; peter1138@6689: peter1138@6691: case GSF_CARGOS: peter1138@6691: CargoMapSpriteGroup(buf, idcount, cidcount); peter1138@6691: return; peter1138@6691: peter1138@6689: default: peter1138@6689: grfmsg(1, "FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature); peter1138@6689: return; peter1138@6689: } peter1138@6689: } peter1138@6689: celestar@356: /* Action 0x04 */ belugas@3879: static void FeatureNewName(byte *buf, int len) truelight@0: { truelight@0: /* <04> truelight@0: * belugas@3601: * B veh-type see action 0 (as 00..07, + 0A belugas@3601: * But IF veh-type = 48, then generic text belugas@3601: * B language-id If bit 6 is set, This is the extended language scheme, belugas@3601: with up to 64 language. belugas@3601: Otherwise, it is a mapping where set bits have meaning belugas@3601: 0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish belugas@3601: Bit 7 set means this is a generic text, not a vehicle one (or else) truelight@0: * B num-veh number of vehicles which are getting a new name tron@2346: * B/W offset number of the first vehicle that gets a new name belugas@3601: * Byte : ID of vehicle to change belugas@3601: * Word : ID of string to change/add truelight@0: * S data new texts, each of them zero-terminated, after truelight@0: * which the next name begins. */ peter1138@6607: peter1138@3643: bool new_scheme = _cur_grffile->grf_version >= 7; truelight@0: peter1138@5841: if (!check_length(len, 6, "FeatureNewName")) return; tron@2346: buf++; peter1138@6607: uint8 feature = grf_load_byte(&buf); peter1138@6607: uint8 lang = grf_load_byte(&buf); peter1138@6607: uint8 num = grf_load_byte(&buf); peter1138@6607: bool generic = HASBIT(lang, 7); peter1138@6607: uint16 id = generic ? grf_load_word(&buf) : grf_load_byte(&buf); peter1138@4992: peter1138@4992: CLRBIT(lang, 7); tron@2346: peter1138@3760: if (feature <= GSF_AIRCRAFT && id < _vehcounts[feature]) { belugas@3601: id += _vehshifts[feature]; tron@2346: } peter1138@6607: uint16 endid = id + num; truelight@0: Darkvater@5568: grfmsg(6, "FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X", celestar@379: id, endid, feature, lang); celestar@379: peter1138@4992: len -= generic ? 6 : 5; peter1138@4992: celestar@357: for (; id < endid && len > 0; id++) { maedhros@6416: const char *name = grf_load_string(&buf, len); maedhros@6416: size_t name_length = strlen(name) + 1; maedhros@6416: maedhros@6416: len -= (int)name_length; maedhros@6416: richk@6719: grfmsg(8, "FeatureNewName: 0x%04X <- %s", id, name); richk@6719: richk@6719: switch (feature) { richk@6719: case GSF_TRAIN: richk@6719: case GSF_ROAD: richk@6719: case GSF_SHIP: richk@6719: case GSF_AIRCRAFT: richk@6719: if (id < TOTAL_NUM_ENGINES) { richk@6719: StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id); richk@6719: SetCustomEngineName(id, string); richk@6719: } else { richk@6719: AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id); peter1138@3614: } richk@6719: break; richk@6719: richk@6719: case GSF_TOWNHOUSE: richk@6719: default: richk@6719: switch (GB(id, 8, 8)) { richk@6719: case 0xC4: // Station class name richk@6719: if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) { richk@6719: grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8)); richk@6719: } else { richk@6719: StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass; richk@6719: SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED)); maedhros@6658: } richk@6719: break; richk@6719: richk@6719: case 0xC5: // Station name richk@6719: if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) { richk@6719: grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8)); richk@6719: } else { richk@6719: _cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED); richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0xC9: // House name richk@6719: if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) { richk@6719: grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8)); richk@6719: } else { richk@6719: _cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED); richk@6719: } richk@6719: break; richk@6719: richk@6719: case 0xD0: richk@6719: case 0xDC: richk@6719: AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED); richk@6719: break; richk@6719: richk@6719: default: richk@6719: grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id); richk@6719: break; richk@6719: } richk@6719: break; peter1138@3642: peter1138@3642: #if 0 belugas@3601: case GSF_CANAL : belugas@3601: case GSF_BRIDGE : belugas@3601: AddGRFString(_cur_spriteid, id, lang, name); richk@6719: switch (GB(id, 8, 8)) { belugas@6674: case 0xC9: // House name belugas@3601: default: Darkvater@5568: grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id); belugas@3601: } belugas@3601: break; belugas@3601: belugas@3601: case GSF_INDUSTRIES : belugas@6674: case 0x48 : // for generic strings belugas@3601: AddGRFString(_cur_spriteid, id, lang, name); belugas@3601: break; belugas@3601: default : Darkvater@5568: grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature); belugas@3601: break; belugas@3601: #endif celestar@379: } truelight@0: } truelight@0: } truelight@0: celestar@356: /* Action 0x05 */ truelight@0: static void GraphicsNew(byte *buf, int len) truelight@0: { truelight@0: /* <05> truelight@0: * truelight@0: * B graphics-type What set of graphics the sprites define. tron@2346: * E num-sprites How many sprites are in this set? truelight@0: * V other data Graphics type specific data. Currently unused. */ truelight@0: /* TODO */ celestar@356: peter1138@3708: SpriteID replace = 0; celestar@356: peter1138@5841: if (!check_length(len, 2, "GraphicsNew")) return; tron@2346: buf++; peter1138@6607: uint8 type = grf_load_byte(&buf); peter1138@6607: uint16 num = grf_load_extended(&buf); celestar@356: peter1138@3638: switch (type) { belugas@6674: case 0x04: // Signal graphics peter1138@3638: if (num != 112 && num != 240) { richk@6719: grfmsg(1, "GraphicsNew: Signal graphics sprite count must be 112 or 240, skipping"); peter1138@3638: return; peter1138@3638: } peter1138@3638: _signal_base = _cur_spriteid; peter1138@3638: break; peter1138@3638: belugas@6674: case 0x05: // Catenary graphics peter1138@3708: if (num != 48) { richk@6719: grfmsg(1, "GraphicsNew: Catenary graphics sprite count must be 48, skipping"); peter1138@3708: return; peter1138@3708: } peter1138@3708: replace = SPR_ELRAIL_BASE + 3; peter1138@3708: break; peter1138@3708: belugas@6674: case 0x06: // Foundations peter1138@3709: if (num != 74) { richk@6719: grfmsg(1, "GraphicsNew: Foundation graphics sprite count must be 74, skipping"); peter1138@3709: return; peter1138@3709: } peter1138@3709: replace = SPR_SLOPES_BASE; peter1138@3709: break; peter1138@3709: belugas@6674: case 0x08: // Canal graphics peter1138@3709: if (num != 65) { richk@6719: grfmsg(1, "GraphicsNew: Canal graphics sprite count must be 65, skipping"); peter1138@3709: return; peter1138@3709: } peter1138@3709: replace = SPR_CANALS_BASE + 5; peter1138@3709: break; peter1138@3709: richk@6719: case 0x09: // One way graphics richk@6719: if (num != 6) { richk@6719: grfmsg(1, "GraphicsNew: One way road graphics sprite count must be 6, skipping"); richk@6719: return; richk@6719: } richk@6719: replace = SPR_ONEWAY_BASE; richk@6719: break; richk@6719: richk@6719: case 0x0A: // 2CC colour maps richk@6719: if (num != 256) { richk@6719: grfmsg(1, "GraphicsNew: 2CC colour maps sprite count must be 256, skipping"); richk@6719: return; richk@6719: } richk@6719: replace = SPR_2CCMAP_BASE; richk@6719: break; richk@6719: richk@6719: case 0x0B: // tramways richk@6719: if (num != 113) { richk@6719: grfmsg(1, "GraphicsNews: Tramway graphics sprite count must be 113, skipping"); richk@6719: return; richk@6719: } richk@6719: replace = SPR_TRAMWAY_BASE; richk@6719: break; richk@6719: belugas@6674: case 0x0D: // Coast graphics peter1138@5210: if (num != 16) { richk@6719: grfmsg(1, "GraphicsNew: Coast graphics sprite count must be 16, skipping"); peter1138@5210: return; peter1138@5210: } peter1138@5210: _coast_base = _cur_spriteid; peter1138@5210: break; peter1138@5210: richk@6719: case 0x10: // New airport sprites richk@6719: if (num != 15) { richk@6719: grfmsg(1, "GraphicsNew: Airport graphics sprite count must be 15, skipping"); richk@6719: return; richk@6719: } richk@6719: replace = SPR_AIRPORTX_BASE; richk@6719: break; richk@6719: richk@6719: case 0x11: // Road stop sprites richk@6719: if (num != 8) { richk@6719: grfmsg(1, "GraphicsNew: Road stop graphics sprite count must be 8, skipping"); richk@6719: return; richk@6719: } richk@6719: replace = SPR_ROADSTOP_BASE; richk@6719: break; richk@6719: peter1138@3638: default: Darkvater@5568: grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", peter1138@3638: type, num); peter1138@3638: return; peter1138@3638: } peter1138@3638: peter1138@3708: if (replace == 0) { Darkvater@5568: grfmsg(2, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid); peter1138@3708: } else { Darkvater@5568: grfmsg(2, "GraphicsNew: Replacing %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, replace); peter1138@3708: } peter1138@3638: peter1138@3638: for (; num > 0; num--) { peter1138@3708: LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index); peter1138@3638: _nfo_line++; peter1138@3638: } truelight@0: } truelight@0: richk@6719: /* Action 0x05 (SKIP) */ richk@6719: static void SkipAct5(byte *buf, int len) richk@6719: { richk@6719: if (!check_length(len, 2, "SkipAct5")) return; richk@6719: buf++; richk@6719: richk@6719: /* Ignore type byte */ richk@6719: grf_load_byte(&buf); richk@6719: richk@6719: /* Skip the sprites of this action */ richk@6719: _skip_sprites = grf_load_extended(&buf); richk@6719: richk@6719: grfmsg(3, "SkipAct5: Skipping %d sprites", _skip_sprites); richk@6719: } richk@6719: peter1138@3806: static uint32 GetParamVal(byte param, uint32 *cond_val) peter1138@3806: { peter1138@3806: switch (param) { belugas@6674: case 0x81: // current year glx@5340: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; glx@5340: belugas@6674: case 0x83: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland peter1138@3806: return _opt.landscape; peter1138@3806: belugas@6674: case 0x84: // GRF loading stage peter1138@5161: return (_cur_stage > GLS_INIT) | ((_cur_stage == GLS_ACTIVATION) << 9); peter1138@3806: belugas@6674: case 0x85: // TTDPatch flags, only for bit tests peter1138@3811: if (cond_val == NULL) { peter1138@3811: /* Supported in Action 0x07 and 0x09, not 0x0D */ peter1138@3811: return 0; peter1138@3811: } else { peter1138@3811: uint32 param_val = _ttdpatch_flags[*cond_val / 0x20]; peter1138@3811: *cond_val %= 0x20; peter1138@3811: return param_val; peter1138@3811: } peter1138@3806: belugas@6674: case 0x86: // road traffic side, bit 4 clear=left, set=right peter1138@3806: return _opt.road_side << 4; peter1138@3806: belugas@6674: case 0x88: // GRF ID check peter1138@3806: return 0; peter1138@3806: belugas@6674: case 0x8B: { // TTDPatch version peter1138@3806: uint major = 2; peter1138@4993: uint minor = 6; peter1138@4993: uint revision = 0; // special case: 2.0.1 is 2.0.10 richk@6719: uint build = 1210; peter1138@4993: return (major << 24) | (minor << 20) | (revision << 16) | build; peter1138@3806: } peter1138@3806: belugas@6674: case 0x8D: // TTD Version, 00=DOS, 01=Windows peter1138@3806: return !_use_dos_palette; peter1138@3806: belugas@6674: case 0x8E: // Y-offset for train sprites peter1138@3806: return _traininfo_vehicle_pitch; peter1138@3806: belugas@6674: case 0x92: // Game mode peter1138@3806: return _game_mode; peter1138@3806: belugas@6674: case 0x9A: // Always -1 rubidium@5838: return UINT_MAX; peter1138@5287: belugas@6674: case 0x9D: // TTD Platform, 00=TTDPatch, 01=OpenTTD peter1138@3806: return 1; peter1138@3806: belugas@6674: case 0x9E: // Miscellaneous GRF features peter1138@3814: return _misc_grf_features; peter1138@3814: peter1138@3806: default: peter1138@3806: /* GRF Parameter */ peter1138@3806: if (param < 0x80) return _cur_grffile->param[param]; peter1138@3806: peter1138@3806: /* In-game variable. */ Darkvater@5568: grfmsg(1, "Unsupported in-game variable 0x%02X", param); rubidium@5838: return UINT_MAX; peter1138@3806: } peter1138@3806: } peter1138@3806: peter1138@3895: /* Action 0x06 */ peter1138@3895: static void CfgApply(byte *buf, int len) peter1138@3895: { peter1138@3895: /* <06> ... peter1138@3895: * peter1138@3895: * B param-num Number of parameter to substitute (First = "zero") peter1138@3895: * Ignored if that parameter was not specified in newgrf.cfg peter1138@3895: * B param-size How many bytes to replace. If larger than 4, the peter1138@3895: * bytes of the following parameter are used. In that peter1138@3895: * case, nothing is applied unless *all* parameters peter1138@3895: * were specified. peter1138@3895: * B offset Offset into data from beginning of next sprite peter1138@3895: * to place where parameter is to be stored. */ peter1138@3895: peter1138@3895: /* Preload the next sprite */ peter1138@3895: uint32 pos = FioGetPos(); peter1138@3895: uint16 num = FioReadWord(); peter1138@3895: uint8 type = FioReadByte(); peter1138@3895: peter1138@3895: /* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */ peter1138@3895: if (type == 0xFF) { KUDr@5860: _preload_sprite = MallocT(num); peter1138@3895: FioReadBlock(_preload_sprite, num); peter1138@3895: } peter1138@3895: peter1138@3895: /* Reset the file position to the start of the next sprite */ peter1138@3895: FioSeekTo(pos, SEEK_SET); peter1138@3895: peter1138@3895: if (type != 0xFF) { Darkvater@5568: grfmsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)"); peter1138@3895: return; peter1138@3895: } peter1138@3895: peter1138@3895: /* Now perform the Action 0x06 on our data. */ peter1138@3895: buf++; peter1138@3895: peter1138@3895: for (;;) { peter1138@3895: uint i; peter1138@3895: uint param_num; peter1138@3895: uint param_size; peter1138@3895: uint offset; peter1138@3895: bool add_value; peter1138@3895: peter1138@3895: /* Read the parameter to apply. 0xFF indicates no more data to change. */ peter1138@3895: param_num = grf_load_byte(&buf); peter1138@3895: if (param_num == 0xFF) break; peter1138@3895: peter1138@3895: /* Get the size of the parameter to use. If the size covers multiple peter1138@3895: * double words, sequential parameter values are used. */ peter1138@3895: param_size = grf_load_byte(&buf); peter1138@3895: peter1138@3895: /* Bit 7 of param_size indicates we should add to the original value peter1138@3895: * instead of replacing it. */ peter1138@3895: add_value = HASBIT(param_size, 7); peter1138@3895: param_size = GB(param_size, 0, 7); peter1138@3895: peter1138@3895: /* Where to apply the data to within the pseudo sprite data. */ peter1138@3895: offset = grf_load_extended(&buf); peter1138@3895: peter1138@3895: /* If the parameter is a GRF parameter (not an internal variable) check peter1138@3895: * if it (and all further sequential parameters) has been defined. */ peter1138@3895: if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur_grffile->param_end) { Darkvater@5568: grfmsg(2, "CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4)); peter1138@3895: break; peter1138@3895: } peter1138@3895: Darkvater@5568: grfmsg(8, "CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset); peter1138@3895: richk@6719: bool carry = false; peter1138@3895: for (i = 0; i < param_size; i++) { peter1138@3895: uint32 value = GetParamVal(param_num + i / 4, NULL); richk@6719: /* Reset carry flag for each iteration of the variable (only really richk@6719: * matters if param_size is greater than 4) */ richk@6719: if (i == 0) carry = false; peter1138@3895: peter1138@3895: if (add_value) { richk@6719: uint new_value = _preload_sprite[offset + i] + GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0); richk@6719: _preload_sprite[offset + i] = GB(new_value, 0, 8); richk@6719: /* Check if the addition overflowed */ richk@6719: carry = new_value >= 256; peter1138@3895: } else { peter1138@3895: _preload_sprite[offset + i] = GB(value, (i % 4) * 8, 8); peter1138@3895: } peter1138@3895: } peter1138@3895: } peter1138@3895: } peter1138@3895: celestar@356: /* Action 0x07 */ celestar@356: /* Action 0x09 */ truelight@0: static void SkipIf(byte *buf, int len) truelight@0: { truelight@0: /* <07/09> truelight@0: * truelight@0: * B param-num truelight@0: * B param-size truelight@0: * B condition-type truelight@0: * V value truelight@0: * B num-sprites */ truelight@0: /* TODO: More params. More condition types. */ tron@2336: uint32 cond_val = 0; peter1138@3806: uint32 mask = 0; darkvater@360: bool result; truelight@0: peter1138@5841: if (!check_length(len, 6, "SkipIf")) return; peter1138@3714: buf++; peter1138@6607: uint8 param = grf_load_byte(&buf); peter1138@6607: uint8 paramsize = grf_load_byte(&buf); peter1138@6607: uint8 condtype = grf_load_byte(&buf); truelight@0: darkvater@359: if (condtype < 2) { tron@1611: /* Always 1 for bit tests, the given value should be ignored. */ darkvater@359: paramsize = 1; darkvater@359: } darkvater@359: tron@1611: switch (paramsize) { peter1138@3806: case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break; peter1138@3806: case 2: cond_val = grf_load_word(&buf); mask = 0x0000FFFF; break; peter1138@3806: case 1: cond_val = grf_load_byte(&buf); mask = 0x000000FF; break; tron@1611: default: break; tron@1611: } darkvater@359: peter1138@3806: if (param < 0x80 && _cur_grffile->param_end <= param) { richk@6719: grfmsg(7, "SkipIf: Param %d undefined, skipping test", param); peter1138@3806: return; celestar@357: } truelight@0: peter1138@6607: uint32 param_val = GetParamVal(param, &cond_val); peter1138@3806: richk@6719: grfmsg(7, "SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val); peter1138@5703: peter1138@5703: if (param == 0x88) { peter1138@5703: /* GRF ID checks */ peter1138@5703: peter1138@5703: const GRFConfig *c = GetGRFConfig(cond_val); peter1138@5703: peter1138@5703: if (condtype != 10 && c == NULL) { richk@6719: grfmsg(7, "SkipIf: GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val)); peter1138@5703: return; peter1138@5234: } peter1138@5234: peter1138@5703: switch (condtype) { peter1138@5703: /* Tests 6 to 10 are only for param 0x88, GRFID checks */ belugas@6674: case 6: // Is GRFID active? maedhros@6555: result = c->status == GCS_ACTIVATED; peter1138@5703: break; peter1138@5703: belugas@6674: case 7: // Is GRFID non-active? maedhros@6555: result = c->status != GCS_ACTIVATED; peter1138@5703: break; peter1138@5703: belugas@6674: case 8: // GRFID is not but will be active? maedhros@6555: result = c->status == GCS_INITIALISED; peter1138@5703: break; peter1138@5703: belugas@6674: case 9: // GRFID is or will be active? maedhros@6555: result = c->status == GCS_ACTIVATED || c->status == GCS_INITIALISED; peter1138@5703: break; peter1138@5703: belugas@6674: case 10: // GRFID is not nor will be active peter1138@5703: /* This is the only condtype that doesn't get ignored if the GRFID is not found */ maedhros@6555: result = c == NULL || c->flags == GCS_DISABLED || c->status == GCS_NOT_FOUND; peter1138@5703: break; peter1138@5703: richk@6719: default: grfmsg(1, "SkipIf: Unsupported GRF test %d. Ignoring", condtype); return; peter1138@5234: } peter1138@5703: } else { peter1138@5703: /* Parameter or variable tests */ peter1138@5703: switch (condtype) { peter1138@5703: case 0: result = !!(param_val & (1 << cond_val)); peter1138@5703: break; peter1138@5703: case 1: result = !(param_val & (1 << cond_val)); peter1138@5703: break; peter1138@5703: case 2: result = (param_val & mask) == cond_val; peter1138@5703: break; peter1138@5703: case 3: result = (param_val & mask) != cond_val; peter1138@5703: break; peter1138@5703: case 4: result = (param_val & mask) < cond_val; peter1138@5703: break; peter1138@5703: case 5: result = (param_val & mask) > cond_val; peter1138@5703: break; richk@6719: case 11: result = GetCargoIDByLabel(BSWAP32(cond_val)) == CT_INVALID; richk@6719: break; richk@6719: case 12: result = GetCargoIDByLabel(BSWAP32(cond_val)) != CT_INVALID; richk@6719: break; richk@6719: richk@6719: default: grfmsg(1, "SkipIf: Unsupported test %d. Ignoring", condtype); return; peter1138@5234: } celestar@357: } celestar@357: pasky@1607: if (!result) { richk@6719: grfmsg(2, "SkipIf: Not skipping sprites, test was false"); celestar@357: return; darkvater@359: } darkvater@359: peter1138@6607: uint8 numsprites = grf_load_byte(&buf); Darkvater@3561: Darkvater@3561: /* numsprites can be a GOTO label if it has been defined in the GRF Darkvater@3561: * file. The jump will always be the first matching label that follows Darkvater@3561: * the current nfo_line. If no matching label is found, the first matching Darkvater@3561: * label in the file is used. */ peter1138@6607: GRFLabel *choice = NULL; peter1138@6607: for (GRFLabel *label = _cur_grffile->label; label != NULL; label = label->next) { Darkvater@3561: if (label->label != numsprites) continue; Darkvater@3561: Darkvater@3561: /* Remember a goto before the current line */ Darkvater@3561: if (choice == NULL) choice = label; Darkvater@3561: /* If we find a label here, this is definitely good */ Darkvater@3561: if (label->nfo_line > _nfo_line) { Darkvater@3561: choice = label; Darkvater@3561: break; Darkvater@3561: } Darkvater@3561: } Darkvater@3561: Darkvater@3561: if (choice != NULL) { richk@6719: grfmsg(2, "SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line); Darkvater@3561: FioSeekTo(choice->pos, SEEK_SET); Darkvater@3561: _nfo_line = choice->nfo_line; Darkvater@3561: return; Darkvater@3561: } Darkvater@3561: richk@6719: grfmsg(2, "SkipIf: Skipping %d sprites, test was true", numsprites); celestar@357: _skip_sprites = numsprites; celestar@357: if (_skip_sprites == 0) { celestar@357: /* Zero means there are no sprites to skip, so celestar@357: * we use -1 to indicate that all further celestar@357: * sprites should be skipped. */ celestar@357: _skip_sprites = -1; maedhros@6422: maedhros@6422: /* If an action 8 hasn't been encountered yet, disable the grf. */ peter1138@6699: if (_cur_stage != GLS_RESERVE && _cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED; truelight@0: } truelight@0: } truelight@0: peter1138@5317: peter1138@5753: /* Action 0x08 (GLS_FILESCAN) */ peter1138@5753: static void ScanInfo(byte *buf, int len) peter1138@5228: { peter1138@6607: if (!check_length(len, 8, "Info")) return; peter1138@6607: buf++; peter1138@6607: grf_load_byte(&buf); peter1138@6607: uint32 grfid = grf_load_dword(&buf); peter1138@5228: peter1138@5228: _cur_grfconfig->grfid = grfid; peter1138@5317: peter1138@5329: /* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */ peter1138@5329: if (GB(grfid, 24, 8) == 0xFF) SETBIT(_cur_grfconfig->flags, GCF_SYSTEM); peter1138@5329: peter1138@5317: len -= 6; peter1138@6607: const char *name = grf_load_string(&buf, len); rubidium@6512: _cur_grfconfig->name = TranslateTTDPatchCodes(name); rubidium@6512: rubidium@6512: len -= strlen(name) + 1; rubidium@6512: if (len > 0) { peter1138@6607: const char *info = grf_load_string(&buf, len); rubidium@6512: _cur_grfconfig->info = TranslateTTDPatchCodes(info); peter1138@5317: } peter1138@5329: peter1138@5329: /* GLS_INFOSCAN only looks for the action 8, so we can skip the rest of the file */ peter1138@5228: _skip_sprites = -1; peter1138@5228: } peter1138@5228: peter1138@3640: /* Action 0x08 */ truelight@0: static void GRFInfo(byte *buf, int len) truelight@0: { truelight@0: /* <08> truelight@0: * truelight@0: * B version newgrf version, currently 06 truelight@0: * 4*B grf-id globally unique ID of this .grf file truelight@0: * S name name of this .grf set truelight@0: * S info string describing the set, and e.g. author and copyright */ peter1138@6607: peter1138@6607: if (!check_length(len, 8, "GRFInfo")) return; peter1138@6607: buf++; peter1138@6607: uint8 version = grf_load_byte(&buf); peter1138@6607: uint32 grfid = grf_load_dword(&buf); peter1138@6607: const char *name = grf_load_string(&buf, len - 6); darkvater@366: darkvater@366: _cur_grffile->grfid = grfid; peter1138@3640: _cur_grffile->grf_version = version; maedhros@6555: _cur_grfconfig->status = _cur_stage < GLS_ACTIVATION ? GCS_INITIALISED : GCS_ACTIVATED; darkvater@366: Darkvater@3711: /* Do swap the GRFID for displaying purposes since people expect that */ richk@6719: DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name); truelight@0: } truelight@0: peter1138@3640: /* Action 0x0A */ truelight@0: static void SpriteReplace(byte *buf, int len) truelight@0: { truelight@0: /* <0A> [ ...] truelight@0: * : truelight@0: * truelight@0: * B num-sets How many sets of sprites to replace. truelight@0: * Each set: truelight@0: * B num-sprites How many sprites are in this set truelight@0: * W first-sprite First sprite number to replace */ darkvater@361: belugas@6674: buf++; // skip action byte peter1138@6607: uint8 num_sets = grf_load_byte(&buf); peter1138@6607: peter1138@6607: for (uint i = 0; i < num_sets; i++) { tron@2342: uint8 num_sprites = grf_load_byte(&buf); tron@2342: uint16 first_sprite = grf_load_word(&buf); darkvater@398: Darkvater@5568: grfmsg(2, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d", tron@2342: i, num_sprites, first_sprite tron@2342: ); darkvater@361: peter1138@6607: for (uint j = 0; j < num_sprites; j++) { tron@2342: LoadNextSprite(first_sprite + j, _file_index); // XXX peter1138@3557: _nfo_line++; darkvater@361: } darkvater@361: } truelight@0: } truelight@0: richk@6719: /* Action 0x0A (SKIP) */ richk@6719: static void SkipActA(byte *buf, int len) richk@6719: { richk@6719: buf++; richk@6719: uint8 num_sets = grf_load_byte(&buf); richk@6719: richk@6719: for (uint i = 0; i < num_sets; i++) { richk@6719: /* Skip the sprites this replaces */ richk@6719: _skip_sprites += grf_load_byte(&buf); richk@6719: /* But ignore where they go */ richk@6719: grf_load_word(&buf); richk@6719: } richk@6719: richk@6719: grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites); richk@6719: } richk@6719: peter1138@3715: /* Action 0x0B */ maedhros@6465: static void GRFLoadError(byte *buf, int len) truelight@0: { truelight@0: /* <0B> [ 00] [] 00 [] truelight@0: * truelight@0: * B severity 00: notice, contine loading grf file truelight@0: * 01: warning, continue loading grf file truelight@0: * 02: error, but continue loading grf file, and attempt truelight@0: * loading grf again when loading or starting next game truelight@0: * 03: error, abort loading and prevent loading again in truelight@0: * the future (only when restarting the patch) truelight@0: * B language-id see action 4, use 1F for built-in error messages truelight@0: * B message-id message to show, see below truelight@0: * S message for custom messages (message-id FF), text of the message truelight@0: * not present for built-in messages. truelight@0: * V data additional data for built-in (or custom) messages maedhros@6465: * B parnum parameter numbers to be shown in the message (maximum of 2) */ maedhros@6465: maedhros@6465: static const StringID msgstr[] = { maedhros@6465: STR_NEWGRF_ERROR_VERSION_NUMBER, maedhros@6465: STR_NEWGRF_ERROR_DOS_OR_WINDOWS, maedhros@6465: STR_NEWGRF_ERROR_UNSET_SWITCH, maedhros@6465: STR_NEWGRF_ERROR_INVALID_PARAMETER, maedhros@6465: STR_NEWGRF_ERROR_LOAD_BEFORE, maedhros@6465: STR_NEWGRF_ERROR_LOAD_AFTER truelight@0: }; Darkvater@5567: maedhros@6465: static const StringID sevstr[] = { maedhros@6465: STR_NEWGRF_ERROR_MSG_INFO, maedhros@6465: STR_NEWGRF_ERROR_MSG_WARNING, maedhros@6465: STR_NEWGRF_ERROR_MSG_ERROR, maedhros@6465: STR_NEWGRF_ERROR_MSG_FATAL Darkvater@5567: }; truelight@0: maedhros@6465: /* AddGRFString expects the string to be referred to by an id in the newgrf maedhros@6465: * file. Errors messages are never referred to however, so invent ids that maedhros@6465: * are unlikely to be reached in a newgrf file so they don't overwrite maedhros@6465: * anything else. */ maedhros@6465: enum { maedhros@6465: MESSAGE_STRING_ID = MAX_UVALUE(StringID) - 1, maedhros@6465: MESSAGE_DATA_ID = MAX_UVALUE(StringID) maedhros@6465: }; maedhros@6465: maedhros@6465: if (!check_length(len, 6, "GRFLoadError")) return; maedhros@6465: maedhros@6465: /* For now we can only show one message per newgrf file. */ maedhros@6465: if (_cur_grfconfig->error != NULL) return; maedhros@6416: belugas@6674: buf++; // Skip the action byte. maedhros@6421: byte severity = grf_load_byte(&buf); maedhros@6465: byte lang = grf_load_byte(&buf); maedhros@6421: byte message_id = grf_load_byte(&buf); maedhros@6421: len -= 4; maedhros@6421: maedhros@6421: /* Skip the error until the activation stage unless bit 7 of the severity maedhros@6421: * is set. */ maedhros@6421: if (!HASBIT(severity, 7) && _cur_stage < GLS_ACTIVATION) { richk@6719: grfmsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage 1"); miham@441: return; peter1138@3588: } maedhros@6421: CLRBIT(severity, 7); maedhros@6421: maedhros@6421: if (severity >= lengthof(sevstr)) { maedhros@6465: grfmsg(7, "GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity); maedhros@6421: severity = 2; maedhros@6421: } else if (severity == 3) { maedhros@6421: /* This is a fatal error, so make sure the GRF is deactivated and no maedhros@6421: * more of it gets loaded. */ maedhros@6555: _cur_grfconfig->status = GCS_DISABLED; maedhros@6421: maedhros@6421: _skip_sprites = -1; maedhros@6421: } maedhros@6421: maedhros@6421: if (message_id >= lengthof(msgstr) && message_id != 0xFF) { maedhros@6465: grfmsg(7, "GRFLoadError: Invalid message id."); maedhros@6421: return; maedhros@6421: } maedhros@6421: maedhros@6421: if (len <= 1) { maedhros@6465: grfmsg(7, "GRFLoadError: No message data supplied."); maedhros@6421: return; maedhros@6421: } maedhros@6421: maedhros@6465: bool new_scheme = _cur_grffile->grf_version >= 7; maedhros@6465: GRFError *error = CallocT(1); maedhros@6465: maedhros@6465: error->severity = sevstr[severity]; maedhros@6465: maedhros@6465: if (message_id == 0xFF) { maedhros@6465: /* This is a custom error message. */ maedhros@6465: const char *message = grf_load_string(&buf, len); maedhros@6465: len -= (strlen(message) + 1); maedhros@6465: maedhros@6465: error->message = AddGRFString(_cur_grffile->grfid, MESSAGE_STRING_ID, lang, new_scheme, message, STR_UNDEFINED); maedhros@6465: } else { maedhros@6465: error->message = msgstr[message_id]; maedhros@6429: } maedhros@6429: maedhros@6465: if (len > 0) { maedhros@6465: const char *data = grf_load_string(&buf, len); maedhros@6465: len -= (strlen(data) + 1); maedhros@6465: maedhros@6465: error->data = AddGRFString(_cur_grffile->grfid, MESSAGE_DATA_ID, lang, new_scheme, data, STR_UNDEFINED); maedhros@6465: } maedhros@6465: maedhros@6465: /* Only two parameter numbers can be used in the string. */ maedhros@6465: uint i = 0; maedhros@6465: for (; i < 2 && len > 0; i++) { maedhros@6465: error->param_number[i] = grf_load_byte(&buf); maedhros@6465: len--; maedhros@6465: } maedhros@6465: error->num_params = i; maedhros@6465: maedhros@6465: _cur_grfconfig->error = error; truelight@0: } truelight@0: peter1138@3715: /* Action 0x0C */ truelight@0: static void GRFComment(byte *buf, int len) truelight@0: { truelight@0: /* <0C> [] truelight@0: * truelight@0: * V ignored Anything following the 0C is ignored */ Darkvater@3561: Darkvater@3561: if (len == 1) return; Darkvater@3561: tron@6433: int text_len = len - 1; tron@6433: const char *text = (const char*)(buf + 1); tron@6433: grfmsg(2, "GRFComment: %.*s", text_len, text); truelight@0: } truelight@0: peter1138@5776: /* Action 0x0D (GLS_SAFETYSCAN) */ peter1138@5776: static void SafeParamSet(byte *buf, int len) peter1138@5776: { peter1138@5841: if (!check_length(len, 5, "SafeParamSet")) return; peter1138@5776: buf++; peter1138@6607: uint8 target = grf_load_byte(&buf); peter1138@5776: peter1138@5776: /* Only writing GRF parameters is considered safe */ peter1138@5776: if (target < 0x80) return; peter1138@5776: peter1138@5776: /* GRM could be unsafe, but as here it can only happen after other GRFs peter1138@5776: * are loaded, it should be okay. If the GRF tried to use the slots it peter1138@5776: * reserved, it would be marked unsafe anyway. GRM for (e.g. bridge) peter1138@5776: * sprites is considered safe. */ peter1138@5776: peter1138@5776: SETBIT(_cur_grfconfig->flags, GCF_UNSAFE); peter1138@5776: peter1138@5776: /* Skip remainder of GRF */ peter1138@5776: _skip_sprites = -1; peter1138@5776: } peter1138@5776: richk@6719: richk@6719: static uint32 GetPatchVariable(uint8 param) richk@6719: { richk@6719: switch (param) { richk@6719: /* start year - 1920 */ richk@6719: case 0x0B: return max(_patches.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR; richk@6719: /* freight trains weight factor */ richk@6719: case 0x0E: return _patches.freight_trains; richk@6719: /* empty wagon speed increase */ richk@6719: case 0x0F: return 0; richk@6719: /* plane speed factor */ richk@6719: case 0x10: return 4; richk@6719: /* 2CC colormap base sprite */ richk@6719: case 0x11: return SPR_2CCMAP_BASE; richk@6719: richk@6719: default: richk@6719: grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param); richk@6719: return 0; richk@6719: } richk@6719: } richk@6719: richk@6719: richk@6719: static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, const char *type) richk@6719: { richk@6719: uint start = 0; richk@6719: uint size = 0; richk@6719: richk@6719: if (op == 6) { richk@6719: /* Return GRFID of set that reserved ID */ richk@6719: return grm[_cur_grffile->param[target]]; richk@6719: } richk@6719: richk@6719: /* With an operation of 2 or 3, we want to reserve a specific block of IDs */ richk@6719: if (op == 2 || op == 3) start = _cur_grffile->param[target]; richk@6719: richk@6719: for (uint i = start; i < num_ids; i++) { richk@6719: if (grm[i] == 0) { richk@6719: size++; richk@6719: } else { richk@6719: if (op == 2 || op == 3) break; richk@6719: start = i + 1; richk@6719: size = 0; richk@6719: } richk@6719: richk@6719: if (size == count) break; richk@6719: } richk@6719: richk@6719: if (size == count) { richk@6719: /* Got the slot... */ richk@6719: if (op == 0 || op == 3) { richk@6719: grfmsg(2, "ParamSet: GRM: Reserving %d %s at %d", count, type, start); richk@6719: for (uint i = 0; i < count; i++) grm[start + i] = _cur_grffile->grfid; richk@6719: } richk@6719: return start; richk@6719: } richk@6719: richk@6719: /* Unable to allocate */ richk@6719: if (op != 4 && op != 5) { richk@6719: /* Deactivate GRF */ richk@6719: grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type); richk@6719: _cur_grfconfig->status = GCS_DISABLED; richk@6719: _skip_sprites = -1; richk@6719: return UINT_MAX; richk@6719: } richk@6719: richk@6719: grfmsg(1, "ParamSet: GRM: Unable to allocate %d %s", count, type); richk@6719: return UINT_MAX; richk@6719: } richk@6719: richk@6719: celestar@356: /* Action 0x0D */ truelight@0: static void ParamSet(byte *buf, int len) truelight@0: { truelight@0: /* <0D> [] truelight@0: * truelight@0: * B target parameter number where result is stored truelight@0: * B operation operation to perform, see below truelight@0: * B source1 first source operand truelight@0: * B source2 second source operand truelight@0: * D data data to use in the calculation, not necessary truelight@0: * if both source1 and source2 refer to actual parameters truelight@0: * truelight@0: * Operations truelight@0: * 00 Set parameter equal to source1 truelight@0: * 01 Addition, source1 + source2 truelight@0: * 02 Subtraction, source1 - source2 truelight@0: * 03 Unsigned multiplication, source1 * source2 (both unsigned) truelight@0: * 04 Signed multiplication, source1 * source2 (both signed) truelight@0: * 05 Unsigned bit shift, source1 by source2 (source2 taken to be a truelight@0: * signed quantity; left shift if positive and right shift if truelight@0: * negative, source1 is unsigned) truelight@0: * 06 Signed bit shift, source1 by source2 truelight@0: * (source2 like in 05, and source1 as well) truelight@0: */ darkvater@362: peter1138@5841: if (!check_length(len, 5, "ParamSet")) return; bjarni@418: buf++; peter1138@6607: uint8 target = grf_load_byte(&buf); peter1138@6607: uint8 oper = grf_load_byte(&buf); peter1138@6607: uint32 src1 = grf_load_byte(&buf); peter1138@6607: uint32 src2 = grf_load_byte(&buf); peter1138@6607: peter1138@6607: uint32 data = 0; tron@2345: if (len >= 8) data = grf_load_dword(&buf); darkvater@398: darkvater@362: /* You can add 80 to the operation to make it apply only if the target darkvater@362: * is not defined yet. In this respect, a parameter is taken to be darkvater@362: * defined if any of the following applies: darkvater@362: * - it has been set to any value in the newgrf(w).cfg parameter list darkvater@362: * - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by darkvater@362: * an earlier action D */ peter1138@6607: if (HASBIT(oper, 7)) { peter1138@3807: if (target < 0x80 && target < _cur_grffile->param_end) { richk@6719: grfmsg(7, "ParamSet: Param %u already defined, skipping", target); darkvater@362: return; peter1138@3807: } peter1138@3807: peter1138@6607: oper = GB(oper, 0, 7); darkvater@362: } darkvater@362: peter1138@3808: if (src2 == 0xFE) { peter1138@3808: if (GB(data, 0, 8) == 0xFF) { peter1138@3808: if (data == 0x0000FFFF) { peter1138@3808: /* Patch variables */ richk@6719: src1 = GetPatchVariable(src1); peter1138@3808: } else { peter1138@3808: /* GRF Resource Management */ peter1138@5225: if (_cur_stage != GLS_ACTIVATION) { peter1138@4961: /* Ignore GRM during initialization */ peter1138@4961: src1 = 0; peter1138@4961: } else { peter1138@4961: uint8 op = src1; peter1138@4961: uint8 feature = GB(data, 8, 8); peter1138@4961: uint16 count = GB(data, 16, 16); peter1138@4961: peter1138@4961: switch (feature) { belugas@6674: case 0x00: // Trains belugas@6674: case 0x01: // Road Vehicles belugas@6674: case 0x02: // Ships belugas@6674: case 0x03: // Aircraft richk@6719: src1 = PerformGRM(&_grm_engines[_vehshifts[feature]], _vehcounts[feature], count, op, target, "vehicles"); richk@6719: if (_skip_sprites == -1) return; peter1138@4961: break; peter1138@4961: belugas@6674: case 0x08: // General sprites peter1138@4961: switch (op) { peter1138@4961: case 0: peter1138@6140: /* Check if the allocated sprites will fit below the original sprite limit */ peter1138@6140: if (_cur_spriteid + count >= 16384) { richk@6719: grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count); maedhros@6555: _cur_grfconfig->status = GCS_DISABLED; peter1138@6140: peter1138@6140: _skip_sprites = -1; peter1138@6140: return; peter1138@6140: } peter1138@6140: peter1138@4961: /* 'Reserve' space at the current sprite ID */ peter1138@4961: src1 = _cur_spriteid; peter1138@4961: _cur_spriteid += count; peter1138@4961: break; peter1138@4961: peter1138@4961: case 1: peter1138@4961: src1 = _cur_spriteid; peter1138@4961: break; peter1138@4961: peter1138@4961: default: richk@6719: grfmsg(1, "ParamSet: GRM: Unsupported operation %d for general sprites", op); peter1138@4961: return; peter1138@4961: } peter1138@4961: break; peter1138@4961: richk@6719: case 0x0B: // Cargo richk@6719: src1 = PerformGRM(_grm_cargos, NUM_CARGO, count, op, target, "cargos"); richk@6719: if (_skip_sprites == -1) return; richk@6719: break; richk@6719: richk@6719: default: grfmsg(1, "ParamSet: GRM: Unsupported feature 0x%X", feature); return; peter1138@4961: } peter1138@4961: } peter1138@3808: } peter1138@3808: } else { peter1138@3808: /* Read another GRF File's parameter */ peter1138@3808: const GRFFile *file = GetFileByGRFID(data); peter1138@3808: if (file == NULL || src1 >= file->param_end) { peter1138@3808: src1 = 0; peter1138@3808: } else { peter1138@3808: src1 = file->param[src1]; peter1138@3808: } peter1138@3808: } darkvater@362: } else { peter1138@3808: /* The source1 and source2 operands refer to the grf parameter number peter1138@3808: * like in action 6 and 7. In addition, they can refer to the special peter1138@3808: * variables available in action 7, or they can be FF to use the value peter1138@3808: * of . If referring to parameters that are undefined, a value peter1138@3808: * of 0 is used instead. */ peter1138@3811: src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL); peter1138@3811: src2 = (src2 == 0xFF) ? data : GetParamVal(src2, NULL); darkvater@362: } darkvater@362: darkvater@362: /* TODO: You can access the parameters of another GRF file by using darkvater@362: * source2=FE, source1=the other GRF's parameter number and data=GRF darkvater@362: * ID. This is only valid with operation 00 (set). If the GRF ID darkvater@362: * cannot be found, a value of 0 is used for the parameter value darkvater@362: * instead. */ darkvater@362: peter1138@6607: uint32 res; darkvater@362: switch (oper) { darkvater@362: case 0x00: tron@2345: res = src1; darkvater@362: break; tron@2345: tron@2345: case 0x01: tron@2345: res = src1 + src2; darkvater@362: break; tron@2345: tron@2345: case 0x02: tron@2345: res = src1 - src2; tron@2345: break; tron@2345: darkvater@362: case 0x03: tron@2345: res = src1 * src2; darkvater@362: break; tron@2345: darkvater@362: case 0x04: tron@2345: res = (int32)src1 * (int32)src2; darkvater@362: break; tron@2345: darkvater@362: case 0x05: tron@4077: if ((int32)src2 < 0) { tron@2345: res = src1 >> -(int32)src2; tron@4077: } else { tron@2345: res = src1 << src2; tron@4077: } darkvater@362: break; tron@2345: darkvater@362: case 0x06: tron@4077: if ((int32)src2 < 0) { tron@2345: res = (int32)src1 >> -(int32)src2; tron@4077: } else { tron@2345: res = (int32)src1 << src2; tron@4077: } darkvater@362: break; tron@2345: belugas@6674: case 0x07: // Bitwise AND peter1138@2442: res = src1 & src2; peter1138@2442: break; peter1138@2442: belugas@6674: case 0x08: // Bitwise OR peter1138@2442: res = src1 | src2; peter1138@2442: break; peter1138@2442: belugas@6674: case 0x09: // Unsigned division peter1138@2442: if (src2 == 0) { peter1138@2442: res = src1; peter1138@2442: } else { peter1138@2442: res = src1 / src2; peter1138@2442: } peter1138@2442: break; peter1138@2442: belugas@6674: case 0x0A: // Signed divison peter1138@2442: if (src2 == 0) { peter1138@2442: res = src1; peter1138@2442: } else { peter1138@2442: res = (int32)src1 / (int32)src2; peter1138@2442: } peter1138@2442: break; peter1138@2442: belugas@6674: case 0x0B: // Unsigned modulo peter1138@2442: if (src2 == 0) { peter1138@2442: res = src1; peter1138@2442: } else { peter1138@2442: res = src1 % src2; peter1138@2442: } peter1138@2442: break; peter1138@2442: belugas@6674: case 0x0C: // Signed modulo peter1138@2442: if (src2 == 0) { peter1138@2442: res = src1; peter1138@2442: } else { peter1138@2442: res = (int32)src1 % (int32)src2; peter1138@2442: } peter1138@2442: break; peter1138@2442: Darkvater@5568: default: grfmsg(0, "ParamSet: Unknown operation %d, skipping", oper); return; tron@2345: } tron@2345: tron@2345: switch (target) { tron@2345: case 0x8E: // Y-Offset for train sprites tron@2345: _traininfo_vehicle_pitch = res; tron@2345: break; tron@2345: belugas@6674: /* @todo implement */ tron@2345: case 0x8F: // Rail track type cost factors tron@2345: case 0x93: // Tile refresh offset to left tron@2345: case 0x94: // Tile refresh offset to right tron@2345: case 0x95: // Tile refresh offset upwards tron@2345: case 0x96: // Tile refresh offset downwards tron@2345: case 0x97: // Snow line height tron@2345: case 0x99: // Global ID offset Darkvater@5568: grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target); tron@2345: break; tron@2345: belugas@6674: case 0x9E: // Miscellaneous GRF features peter1138@3814: _misc_grf_features = res; peter1138@3845: /* Set train list engine width */ richk@6719: _traininfo_vehicle_width = HasGrfMiscBit(GMB_TRAIN_WIDTH_32_PIXELS) ? 32 : 29; peter1138@3814: break; peter1138@3814: tron@2345: default: tron@2345: if (target < 0x80) { tron@2345: _cur_grffile->param[target] = res; tron@2345: if (target + 1U > _cur_grffile->param_end) _cur_grffile->param_end = target + 1; tron@2345: } else { Darkvater@5568: grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target); tron@2345: } tron@2345: break; darkvater@362: } truelight@0: } truelight@0: peter1138@5753: /* Action 0x0E (GLS_SAFETYSCAN) */ peter1138@5753: static void SafeGRFInhibit(byte *buf, int len) peter1138@5753: { peter1138@5753: /* <0E> peter1138@5753: * peter1138@5753: * B num Number of GRFIDs that follow peter1138@5753: * D grfids GRFIDs of the files to deactivate */ peter1138@5753: peter1138@6607: if (!check_length(len, 2, "GRFInhibit")) return; peter1138@6607: buf++; peter1138@6607: uint8 num = grf_load_byte(&buf); peter1138@6607: if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return; peter1138@6607: peter1138@6607: for (uint i = 0; i < num; i++) { peter1138@5753: uint32 grfid = grf_load_dword(&buf); peter1138@5753: peter1138@5753: /* GRF is unsafe it if tries to deactivate other GRFs */ peter1138@5753: if (grfid != _cur_grfconfig->grfid) { peter1138@5753: SETBIT(_cur_grfconfig->flags, GCF_UNSAFE); peter1138@5753: peter1138@5753: /* Skip remainder of GRF */ peter1138@5753: _skip_sprites = -1; peter1138@5753: peter1138@5753: return; peter1138@5753: } peter1138@5753: } peter1138@5753: } peter1138@5753: peter1138@3715: /* Action 0x0E */ truelight@0: static void GRFInhibit(byte *buf, int len) truelight@0: { truelight@0: /* <0E> truelight@0: * truelight@0: * B num Number of GRFIDs that follow truelight@0: * D grfids GRFIDs of the files to deactivate */ darkvater@367: peter1138@6607: if (!check_length(len, 2, "GRFInhibit")) return; peter1138@6607: buf++; peter1138@6607: uint8 num = grf_load_byte(&buf); peter1138@6607: if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return; peter1138@6607: peter1138@6607: for (uint i = 0; i < num; i++) { darkvater@367: uint32 grfid = grf_load_dword(&buf); peter1138@5333: GRFConfig *file = GetGRFConfig(grfid); darkvater@367: darkvater@367: /* Unset activation flag */ peter1138@5557: if (file != NULL && file != _cur_grfconfig) { Darkvater@5568: grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename); maedhros@6555: file->status = GCS_DISABLED; darkvater@367: } darkvater@367: } truelight@0: } truelight@0: peter1138@3715: /* Action 0x10 */ Darkvater@3561: static void DefineGotoLabel(byte *buf, int len) Darkvater@3561: { Darkvater@3561: /* <10>