2005-07-24 14:12:37 +00:00
/* $Id$ */
2008-05-06 15:11:33 +00:00
/** @file newgrf.cpp Base of all NewGRF support. */
2007-03-21 03:06:21 +00:00
2004-08-09 17:04:08 +00:00
# include "stdafx.h"
# include <stdarg.h>
2005-06-02 19:30:21 +00:00
# include "openttd.h"
2005-02-05 15:58:59 +00:00
# include "debug.h"
2004-08-09 17:04:08 +00:00
# include "fileio.h"
2008-03-31 00:17:39 +00:00
# include "engine_func.h"
2008-04-29 21:31:29 +00:00
# include "engine_base.h"
2005-08-15 11:39:13 +00:00
# include "spritecache.h"
2004-11-14 16:42:08 +00:00
# include "sprite.h"
2004-11-17 18:49:55 +00:00
# include "newgrf.h"
2005-07-21 22:15:02 +00:00
# include "variables.h"
2005-10-01 17:38:48 +00:00
# include "bridge.h"
2007-03-19 11:27:30 +00:00
# include "town.h"
2006-02-03 12:55:21 +00:00
# include "newgrf_engine.h"
2006-04-21 03:00:20 +00:00
# include "newgrf_text.h"
2006-11-16 22:05:33 +00:00
# include "fontcache.h"
2006-08-25 00:41:10 +00:00
# include "currency.h"
2007-03-20 13:47:00 +00:00
# include "landscape.h"
2006-12-04 08:30:04 +00:00
# include "newgrf_config.h"
2007-03-19 11:27:30 +00:00
# include "newgrf_house.h"
2006-09-27 18:17:01 +00:00
# include "newgrf_sound.h"
2006-04-20 20:51:57 +00:00
# include "newgrf_spritegroup.h"
2008-03-31 06:42:26 +00:00
# include "newgrf_station.h"
2007-02-20 22:09:21 +00:00
# include "cargotype.h"
2007-04-26 20:20:12 +00:00
# include "industry.h"
2007-05-06 18:14:33 +00:00
# include "newgrf_canal.h"
2007-05-15 21:36:58 +00:00
# include "newgrf_commons.h"
2007-06-18 23:00:55 +00:00
# include "newgrf_townname.h"
2007-07-11 22:57:47 +00:00
# include "newgrf_industries.h"
2007-10-20 21:39:50 +00:00
# include "gfxinit.h"
2008-05-04 21:53:36 +00:00
# include "rev.h"
2007-10-29 23:02:31 +00:00
# include "fios.h"
2007-12-18 20:58:12 +00:00
# include "rail.h"
2007-12-21 19:49:27 +00:00
# include "strings_func.h"
2007-12-23 10:56:02 +00:00
# include "gfx_func.h"
2007-12-26 13:50:40 +00:00
# include "date_func.h"
2007-12-27 13:35:39 +00:00
# include "vehicle_func.h"
2007-12-29 09:24:26 +00:00
# include "sound_func.h"
2008-01-07 14:23:25 +00:00
# include "string_func.h"
2008-01-09 21:05:03 +00:00
# include "road_func.h"
2008-01-12 14:10:35 +00:00
# include "player_base.h"
2008-01-13 14:37:30 +00:00
# include "settings_type.h"
2008-06-19 10:20:45 +00:00
# include "network/network.h"
2008-01-23 17:08:35 +00:00
# include "map_func.h"
2008-04-29 21:31:29 +00:00
# include <map>
2006-04-20 20:51:57 +00:00
2008-01-13 01:21:35 +00:00
# include "table/strings.h"
# include "table/sprites.h"
# include "table/town_land.h"
# include "table/build_industry.h"
# include "table/landscape_sprite.h"
2004-08-09 17:04:08 +00:00
/* TTDPatch extended GRF format codec
* ( c ) Petr Baudis 2004 ( GPL ' d )
2004-11-12 15:15:56 +00:00
* Changes by Florian octo Forster are ( c ) by the OpenTTD development team .
*
2004-08-09 17:04:08 +00:00
* Contains portions of documentation by TTDPatch team .
* Thanks especially to Josef Drexler for the documentation as well as a lot
* of help at # tycoon . Also thanks to Michael Blunck for is GRF files which
* served as subject to the initial testing of this codec . */
2004-11-17 20:08:13 +00:00
2005-08-15 11:39:13 +00:00
static int _skip_sprites ; // XXX
static uint _file_index ; // XXX
2004-08-09 17:04:08 +00:00
2005-08-14 18:10:18 +00:00
static GRFFile * _cur_grffile ;
2005-03-10 07:01:43 +00:00
GRFFile * _first_grffile ;
2006-05-01 16:52:43 +00:00
static SpriteID _cur_spriteid ;
2006-12-03 23:46:54 +00:00
static GrfLoadingStage _cur_stage ;
2006-04-15 21:27:59 +00:00
static uint32 _nfo_line ;
2004-08-09 17:04:08 +00:00
2006-12-04 08:30:04 +00:00
static GRFConfig * _cur_grfconfig ;
2006-05-11 12:41:02 +00:00
/* Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E */
static byte _misc_grf_features = 0 ;
2004-11-12 19:03:37 +00:00
/* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
static uint32 _ttdpatch_flags [ 8 ] ;
2007-05-31 19:13:41 +00:00
/* Indicates which are the newgrf features currently loaded ingame */
2007-06-15 23:55:52 +00:00
GRFLoadedFeatures _loaded_newgrf_features ;
2004-11-12 19:03:37 +00:00
2007-03-07 12:11:48 +00:00
enum GrfDataType {
2006-09-27 18:17:01 +00:00
GDT_SOUND ,
2007-03-07 12:11:48 +00:00
} ;
2006-09-27 18:17:01 +00:00
static byte _grf_data_blocks ;
static GrfDataType _grf_data_type ;
2008-05-08 13:20:54 +00:00
typedef void ( * SpecialSpriteHandler ) ( byte * buf , size_t len ) ;
2004-08-09 17:04:08 +00:00
2006-05-06 22:20:16 +00:00
enum {
MAX_STATIONS = 256 ,
} ;
2008-04-22 18:20:41 +00:00
/* Temporary data used when loading only */
struct GRFTempEngineData {
uint16 cargo_allowed ;
uint16 cargo_disallowed ;
} ;
static GRFTempEngineData * _gted ;
2004-08-09 17:04:08 +00:00
2008-04-29 21:31:29 +00:00
/* Contains the GRF ID of the owner of a vehicle if it has been reserved.
* GRM for vehicles is only used if dynamic engine allocation is disabled ,
* so 256 is the number of original engines . */
static uint32 _grm_engines [ 256 ] ;
2006-10-27 13:15:21 +00:00
2007-06-02 08:56:21 +00:00
/* Contains the GRF ID of the owner of a cargo if it has been reserved */
2008-03-05 09:37:43 +00:00
static uint32 _grm_cargos [ NUM_CARGO * 2 ] ;
2007-06-02 08:56:21 +00:00
2008-05-06 17:24:27 +00:00
struct GRFLocation {
2008-05-05 19:02:10 +00:00
uint32 grfid ;
uint32 nfoline ;
2008-05-06 17:24:27 +00:00
GRFLocation ( uint32 grfid , uint32 nfoline ) : grfid ( grfid ) , nfoline ( nfoline ) { }
2008-05-05 19:02:10 +00:00
2008-05-06 17:24:27 +00:00
bool operator < ( const GRFLocation & other ) const
2008-05-05 19:02:10 +00:00
{
return this - > grfid < other . grfid | | ( this - > grfid = = other . grfid & & this - > nfoline < other . nfoline ) ;
}
2008-08-19 09:08:45 +00:00
bool operator = = ( const GRFLocation & other ) const
{
return this - > grfid = = other . grfid & & this - > nfoline = = other . nfoline ;
}
2008-05-05 19:02:10 +00:00
} ;
2008-05-06 17:24:27 +00:00
static std : : map < GRFLocation , SpriteID > _grm_sprites ;
2008-08-19 09:08:45 +00:00
typedef std : : map < GRFLocation , byte * > GRFLineToSpriteOverride ;
GRFLineToSpriteOverride _grf_line_to_action6_sprite_override ;
2008-05-05 19:02:10 +00:00
2006-12-26 17:36:18 +00:00
/** DEBUG() function dedicated to newGRF debugging messages
* Function is essentialy the same as DEBUG ( grf , severity , . . . ) with the
* addition of file : line information when parsing grf files .
* NOTE : for the above reason ( s ) grfmsg ( ) should ONLY be used for
* loading / parsing grf files , not for runtime debug messages as there
* is no file information available during that time .
* @ param severity debugging severity level , see debug . h
2007-04-17 20:23:13 +00:00
* @ param str message in printf ( ) format */
2006-12-26 17:36:18 +00:00
void CDECL grfmsg ( int severity , const char * str , . . . )
2004-08-09 17:04:08 +00:00
{
2004-08-16 14:48:35 +00:00
char buf [ 1024 ] ;
2004-08-09 17:04:08 +00:00
va_list va ;
va_start ( va , str ) ;
2005-03-10 07:01:43 +00:00
vsnprintf ( buf , sizeof ( buf ) , str , va ) ;
2004-08-09 17:04:08 +00:00
va_end ( va ) ;
2004-11-13 12:21:32 +00:00
2006-12-26 17:36:18 +00:00
DEBUG ( grf , severity , " [%s:%d] %s " , _cur_grfconfig - > filename , _nfo_line , buf ) ;
2004-08-09 17:04:08 +00:00
}
2008-05-08 13:20:54 +00:00
static inline bool check_length ( size_t real , size_t wanted , const char * str )
2006-12-26 17:22:47 +00:00
{
2007-01-10 19:20:25 +00:00
if ( real > = wanted ) return true ;
2006-12-26 17:22:47 +00:00
grfmsg ( 0 , " %s: Invalid pseudo sprite length %d (expected %d)! " , str , real , wanted ) ;
2007-01-10 19:20:25 +00:00
return false ;
2006-12-26 17:22:47 +00:00
}
2004-11-12 15:36:49 +00:00
2004-11-24 13:19:48 +00:00
static inline byte grf_load_byte ( byte * * buf )
2004-11-12 23:26:02 +00:00
{
2004-08-09 17:04:08 +00:00
return * ( * buf ) + + ;
}
static uint16 grf_load_word ( byte * * buf )
{
2006-05-01 21:45:35 +00:00
uint16 val = grf_load_byte ( buf ) ;
return val | ( grf_load_byte ( buf ) < < 8 ) ;
2004-08-09 17:04:08 +00:00
}
2005-08-15 22:48:33 +00:00
static uint16 grf_load_extended ( byte * * buf )
{
uint16 val ;
val = grf_load_byte ( buf ) ;
if ( val = = 0xFF ) val = grf_load_word ( buf ) ;
return val ;
}
2005-08-11 12:51:59 +00:00
static uint32 grf_load_dword ( byte * * buf )
2004-08-09 17:04:08 +00:00
{
2006-05-01 21:45:35 +00:00
uint32 val = grf_load_word ( buf ) ;
return val | ( grf_load_word ( buf ) < < 16 ) ;
2004-08-09 17:04:08 +00:00
}
2006-04-26 20:44:28 +00:00
static uint32 grf_load_var ( byte size , byte * * buf )
{
switch ( size ) {
case 1 : return grf_load_byte ( buf ) ;
case 2 : return grf_load_word ( buf ) ;
case 4 : return grf_load_dword ( buf ) ;
default :
NOT_REACHED ( ) ;
return 0 ;
}
}
2004-11-12 15:36:49 +00:00
2007-02-20 17:52:43 +00:00
static const char * grf_load_string ( byte * * buf , size_t max_len )
{
const char * string = * ( const char * * ) buf ;
size_t string_length = ttd_strnlen ( string , max_len ) ;
if ( string_length = = max_len ) {
/* String was not NUL terminated, so make sure it is now. */
( * buf ) [ string_length - 1 ] = ' \0 ' ;
grfmsg ( 7 , " String was not terminated with a zero byte. " ) ;
} else {
/* Increase the string length to include the NUL byte. */
string_length + + ;
}
* buf + = string_length ;
return string ;
}
2005-03-10 07:01:43 +00:00
static GRFFile * GetFileByGRFID ( uint32 grfid )
2004-11-12 22:28:19 +00:00
{
2005-03-10 07:01:43 +00:00
GRFFile * file ;
2004-11-12 22:28:19 +00:00
2005-03-10 07:01:43 +00:00
for ( file = _first_grffile ; file ! = NULL ; file = file - > next ) {
if ( file - > grfid = = grfid ) break ;
}
2004-11-12 22:28:19 +00:00
return file ;
}
2005-03-10 07:01:43 +00:00
static GRFFile * GetFileByFilename ( const char * filename )
2004-11-12 22:28:19 +00:00
{
2005-03-10 07:01:43 +00:00
GRFFile * file ;
2004-11-12 22:28:19 +00:00
2005-03-10 07:01:43 +00:00
for ( file = _first_grffile ; file ! = NULL ; file = file - > next ) {
if ( strcmp ( file - > filename , filename ) = = 0 ) break ;
}
2004-11-12 22:28:19 +00:00
return file ;
}
2008-07-04 18:42:04 +00:00
/** Reset all NewGRFData that was used only while processing data */
static void ClearTemporaryNewGRFData ( )
{
/* Clear the GOTO labels used for GRF processing */
for ( GRFLabel * l = _cur_grffile - > label ; l ! = NULL ; ) {
GRFLabel * l2 = l - > next ;
free ( l ) ;
l = l2 ;
}
_cur_grffile - > label = NULL ;
/* Clear the list of spritegroups */
free ( _cur_grffile - > spritegroups ) ;
_cur_grffile - > spritegroups = NULL ;
_cur_grffile - > spritegroups_count = 0 ;
}
2004-11-12 22:28:19 +00:00
2008-04-17 11:47:22 +00:00
typedef std : : map < StringID * , uint32 > StringIDToGRFIDMapping ;
StringIDToGRFIDMapping _string_to_grf_mapping ;
2007-03-19 11:27:30 +00:00
/** Used when setting an object's property to map to the GRF's strings
* while taking in consideration the " drift " between TTDPatch string system and OpenTTD ' s one
2007-04-17 20:23:13 +00:00
* @ param grfid Id of the grf file
2007-03-19 11:27:30 +00:00
* @ param str StringID that we want to have the equivalent in OoenTTD
* @ return the properly adjusted StringID
*/
2007-09-22 23:40:35 +00:00
StringID MapGRFStringID ( uint32 grfid , StringID str )
2007-03-19 11:27:30 +00:00
{
2007-11-13 18:57:38 +00:00
/* StringID table for TextIDs 0x4E->0x6D */
static StringID units_volume [ ] = {
STR_NOTHING , STR_PASSENGERS , STR_TONS , STR_BAGS ,
STR_LITERS , STR_ITEMS , STR_CRATES , STR_TONS ,
STR_TONS , STR_TONS , STR_TONS , STR_BAGS ,
STR_TONS , STR_TONS , STR_TONS , STR_BAGS ,
STR_TONS , STR_TONS , STR_BAGS , STR_LITERS ,
STR_TONS , STR_LITERS , STR_TONS , STR_NOTHING ,
STR_BAGS , STR_LITERS , STR_TONS , STR_NOTHING ,
STR_TONS , STR_NOTHING , STR_LITERS , STR_NOTHING
} ;
2008-02-29 08:40:49 +00:00
2007-03-19 11:27:30 +00:00
/* 0xD0 and 0xDC stand for all the TextIDs in the range
2007-03-21 03:06:21 +00:00
* of 0xD000 ( misc graphics texts ) and 0xDC00 ( misc persistent texts ) .
2007-03-19 11:27:30 +00:00
* These strings are unique to each grf file , and thus require to be used with the
* grfid in which they are declared */
2008-02-29 08:40:49 +00:00
switch ( GB ( str , 8 , 8 ) ) {
case 0xD0 : case 0xD1 : case 0xD2 : case 0xD3 :
case 0xDC :
return GetGRFStringID ( grfid , str ) ;
case 0xD4 : case 0xD5 : case 0xD6 : case 0xD7 :
/* Strings embedded via 0x81 have 0x400 added to them (no real
* explanation why . . . ) */
return GetGRFStringID ( grfid , str - 0x400 ) ;
default : break ;
2007-03-19 11:27:30 +00:00
}
2008-02-29 08:40:49 +00:00
2007-09-19 17:37:44 +00:00
# define TEXID_TO_STRINGID(begin, end, stringid) if (str >= begin && str <= end) return str + (stringid - begin)
2007-03-22 23:19:40 +00:00
/* We have some changes in our cargo strings, resulting in some missing. */
2007-09-19 17:37:44 +00:00
TEXID_TO_STRINGID ( 0x000E , 0x002D , STR_000E ) ;
TEXID_TO_STRINGID ( 0x002E , 0x004D , STR_002E ) ;
2007-11-13 18:57:38 +00:00
if ( str > = 0x004E & & str < = 0x006D ) str = units_volume [ str - 0x004E ] ;
2007-09-19 17:37:44 +00:00
TEXID_TO_STRINGID ( 0x006E , 0x008D , STR_QUANTITY_NOTHING ) ;
TEXID_TO_STRINGID ( 0x008E , 0x00AD , STR_ABBREV_NOTHING ) ;
2007-03-22 23:19:40 +00:00
2007-12-27 20:49:44 +00:00
/* Map building names according to our lang file changes. There are several
* ranges of house ids , all of which need to be remapped to allow newgrfs
* to use original house names . */
2007-09-19 17:37:44 +00:00
TEXID_TO_STRINGID ( 0x200F , 0x201F , STR_200F_TALL_OFFICE_BLOCK ) ;
2007-12-27 20:49:44 +00:00
TEXID_TO_STRINGID ( 0x2036 , 0x2041 , STR_2036_COTTAGES ) ;
TEXID_TO_STRINGID ( 0x2059 , 0x205C , STR_2059_IGLOO ) ;
2007-09-19 17:37:44 +00:00
/* Same thing for industries, since the introduction of 4 new strings above STR_482A_PRODUCTION_LAST_MONTH */
TEXID_TO_STRINGID ( 0x482A , 0x483B , STR_482A_PRODUCTION_LAST_MONTH ) ;
# undef TEXTID_TO_STRINGID
2007-03-19 11:27:30 +00:00
2007-09-19 18:55:26 +00:00
if ( str = = STR_NULL ) return STR_EMPTY ;
2007-03-19 11:27:30 +00:00
return str ;
}
2007-03-25 08:13:07 +00:00
static uint8 MapDOSColour ( uint8 colour )
{
2008-08-23 20:16:54 +00:00
if ( _use_palette = = PAL_DOS ) return colour ;
2007-03-25 08:13:07 +00:00
if ( colour < 10 ) {
static uint8 dos_to_win_colour_map [ ] = { 0 , 215 , 216 , 136 , 88 , 106 , 32 , 33 , 40 , 245 } ;
return dos_to_win_colour_map [ colour ] ;
}
if ( colour > = 245 & & colour < 254 ) return colour - 28 ;
return colour ;
}
2008-04-29 21:31:29 +00:00
static std : : map < uint32 , uint32 > _grf_id_overrides ;
static void SetNewGRFOverride ( uint32 source_grfid , uint32 target_grfid )
{
_grf_id_overrides [ source_grfid ] = target_grfid ;
grfmsg ( 5 , " SetNewGRFOverride: Added override of 0x%X to 0x%X " , BSWAP32 ( source_grfid ) , BSWAP32 ( target_grfid ) ) ;
}
static Engine * GetNewEngine ( const GRFFile * file , VehicleType type , uint16 internal_id )
{
/* Hack for add-on GRFs that need to modify another GRF's engines. This lets
* them use the same engine slots . */
const GRFFile * grf_match = NULL ;
2008-05-29 15:13:28 +00:00
if ( _settings_game . vehicle . dynamic_engines ) {
2008-04-29 21:31:29 +00:00
uint32 override = _grf_id_overrides [ file - > grfid ] ;
if ( override ! = 0 ) {
grf_match = GetFileByGRFID ( override ) ;
if ( grf_match = = NULL ) {
grfmsg ( 5 , " Tried mapping from GRFID %x to %x but target is not loaded " , BSWAP32 ( file - > grfid ) , BSWAP32 ( override ) ) ;
} else {
grfmsg ( 5 , " Mapping from GRFID %x to %x " , BSWAP32 ( file - > grfid ) , BSWAP32 ( override ) ) ;
}
}
}
/* Check if this vehicle is already defined... */
Engine * e = NULL ;
FOR_ALL_ENGINES ( e ) {
2008-05-29 15:13:28 +00:00
if ( _settings_game . vehicle . dynamic_engines & & e - > grffile ! = NULL & & e - > grffile ! = file & & e - > grffile ! = grf_match ) continue ;
2008-04-29 21:31:29 +00:00
if ( e - > type ! = type ) continue ;
if ( e - > internal_id ! = internal_id ) continue ;
if ( e - > grffile = = NULL ) {
e - > grffile = file ;
grfmsg ( 5 , " Replaced engine at index %d for GRFID %x, type %d, index %d " , e - > index , BSWAP32 ( file - > grfid ) , type , internal_id ) ;
}
return e ;
}
uint engine_pool_size = GetEnginePoolSize ( ) ;
/* ... it's not, so create a new one based off an existing engine */
e = new Engine ( type , internal_id ) ;
e - > grffile = file ;
if ( engine_pool_size ! = GetEnginePoolSize ( ) ) {
/* Resize temporary engine data ... */
_gted = ReallocT ( _gted , GetEnginePoolSize ( ) ) ;
/* and blank the new block. */
size_t len = ( GetEnginePoolSize ( ) - engine_pool_size ) * sizeof ( * _gted ) ;
memset ( _gted + engine_pool_size , 0 , len ) ;
}
grfmsg ( 5 , " Created new engine at index %d for GRFID %x, type %d, index %d " , e - > index , BSWAP32 ( file - > grfid ) , type , internal_id ) ;
return e ;
}
2008-04-30 17:42:08 +00:00
EngineID GetNewEngineID ( const GRFFile * file , VehicleType type , uint16 internal_id )
{
extern uint32 GetNewGRFOverride ( uint32 grfid ) ;
const GRFFile * grf_match = NULL ;
2008-05-29 15:13:28 +00:00
if ( _settings_game . vehicle . dynamic_engines ) {
2008-04-30 17:42:08 +00:00
uint32 override = _grf_id_overrides [ file - > grfid ] ;
if ( override ! = 0 ) grf_match = GetFileByGRFID ( override ) ;
}
const Engine * e = NULL ;
FOR_ALL_ENGINES ( e ) {
2008-05-29 15:13:28 +00:00
if ( _settings_game . vehicle . dynamic_engines & & e - > grffile ! = file & & ( grf_match = = NULL | | e - > grffile ! = grf_match ) ) continue ;
2008-04-30 17:42:08 +00:00
if ( e - > type ! = type ) continue ;
if ( e - > internal_id ! = internal_id ) continue ;
return e - > index ;
}
return INVALID_ENGINE ;
}
2008-02-16 03:01:05 +00:00
/** Map the colour modifiers of TTDPatch to those that Open is using.
* @ param grf_sprite pointer to the structure been modified
*/
static void MapSpriteMappingRecolour ( PalSpriteID * grf_sprite )
{
if ( HasBit ( grf_sprite - > pal , 14 ) ) {
ClrBit ( grf_sprite - > pal , 14 ) ;
SetBit ( grf_sprite - > sprite , SPRITE_MODIFIER_OPAQUE ) ;
}
if ( HasBit ( grf_sprite - > sprite , 14 ) ) {
ClrBit ( grf_sprite - > sprite , 14 ) ;
SetBit ( grf_sprite - > sprite , PALETTE_MODIFIER_TRANSPARENT ) ;
}
if ( HasBit ( grf_sprite - > sprite , 15 ) ) {
ClrBit ( grf_sprite - > sprite , 15 ) ;
SetBit ( grf_sprite - > sprite , PALETTE_MODIFIER_COLOR ) ;
}
}
2007-03-19 11:27:30 +00:00
2004-11-12 18:43:12 +00:00
typedef bool ( * VCI_Handler ) ( uint engine , int numinfo , int prop , byte * * buf , int len ) ;
2004-08-09 17:04:08 +00:00
2004-11-12 18:43:12 +00:00
static bool RailVehicleChangeInfo ( uint engine , int numinfo , int prop , byte * * bufp , int len )
2004-08-09 17:04:08 +00:00
{
byte * buf = * bufp ;
2004-11-12 18:43:12 +00:00
bool ret = false ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
2008-04-29 21:31:29 +00:00
Engine * e = GetNewEngine ( _cur_grffile , VEH_TRAIN , engine + i ) ;
EngineInfo * ei = & e - > info ;
RailVehicleInfo * rvi = & e - > u . rail ;
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x05 : { // Track type
2004-08-09 17:04:08 +00:00
uint8 tracktype = grf_load_byte ( & buf ) ;
2006-02-15 12:53:36 +00:00
switch ( tracktype ) {
2007-07-04 12:52:43 +00:00
case 0 : rvi - > railtype = rvi - > engclass > = 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL ; break ;
case 1 : rvi - > railtype = RAILTYPE_MONO ; break ;
case 2 : rvi - > railtype = RAILTYPE_MAGLEV ; break ;
2006-02-15 12:53:36 +00:00
default :
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " RailVehicleChangeInfo: Invalid track type %d specified, ignoring " , tracktype ) ;
2006-02-15 12:53:36 +00:00
break ;
}
2007-07-04 12:52:43 +00:00
} break ;
2006-02-15 12:53:36 +00:00
2007-07-04 12:52:43 +00:00
case 0x08 : // AI passenger service
2008-01-30 10:27:45 +00:00
/* Tells the AI that this engine is designed for
2007-07-04 13:30:33 +00:00
* passenger services and shouldn ' t be used for freight . */
2008-01-30 10:27:45 +00:00
rvi - > ai_passenger_only = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : { // Speed (1 unit is 1 kmh)
2004-08-09 17:04:08 +00:00
uint16 speed = grf_load_word ( & buf ) ;
2006-02-18 14:41:24 +00:00
if ( speed = = 0xFFFF ) speed = 0 ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
rvi - > max_speed = speed ;
} break ;
2006-02-27 15:35:22 +00:00
2008-05-13 20:39:57 +00:00
case 0x0B : // Power
rvi - > power = grf_load_word ( & buf ) ;
2008-06-05 12:08:20 +00:00
/* Set engine / wagon state based on power */
if ( rvi - > power ! = 0 ) {
if ( rvi - > railveh_type = = RAILVEH_WAGON ) {
rvi - > railveh_type = RAILVEH_SINGLEHEAD ;
}
} else {
rvi - > railveh_type = RAILVEH_WAGON ;
}
2008-05-13 20:39:57 +00:00
break ;
2006-01-07 13:20:02 +00:00
2008-05-13 20:39:57 +00:00
case 0x0D : // Running cost factor
rvi - > running_cost = grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x0E : { // Running cost base
2004-08-09 17:04:08 +00:00
uint32 base = grf_load_dword ( & buf ) ;
2008-02-21 19:09:10 +00:00
/* These magic numbers are used in GRFs to specify the base cost:
* http : //wiki.ttdpatch.net/tiki-index.php?page=BaseCosts
*/
if ( base = = 0 ) {
rvi - > running_cost_class = 0xFF ;
} else if ( base < 0x4B34 | | base > 0x4C54 | | ( base - 0x4B34 ) % 6 ! = 0 ) {
grfmsg ( 1 , " RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring " , base ) ;
} else {
/* Convert the magic number to an index into the price data */
rvi - > running_cost_class = ( base - 0x4B34 ) / 6 ;
2004-08-09 17:04:08 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x12 : { // Sprite ID
2004-08-09 17:04:08 +00:00
uint8 spriteid = grf_load_byte ( & buf ) ;
2006-01-27 07:13:58 +00:00
/* TTD sprite IDs point to a location in a 16bit array, but we use it
* as an array index , so we need it to be half the original value . */
2006-02-18 14:41:24 +00:00
if ( spriteid < 0xFD ) spriteid > > = 1 ;
2006-01-27 07:13:58 +00:00
2007-07-04 12:52:43 +00:00
rvi - > image_index = spriteid ;
} break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x13 : { // Dual-headed
2004-08-09 17:04:08 +00:00
uint8 dual = grf_load_byte ( & buf ) ;
2004-11-13 12:21:32 +00:00
if ( dual ! = 0 ) {
2007-07-04 12:52:43 +00:00
rvi - > railveh_type = RAILVEH_MULTIHEAD ;
2004-08-09 17:04:08 +00:00
} else {
2007-07-04 12:52:43 +00:00
rvi - > railveh_type = rvi - > power = = 0 ?
2007-01-30 22:00:25 +00:00
RAILVEH_WAGON : RAILVEH_SINGLEHEAD ;
2004-08-09 17:04:08 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
case 0x14 : // Cargo capacity
rvi - > capacity = grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x15 : { // Cargo type
2004-08-09 17:04:08 +00:00
uint8 ctype = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
if ( ctype < NUM_CARGO & & HasBit ( _cargo_mask , ctype ) ) {
2007-07-04 12:52:43 +00:00
rvi - > cargo_type = ctype ;
2006-01-12 07:57:40 +00:00
} else {
2007-07-04 12:52:43 +00:00
rvi - > cargo_type = CT_INVALID ;
2007-02-24 19:26:45 +00:00
grfmsg ( 2 , " RailVehicleChangeInfo: Invalid cargo type %d, using first refittable " , ctype ) ;
2006-01-12 07:57:40 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
case 0x16 : // Weight
SB ( rvi - > weight , 0 , 8 , grf_load_byte ( & buf ) ) ;
break ;
case 0x17 : // Cost factor
2008-08-15 17:54:43 +00:00
rvi - > cost_factor = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x18 : // AI rank
rvi - > ai_rank = grf_load_byte ( & buf ) ;
break ;
case 0x19 : { // Engine traction type
/* What do the individual numbers mean?
* 0x00 . . 0x07 : Steam
* 0x08 . . 0x27 : Diesel
* 0x28 . . 0x31 : Electric
* 0x32 . . 0x37 : Monorail
* 0x38 . . 0x41 : Maglev
*/
2004-08-09 17:04:08 +00:00
uint8 traction = grf_load_byte ( & buf ) ;
2007-05-06 15:01:44 +00:00
EngineClass engclass ;
2004-08-09 17:04:08 +00:00
2006-02-18 14:41:24 +00:00
if ( traction < = 0x07 ) {
2007-05-06 15:01:44 +00:00
engclass = EC_STEAM ;
2006-02-18 14:41:24 +00:00
} else if ( traction < = 0x27 ) {
2007-05-06 15:01:44 +00:00
engclass = EC_DIESEL ;
2006-03-29 16:30:26 +00:00
} else if ( traction < = 0x31 ) {
2007-05-06 15:01:44 +00:00
engclass = EC_ELECTRIC ;
2007-05-06 19:44:22 +00:00
} else if ( traction < = 0x37 ) {
engclass = EC_MONORAIL ;
2006-02-18 14:41:24 +00:00
} else if ( traction < = 0x41 ) {
2007-05-06 19:44:22 +00:00
engclass = EC_MAGLEV ;
2006-02-18 14:41:24 +00:00
} else {
2004-08-09 17:04:08 +00:00
break ;
2006-02-18 14:41:24 +00:00
}
2007-07-04 12:52:43 +00:00
if ( rvi - > railtype = = RAILTYPE_RAIL & & engclass > = EC_ELECTRIC ) rvi - > railtype = RAILTYPE_ELECTRIC ;
if ( rvi - > railtype = = RAILTYPE_ELECTRIC & & engclass < EC_ELECTRIC ) rvi - > railtype = RAILTYPE_RAIL ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
rvi - > engclass = engclass ;
} break ;
2006-02-27 15:35:22 +00:00
2008-04-29 21:31:29 +00:00
case 0x1A : // Alter purchase list sort order
2008-07-26 07:43:20 +00:00
AlterVehicleListOrder ( e - > index , grf_load_extended ( & buf ) ) ;
2008-04-29 21:31:29 +00:00
break ;
2006-02-04 21:48:46 +00:00
2007-07-04 12:52:43 +00:00
case 0x1B : // Powered wagons power bonus
rvi - > pow_wag_power = grf_load_word ( & buf ) ;
break ;
2005-06-06 00:19:24 +00:00
2007-07-04 12:52:43 +00:00
case 0x1C : // Refit cost
ei - > refit_cost = grf_load_byte ( & buf ) ;
break ;
2006-06-09 16:35:07 +00:00
2007-07-04 12:52:43 +00:00
case 0x1D : // Refit cargo
ei - > refit_mask = grf_load_dword ( & buf ) ;
break ;
2004-11-17 01:09:15 +00:00
2007-07-04 12:52:43 +00:00
case 0x1E : // Callback
ei - > callbackmask = grf_load_byte ( & buf ) ;
break ;
2005-06-06 22:44:11 +00:00
2007-07-04 12:52:43 +00:00
case 0x1F : // Tractive effort coefficient
rvi - > tractive_effort = grf_load_byte ( & buf ) ;
break ;
2006-12-28 13:18:07 +00:00
2007-10-25 23:24:28 +00:00
case 0x20 : // Air drag
/** @todo Air drag for trains. */
grf_load_byte ( & buf ) ;
ret = true ;
break ;
2007-07-04 12:52:43 +00:00
case 0x21 : // Shorter vehicle
rvi - > shorten_factor = grf_load_byte ( & buf ) ;
break ;
2005-06-06 22:44:11 +00:00
2007-07-04 12:52:43 +00:00
case 0x22 : // Visual effect
2007-07-04 13:30:33 +00:00
/** @see note in engine.h about rvi->visual_effect */
2007-07-04 12:52:43 +00:00
rvi - > visual_effect = grf_load_byte ( & buf ) ;
break ;
2005-06-06 00:19:24 +00:00
2007-07-04 12:52:43 +00:00
case 0x23 : // Powered wagons weight bonus
rvi - > pow_wag_weight = grf_load_byte ( & buf ) ;
break ;
2005-06-06 00:19:24 +00:00
2007-07-04 12:52:43 +00:00
case 0x24 : { // High byte of vehicle weight
2005-10-20 15:15:58 +00:00
byte weight = grf_load_byte ( & buf ) ;
2005-10-20 19:44:41 +00:00
if ( weight > 4 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring " , weight < < 8 ) ;
2005-10-20 15:15:58 +00:00
} else {
2007-07-04 12:52:43 +00:00
SB ( rvi - > weight , 8 , 8 , weight ) ;
2005-10-20 15:15:58 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x25 : // User-defined bit mask to set when checking veh. var. 42
rvi - > user_def_data = grf_load_byte ( & buf ) ;
break ;
case 0x26 : // Retire vehicle early
ei - > retire_early = grf_load_byte ( & buf ) ;
break ;
case 0x27 : // Miscellaneous flags
ei - > misc_flags = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
_loaded_newgrf_features . has_2CC | = HasBit ( ei - > misc_flags , EF_USES_2CC ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x28 : // Cargo classes allowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_allowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x29 : // Cargo classes disallowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_disallowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x2A : // Long format introduction date (days since year 0)
ei - > base_intro = grf_load_dword ( & buf ) ;
break ;
default :
ret = true ;
break ;
}
2004-08-09 17:04:08 +00:00
}
2007-07-04 12:52:43 +00:00
2004-08-09 17:04:08 +00:00
* bufp = buf ;
return ret ;
}
2004-11-13 18:01:33 +00:00
static bool RoadVehicleChangeInfo ( uint engine , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
2008-04-29 21:31:29 +00:00
Engine * e = GetNewEngine ( _cur_grffile , VEH_ROAD , engine + i ) ;
EngineInfo * ei = & e - > info ;
RoadVehicleInfo * rvi = & e - > u . road ;
2004-11-13 18:01:33 +00:00
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : // Speed (1 unit is 0.5 kmh)
rvi - > max_speed = grf_load_byte ( & buf ) ;
break ;
2004-11-13 18:01:33 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : // Running cost factor
rvi - > running_cost = grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2008-02-21 19:09:10 +00:00
case 0x0A : { // Running cost base
uint32 base = grf_load_dword ( & buf ) ;
/* These magic numbers are used in GRFs to specify the base cost:
* http : //wiki.ttdpatch.net/tiki-index.php?page=BaseCosts
*/
if ( base = = 0 ) {
rvi - > running_cost_class = 0xFF ;
} else if ( base < 0x4B34 | | base > 0x4C54 | | ( base - 0x4B34 ) % 6 ! = 0 ) {
grfmsg ( 1 , " RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring " , base ) ;
} else {
/* Convert the magic number to an index into the price data */
rvi - > running_cost_class = ( base - 0x4B34 ) / 6 ;
}
2007-07-04 12:52:43 +00:00
break ;
2008-02-21 19:09:10 +00:00
}
2007-07-04 12:52:43 +00:00
case 0x0E : { // Sprite ID
2004-11-13 18:01:33 +00:00
uint8 spriteid = grf_load_byte ( & buf ) ;
2007-03-21 03:06:21 +00:00
/* cars have different custom id in the GRF file */
2006-02-18 14:41:24 +00:00
if ( spriteid = = 0xFF ) spriteid = 0xFD ;
2004-11-13 18:01:33 +00:00
2006-02-18 14:41:24 +00:00
if ( spriteid < 0xFD ) spriteid > > = 1 ;
2006-01-27 07:13:58 +00:00
2007-07-04 12:52:43 +00:00
rvi - > image_index = spriteid ;
} break ;
2004-11-13 18:01:33 +00:00
2007-07-04 12:52:43 +00:00
case 0x0F : // Cargo capacity
rvi - > capacity = grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x10 : { // Cargo type
2004-11-13 18:01:33 +00:00
uint8 cargo = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
if ( cargo < NUM_CARGO & & HasBit ( _cargo_mask , cargo ) ) {
2007-07-04 12:52:43 +00:00
rvi - > cargo_type = cargo ;
2006-01-12 07:57:40 +00:00
} else {
2007-07-04 12:52:43 +00:00
rvi - > cargo_type = CT_INVALID ;
2007-02-24 19:26:45 +00:00
grfmsg ( 2 , " RoadVehicleChangeInfo: Invalid cargo type %d, using first refittable " , cargo ) ;
2006-01-12 07:57:40 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x11 : // Cost factor
2008-08-15 17:54:43 +00:00
rvi - > cost_factor = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x12 : // SFX
rvi - > sfx = ( SoundFx ) grf_load_byte ( & buf ) ;
break ;
case 0x13 : // Power in 10hp
case 0x14 : // Weight in 1/4 tons
case 0x15 : // Speed in mph*0.8
2007-07-04 13:30:33 +00:00
/** @todo Support for road vehicles realistic power
2007-07-04 12:52:43 +00:00
* computations ( called rvpower in TTDPatch ) is just
* missing in OTTD yet . - - pasky */
grf_load_byte ( & buf ) ;
ret = true ;
break ;
case 0x16 : // Cargos available for refitting
ei - > refit_mask = grf_load_dword ( & buf ) ;
break ;
case 0x17 : // Callback mask
ei - > callbackmask = grf_load_byte ( & buf ) ;
break ;
2007-10-25 23:24:28 +00:00
case 0x18 : // Tractive effort
case 0x19 : // Air drag
/** @todo Tractive effort and air drag for road vehicles. */
grf_load_byte ( & buf ) ;
ret = true ;
break ;
2007-07-04 12:52:43 +00:00
case 0x1A : // Refit cost
ei - > refit_cost = grf_load_byte ( & buf ) ;
break ;
case 0x1B : // Retire vehicle early
ei - > retire_early = grf_load_byte ( & buf ) ;
break ;
case 0x1C : // Miscellaneous flags
ei - > misc_flags = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
_loaded_newgrf_features . has_2CC | = HasBit ( ei - > misc_flags , EF_USES_2CC ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x1D : // Cargo classes allowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_allowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x1E : // Cargo classes disallowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_disallowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x1F : // Long format introduction date (days since year 0)
ei - > base_intro = grf_load_dword ( & buf ) ;
break ;
2008-07-21 14:42:25 +00:00
case 0x20 : // Alter purchase list sort order
2008-07-26 07:43:20 +00:00
AlterVehicleListOrder ( e - > index , grf_load_extended ( & buf ) ) ;
2008-07-21 14:42:25 +00:00
break ;
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2004-11-13 18:01:33 +00:00
}
* bufp = buf ;
return ret ;
}
2004-11-12 18:43:12 +00:00
static bool ShipVehicleChangeInfo ( uint engine , int numinfo , int prop , byte * * bufp , int len )
2004-08-09 17:04:08 +00:00
{
byte * buf = * bufp ;
2004-11-12 18:43:12 +00:00
bool ret = false ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
2008-04-29 21:31:29 +00:00
Engine * e = GetNewEngine ( _cur_grffile , VEH_SHIP , engine + i ) ;
EngineInfo * ei = & e - > info ;
ShipVehicleInfo * svi = & e - > u . ship ;
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : { // Sprite ID
2004-08-09 17:04:08 +00:00
uint8 spriteid = grf_load_byte ( & buf ) ;
2007-03-21 03:06:21 +00:00
/* ships have different custom id in the GRF file */
2006-02-18 14:41:24 +00:00
if ( spriteid = = 0xFF ) spriteid = 0xFD ;
2004-08-09 17:04:08 +00:00
2006-02-18 14:41:24 +00:00
if ( spriteid < 0xFD ) spriteid > > = 1 ;
2006-01-27 07:13:58 +00:00
2007-07-04 12:52:43 +00:00
svi - > image_index = spriteid ;
} break ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : // Refittable
svi - > refittable = ( grf_load_byte ( & buf ) ! = 0 ) ;
break ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
case 0x0A : // Cost factor
2008-08-15 17:54:43 +00:00
svi - > cost_factor = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2004-08-09 17:04:08 +00:00
2007-07-04 12:52:43 +00:00
case 0x0B : // Speed (1 unit is 0.5 kmh)
svi - > max_speed = grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x0C : { // Cargo type
2004-08-09 17:04:08 +00:00
uint8 cargo = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
if ( cargo < NUM_CARGO & & HasBit ( _cargo_mask , cargo ) ) {
2007-07-04 12:52:43 +00:00
svi - > cargo_type = cargo ;
2006-01-12 07:57:40 +00:00
} else {
2007-07-04 12:52:43 +00:00
svi - > cargo_type = CT_INVALID ;
2007-02-24 19:26:45 +00:00
grfmsg ( 2 , " ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable " , cargo ) ;
2006-01-12 07:57:40 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x0D : // Cargo capacity
svi - > capacity = grf_load_word ( & buf ) ;
break ;
case 0x0F : // Running cost factor
svi - > running_cost = grf_load_byte ( & buf ) ;
break ;
case 0x10 : // SFX
svi - > sfx = ( SoundFx ) grf_load_byte ( & buf ) ;
break ;
case 0x11 : // Cargos available for refitting
ei - > refit_mask = grf_load_dword ( & buf ) ;
break ;
case 0x12 : // Callback mask
ei - > callbackmask = grf_load_byte ( & buf ) ;
break ;
case 0x13 : // Refit cost
ei - > refit_cost = grf_load_byte ( & buf ) ;
break ;
2007-10-25 23:24:28 +00:00
case 0x14 : // Ocean speed fraction
case 0x15 : // Canal speed fraction
/** @todo Speed fractions for ships on oceans and canals */
grf_load_byte ( & buf ) ;
ret = true ;
break ;
2007-07-04 12:52:43 +00:00
case 0x16 : // Retire vehicle early
ei - > retire_early = grf_load_byte ( & buf ) ;
break ;
case 0x17 : // Miscellaneous flags
ei - > misc_flags = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
_loaded_newgrf_features . has_2CC | = HasBit ( ei - > misc_flags , EF_USES_2CC ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x18 : // Cargo classes allowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_allowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x19 : // Cargo classes disallowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_disallowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x1A : // Long format introduction date (days since year 0)
ei - > base_intro = grf_load_dword ( & buf ) ;
break ;
2008-07-21 14:42:25 +00:00
case 0x1B : // Alter purchase list sort order
2008-07-26 07:43:20 +00:00
AlterVehicleListOrder ( e - > index , grf_load_extended ( & buf ) ) ;
2008-07-21 14:42:25 +00:00
break ;
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2004-08-09 17:04:08 +00:00
}
* bufp = buf ;
return ret ;
}
2004-11-13 20:37:57 +00:00
static bool AircraftVehicleChangeInfo ( uint engine , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
2008-04-29 21:31:29 +00:00
Engine * e = GetNewEngine ( _cur_grffile , VEH_AIRCRAFT , engine + i ) ;
EngineInfo * ei = & e - > info ;
AircraftVehicleInfo * avi = & e - > u . air ;
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : { // Sprite ID
2004-11-13 20:37:57 +00:00
uint8 spriteid = grf_load_byte ( & buf ) ;
2007-03-21 03:06:21 +00:00
/* aircraft have different custom id in the GRF file */
2006-02-18 14:41:24 +00:00
if ( spriteid = = 0xFF ) spriteid = 0xFD ;
2004-11-13 20:37:57 +00:00
2006-02-18 14:41:24 +00:00
if ( spriteid < 0xFD ) spriteid > > = 1 ;
2006-01-27 07:13:58 +00:00
2007-07-04 12:52:43 +00:00
avi - > image_index = spriteid ;
} break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : // Helicopter
2006-10-23 17:01:02 +00:00
if ( grf_load_byte ( & buf ) = = 0 ) {
2007-07-04 12:52:43 +00:00
avi - > subtype = AIR_HELI ;
2006-10-23 17:01:02 +00:00
} else {
2007-07-04 12:52:43 +00:00
SB ( avi - > subtype , 0 , 1 , 1 ) ; // AIR_CTOL
2006-10-23 17:01:02 +00:00
}
2007-07-04 12:52:43 +00:00
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x0A : // Large
SB ( avi - > subtype , 1 , 1 , ( grf_load_byte ( & buf ) ! = 0 ? 1 : 0 ) ) ; // AIR_FAST
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x0B : // Cost factor
2008-08-15 17:54:43 +00:00
avi - > cost_factor = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x0C : // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
avi - > max_speed = ( grf_load_byte ( & buf ) * 129 ) / 10 ;
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x0D : // Acceleration
avi - > acceleration = ( grf_load_byte ( & buf ) * 129 ) / 10 ;
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x0E : // Running cost factor
avi - > running_cost = grf_load_byte ( & buf ) ;
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x0F : // Passenger capacity
avi - > passenger_capacity = grf_load_word ( & buf ) ;
break ;
2004-11-13 20:37:57 +00:00
2007-07-04 12:52:43 +00:00
case 0x11 : // Mail capacity
avi - > mail_capacity = grf_load_byte ( & buf ) ;
break ;
2006-02-11 07:34:05 +00:00
2007-07-04 12:52:43 +00:00
case 0x12 : // SFX
avi - > sfx = ( SoundFx ) grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x13 : // Cargos available for refitting
ei - > refit_mask = grf_load_dword ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x14 : // Callback mask
ei - > callbackmask = grf_load_byte ( & buf ) ;
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x15 : // Refit cost
ei - > refit_cost = grf_load_byte ( & buf ) ;
break ;
2006-06-09 16:35:07 +00:00
2007-07-04 12:52:43 +00:00
case 0x16 : // Retire vehicle early
ei - > retire_early = grf_load_byte ( & buf ) ;
break ;
2007-05-10 23:10:23 +00:00
2007-07-04 12:52:43 +00:00
case 0x17 : // Miscellaneous flags
ei - > misc_flags = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
_loaded_newgrf_features . has_2CC | = HasBit ( ei - > misc_flags , EF_USES_2CC ) ;
2007-07-04 12:52:43 +00:00
break ;
2006-02-28 08:13:15 +00:00
2007-07-04 12:52:43 +00:00
case 0x18 : // Cargo classes allowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_allowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2006-02-27 15:35:22 +00:00
2007-07-04 12:52:43 +00:00
case 0x19 : // Cargo classes disallowed
2008-04-29 21:31:29 +00:00
_gted [ e - > index ] . cargo_disallowed = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2006-02-11 07:34:05 +00:00
2007-07-04 12:52:43 +00:00
case 0x1A : // Long format introduction date (days since year 0)
ei - > base_intro = grf_load_dword ( & buf ) ;
break ;
2006-11-17 11:03:38 +00:00
2008-07-21 14:42:25 +00:00
case 0x1B : // Alter purchase list sort order
2008-07-26 07:43:20 +00:00
AlterVehicleListOrder ( e - > index , grf_load_extended ( & buf ) ) ;
2008-07-21 14:42:25 +00:00
break ;
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2004-11-13 20:37:57 +00:00
}
* bufp = buf ;
return ret ;
}
2004-11-14 09:07:15 +00:00
static bool StationChangeInfo ( uint stid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
2006-04-11 13:00:06 +00:00
bool ret = false ;
2004-11-14 09:07:15 +00:00
2006-05-06 22:20:16 +00:00
if ( stid + numinfo > MAX_STATIONS ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " StationChangeInfo: Station %u is invalid, max %u, ignoring " , stid + numinfo , MAX_STATIONS ) ;
2006-05-06 22:20:16 +00:00
return false ;
}
2006-04-11 10:05:52 +00:00
/* Allocate station specs if necessary */
2007-01-11 17:29:39 +00:00
if ( _cur_grffile - > stations = = NULL ) _cur_grffile - > stations = CallocT < StationSpec * > ( MAX_STATIONS ) ;
2006-05-06 22:20:16 +00:00
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
StationSpec * statspec = _cur_grffile - > stations [ stid + i ] ;
2006-04-11 10:05:52 +00:00
2007-07-04 12:52:43 +00:00
/* Check that the station we are modifying is defined. */
if ( statspec = = NULL & & prop ! = 0x08 ) {
grfmsg ( 2 , " StationChangeInfo: Attempt to modify undefined station %u, ignoring " , stid + i ) ;
continue ;
2006-04-11 10:05:52 +00:00
}
2004-11-14 09:07:15 +00:00
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : { // Class ID
StationSpec * * spec = & _cur_grffile - > stations [ stid + i ] ;
2006-05-06 22:20:16 +00:00
/* Property 0x08 is special; it is where the station is allocated */
2007-07-04 12:52:43 +00:00
if ( * spec = = NULL ) * spec = CallocT < StationSpec > ( 1 ) ;
2006-05-06 22:20:16 +00:00
2006-05-01 21:45:35 +00:00
/* Swap classid because we read it in BE meaning WAYP or DFLT */
2007-03-10 09:55:11 +00:00
uint32 classid = grf_load_dword ( & buf ) ;
2007-07-04 12:52:43 +00:00
( * spec ) - > sclass = AllocateStationClass ( BSWAP32 ( classid ) ) ;
} break ;
2004-11-14 13:59:11 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : // Define sprite layout
2006-04-27 18:28:56 +00:00
statspec - > tiles = grf_load_extended ( & buf ) ;
2007-01-11 17:29:39 +00:00
statspec - > renderdata = CallocT < DrawTileSprites > ( statspec - > tiles ) ;
2006-05-03 21:07:44 +00:00
statspec - > copied_renderdata = false ;
2007-03-10 09:55:11 +00:00
for ( uint t = 0 ; t < statspec - > tiles ; t + + ) {
2006-04-27 18:28:56 +00:00
DrawTileSprites * dts = & statspec - > renderdata [ t ] ;
2006-04-16 18:57:07 +00:00
uint seq_count = 0 ;
2004-11-14 09:07:15 +00:00
2006-05-03 20:35:41 +00:00
dts - > seq = NULL ;
2008-02-15 18:40:42 +00:00
dts - > ground . sprite = grf_load_word ( & buf ) ;
dts - > ground . pal = grf_load_word ( & buf ) ;
if ( dts - > ground . sprite = = 0 ) continue ;
if ( HasBit ( dts - > ground . pal , 15 ) ) {
ClrBit ( dts - > ground . pal , 15 ) ;
SetBit ( dts - > ground . sprite , SPRITE_MODIFIER_USE_OFFSET ) ;
2007-01-14 19:57:49 +00:00
}
2008-02-16 03:01:05 +00:00
MapSpriteMappingRecolour ( & dts - > ground ) ;
2005-11-12 00:19:34 +00:00
2004-11-14 09:07:15 +00:00
while ( buf < * bufp + len ) {
DrawTileSeqStruct * dtss ;
2007-03-21 03:06:21 +00:00
/* no relative bounding box support */
2007-01-11 17:29:39 +00:00
dts - > seq = ReallocT ( ( DrawTileSeqStruct * ) dts - > seq , + + seq_count ) ;
2004-11-14 09:07:15 +00:00
dtss = ( DrawTileSeqStruct * ) & dts - > seq [ seq_count - 1 ] ;
dtss - > delta_x = grf_load_byte ( & buf ) ;
if ( ( byte ) dtss - > delta_x = = 0x80 ) break ;
dtss - > delta_y = grf_load_byte ( & buf ) ;
dtss - > delta_z = grf_load_byte ( & buf ) ;
2006-08-06 08:23:19 +00:00
dtss - > size_x = grf_load_byte ( & buf ) ;
dtss - > size_y = grf_load_byte ( & buf ) ;
dtss - > size_z = grf_load_byte ( & buf ) ;
2008-02-15 18:34:26 +00:00
dtss - > image . sprite = grf_load_word ( & buf ) ;
dtss - > image . pal = grf_load_word ( & buf ) ;
2006-05-06 22:55:21 +00:00
2006-05-07 10:58:53 +00:00
/* Remap flags as ours collide */
2008-02-15 18:34:26 +00:00
if ( HasBit ( dtss - > image . pal , 15 ) ) {
ClrBit ( dtss - > image . pal , 15 ) ;
SetBit ( dtss - > image . sprite , SPRITE_MODIFIER_USE_OFFSET ) ;
2007-01-14 19:57:49 +00:00
}
2008-02-16 03:01:05 +00:00
MapSpriteMappingRecolour ( & dtss - > image ) ;
2004-11-14 09:07:15 +00:00
}
}
2007-07-04 12:52:43 +00:00
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x0A : { // Copy sprite layout
2004-11-14 13:59:11 +00:00
byte srcid = grf_load_byte ( & buf ) ;
2006-05-06 22:20:16 +00:00
const StationSpec * srcstatspec = _cur_grffile - > stations [ srcid ] ;
2004-11-14 13:59:11 +00:00
2006-04-27 18:28:56 +00:00
statspec - > tiles = srcstatspec - > tiles ;
2006-05-03 20:42:45 +00:00
statspec - > renderdata = srcstatspec - > renderdata ;
2006-05-03 21:07:44 +00:00
statspec - > copied_renderdata = true ;
2007-07-04 12:52:43 +00:00
} break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x0B : // Callback mask
statspec - > callbackmask = grf_load_byte ( & buf ) ;
break ;
2004-11-17 18:03:33 +00:00
2007-07-04 12:52:43 +00:00
case 0x0C : // Disallowed number of platforms
statspec - > disallowed_platforms = grf_load_byte ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x0D : // Disallowed platform lengths
statspec - > disallowed_lengths = grf_load_byte ( & buf ) ;
break ;
2004-11-17 18:03:33 +00:00
2007-07-04 12:52:43 +00:00
case 0x0E : // Define custom layout
2006-11-08 12:17:14 +00:00
statspec - > copied_layouts = false ;
2004-11-14 09:07:15 +00:00
while ( buf < * bufp + len ) {
byte length = grf_load_byte ( & buf ) ;
byte number = grf_load_byte ( & buf ) ;
2004-11-17 18:03:33 +00:00
StationLayout layout ;
2006-04-16 18:57:07 +00:00
uint l , p ;
2004-11-17 18:03:33 +00:00
if ( length = = 0 | | number = = 0 ) break ;
//debug("l %d > %d ?", length, stat->lengths);
2006-04-27 18:28:56 +00:00
if ( length > statspec - > lengths ) {
2007-01-11 17:29:39 +00:00
statspec - > platforms = ReallocT ( statspec - > platforms , length ) ;
2006-04-27 18:28:56 +00:00
memset ( statspec - > platforms + statspec - > lengths , 0 , length - statspec - > lengths ) ;
2004-11-17 18:03:33 +00:00
2007-01-11 17:29:39 +00:00
statspec - > layouts = ReallocT ( statspec - > layouts , length ) ;
2006-04-27 18:28:56 +00:00
memset ( statspec - > layouts + statspec - > lengths , 0 ,
( length - statspec - > lengths ) * sizeof ( * statspec - > layouts ) ) ;
2004-11-17 18:03:33 +00:00
2006-04-27 18:28:56 +00:00
statspec - > lengths = length ;
2004-11-17 18:03:33 +00:00
}
l = length - 1 ; // index is zero-based
//debug("p %d > %d ?", number, stat->platforms[l]);
2006-04-27 18:28:56 +00:00
if ( number > statspec - > platforms [ l ] ) {
2007-01-11 17:29:39 +00:00
statspec - > layouts [ l ] = ReallocT ( statspec - > layouts [ l ] , number ) ;
2007-03-21 03:06:21 +00:00
/* We expect NULL being 0 here, but C99 guarantees that. */
2006-04-27 18:28:56 +00:00
memset ( statspec - > layouts [ l ] + statspec - > platforms [ l ] , 0 ,
( number - statspec - > platforms [ l ] ) * sizeof ( * * statspec - > layouts ) ) ;
2004-11-17 18:03:33 +00:00
2006-04-27 18:28:56 +00:00
statspec - > platforms [ l ] = number ;
2004-11-17 18:03:33 +00:00
}
2004-12-04 15:02:45 +00:00
p = 0 ;
2007-01-11 17:29:39 +00:00
layout = MallocT < byte > ( length * number ) ;
2006-02-18 14:41:24 +00:00
for ( l = 0 ; l < length ; l + + ) {
for ( p = 0 ; p < number ; p + + ) {
2004-11-17 18:03:33 +00:00
layout [ l * number + p ] = grf_load_byte ( & buf ) ;
2006-02-18 14:41:24 +00:00
}
}
2004-11-14 09:07:15 +00:00
2004-11-17 18:03:33 +00:00
l - - ;
p - - ;
2006-04-27 18:28:56 +00:00
free ( statspec - > layouts [ l ] [ p ] ) ;
statspec - > layouts [ l ] [ p ] = layout ;
2004-11-14 09:07:15 +00:00
}
2007-07-04 12:52:43 +00:00
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x0F : { // Copy custom layout
2006-11-08 12:17:14 +00:00
byte srcid = grf_load_byte ( & buf ) ;
const StationSpec * srcstatspec = _cur_grffile - > stations [ srcid ] ;
statspec - > lengths = srcstatspec - > lengths ;
statspec - > platforms = srcstatspec - > platforms ;
statspec - > layouts = srcstatspec - > layouts ;
statspec - > copied_layouts = true ;
2007-07-04 12:52:43 +00:00
} break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x10 : // Little/lots cargo threshold
statspec - > cargo_threshold = grf_load_word ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x11 : // Pylon placement
statspec - > pylons = grf_load_byte ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x12 : // Cargo types for random triggers
statspec - > cargo_triggers = grf_load_dword ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x13 : // General flags
statspec - > flags = grf_load_byte ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x14 : // Overhead wire placement
statspec - > wires = grf_load_byte ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2007-07-04 12:52:43 +00:00
case 0x15 : // Blocked tiles
statspec - > blocked = grf_load_byte ( & buf ) ;
break ;
2006-04-11 13:00:06 +00:00
2008-04-19 23:19:12 +00:00
case 0x16 : // Animation info
statspec - > anim_frames = grf_load_byte ( & buf ) ;
statspec - > anim_status = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2007-02-02 02:56:29 +00:00
2008-04-19 23:19:12 +00:00
case 0x17 : // Animation speed
statspec - > anim_speed = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2007-02-02 02:56:29 +00:00
2008-04-19 23:19:12 +00:00
case 0x18 : // Animation triggers
statspec - > anim_triggers = grf_load_word ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
2007-02-02 02:56:29 +00:00
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2004-11-14 09:07:15 +00:00
}
* bufp = buf ;
return ret ;
}
2008-01-21 20:41:04 +00:00
static bool CanalChangeInfo ( uint id , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
if ( id + numinfo > CF_END ) {
grfmsg ( 1 , " CanalChangeInfo: Canal feature %u is invalid, max %u, ignoreing " , id + numinfo , CF_END ) ;
return false ;
}
for ( int i = 0 ; i < numinfo ; i + + ) {
WaterFeature * wf = & _water_feature [ id + i ] ;
switch ( prop ) {
case 0x08 :
wf - > callbackmask = grf_load_byte ( & buf ) ;
break ;
case 0x09 :
wf - > flags = grf_load_byte ( & buf ) ;
break ;
default :
ret = true ;
break ;
}
}
* bufp = buf ;
return ret ;
}
2005-10-01 17:38:48 +00:00
static bool BridgeChangeInfo ( uint brid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
2006-04-11 10:53:07 +00:00
bool ret = false ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
if ( brid + numinfo > MAX_BRIDGES ) {
grfmsg ( 1 , " BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring " , brid + numinfo , MAX_BRIDGES ) ;
return false ;
}
for ( int i = 0 ; i < numinfo ; i + + ) {
2008-02-11 17:35:15 +00:00
BridgeSpec * bridge = & _bridge [ brid + i ] ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : // Year of availability
bridge - > avail_year = ORIGINAL_BASE_YEAR + grf_load_byte ( & buf ) ;
break ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : // Minimum length
bridge - > min_length = grf_load_byte ( & buf ) ;
break ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
case 0x0A : // Maximum length
bridge - > max_length = grf_load_byte ( & buf ) ;
break ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
case 0x0B : // Cost factor
bridge - > price = grf_load_byte ( & buf ) ;
break ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
case 0x0C : // Maximum speed
bridge - > speed = grf_load_word ( & buf ) ;
break ;
case 0x0D : { // Bridge sprite tables
2005-10-01 17:38:48 +00:00
byte tableid = grf_load_byte ( & buf ) ;
byte numtables = grf_load_byte ( & buf ) ;
if ( bridge - > sprite_table = = NULL ) {
2006-04-15 16:03:45 +00:00
/* Allocate memory for sprite table pointers and zero out */
2007-01-11 17:29:39 +00:00
bridge - > sprite_table = CallocT < PalSpriteID * > ( 7 ) ;
2005-10-01 17:38:48 +00:00
}
2006-04-15 16:03:45 +00:00
for ( ; numtables - - ! = 0 ; tableid + + ) {
if ( tableid > = 7 ) { // skip invalid data
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " BridgeChangeInfo: Table %d >= 7, skipping " , tableid ) ;
2007-03-10 09:55:11 +00:00
for ( byte sprite = 0 ; sprite < 32 ; sprite + + ) grf_load_dword ( & buf ) ;
2006-04-15 16:03:45 +00:00
continue ;
2005-10-02 12:00:30 +00:00
}
2006-04-15 16:03:45 +00:00
if ( bridge - > sprite_table [ tableid ] = = NULL ) {
2007-01-11 17:29:39 +00:00
bridge - > sprite_table [ tableid ] = MallocT < PalSpriteID > ( 32 ) ;
2006-04-15 16:03:45 +00:00
}
2007-03-10 09:55:11 +00:00
for ( byte sprite = 0 ; sprite < 32 ; sprite + + ) {
2007-01-14 19:57:49 +00:00
SpriteID image = grf_load_word ( & buf ) ;
SpriteID pal = grf_load_word ( & buf ) ;
bridge - > sprite_table [ tableid ] [ sprite ] . sprite = image ;
bridge - > sprite_table [ tableid ] [ sprite ] . pal = pal ;
2008-02-16 03:01:05 +00:00
MapSpriteMappingRecolour ( & bridge - > sprite_table [ tableid ] [ sprite ] ) ;
2007-01-14 19:57:49 +00:00
}
2005-10-01 17:38:48 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
case 0x0E : // Flags; bit 0 - disable far pillars
bridge - > flags = grf_load_byte ( & buf ) ;
break ;
2005-10-01 17:38:48 +00:00
2007-07-04 12:52:43 +00:00
case 0x0F : // Long format year of availability (year since year 0)
2007-11-19 18:38:10 +00:00
bridge - > avail_year = Clamp ( grf_load_dword ( & buf ) , MIN_YEAR , MAX_YEAR ) ;
2007-07-04 12:52:43 +00:00
break ;
2006-11-17 11:03:38 +00:00
2008-02-06 03:01:29 +00:00
case 0x10 : { // purchase string
StringID newone = GetGRFStringID ( _cur_grffile - > grfid , grf_load_word ( & buf ) ) ;
if ( newone ! = STR_UNDEFINED ) bridge - > material = newone ;
} break ;
2008-02-12 03:05:27 +00:00
case 0x11 : // description of bridge with rails or roads
case 0x12 : {
2008-02-06 03:01:29 +00:00
StringID newone = GetGRFStringID ( _cur_grffile - > grfid , grf_load_word ( & buf ) ) ;
2008-02-12 03:05:27 +00:00
if ( newone ! = STR_UNDEFINED ) bridge - > transport_name [ prop - 0x11 ] = newone ;
2008-02-06 03:01:29 +00:00
} break ;
2008-08-25 17:16:27 +00:00
case 0x13 : // 16 bits cost multiplier
bridge - > price = grf_load_word ( & buf ) ;
break ;
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2005-10-01 17:38:48 +00:00
}
* bufp = buf ;
return ret ;
}
2004-11-14 09:07:15 +00:00
2007-03-19 11:27:30 +00:00
static bool TownHouseChangeInfo ( uint hid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
2007-07-04 13:01:55 +00:00
if ( hid + numinfo > HOUSE_MAX ) {
grfmsg ( 1 , " TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring. " , hid + numinfo , HOUSE_MAX ) ;
2007-03-19 11:27:30 +00:00
return false ;
}
/* Allocate house specs if they haven't been allocated already. */
if ( _cur_grffile - > housespec = = NULL ) {
_cur_grffile - > housespec = CallocT < HouseSpec * > ( HOUSE_MAX ) ;
}
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
HouseSpec * housespec = _cur_grffile - > housespec [ hid + i ] ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
if ( prop ! = 0x08 & & housespec = = NULL ) {
grfmsg ( 2 , " TownHouseChangeInfo: Attempt to modify undefined house %u. Ignoring. " , hid + i ) ;
continue ;
2007-03-19 11:27:30 +00:00
}
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : { // Substitute building type, and definition of a new house
HouseSpec * * house = & _cur_grffile - > housespec [ hid + i ] ;
2007-03-19 11:27:30 +00:00
byte subs_id = grf_load_byte ( & buf ) ;
if ( subs_id = = 0xFF ) {
/* Instead of defining a new house, a substitute house id
* of 0xFF disables the old house with the current id . */
_house_specs [ hid + i ] . enabled = false ;
continue ;
} else if ( subs_id > = NEW_HOUSE_OFFSET ) {
/* The substitute id must be one of the original houses. */
grfmsg ( 2 , " TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring. " , subs_id , hid + i ) ;
return false ;
}
/* Allocate space for this house. */
2007-07-04 12:52:43 +00:00
if ( * house = = NULL ) * house = CallocT < HouseSpec > ( 1 ) ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
housespec = * house ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
memcpy ( housespec , & _house_specs [ subs_id ] , sizeof ( _house_specs [ subs_id ] ) ) ;
housespec - > enabled = true ;
housespec - > local_id = hid + i ;
housespec - > substitute_id = subs_id ;
housespec - > grffile = _cur_grffile ;
housespec - > random_colour [ 0 ] = 0x04 ; // those 4 random colours are the base colour
housespec - > random_colour [ 1 ] = 0x08 ; // for all new houses
housespec - > random_colour [ 2 ] = 0x0C ; // they stand for red, blue, orange and green
housespec - > random_colour [ 3 ] = 0x06 ;
2007-03-19 11:27:30 +00:00
2007-08-10 08:57:04 +00:00
/* Make sure that the third cargo type is valid in this
* climate . This can cause problems when copying the properties
* of a house that accepts food , where the new house is valid
* in the temperate climate . */
if ( ! GetCargo ( housespec - > accepts_cargo [ 2 ] ) - > IsValid ( ) ) {
housespec - > cargo_acceptance [ 2 ] = 0 ;
}
2007-07-04 13:30:33 +00:00
/**
* New houses do not ( currently ) expect to have a default start
* date before 1930 , as this breaks the build date stuff .
* @ see FinaliseHouseArray ( ) for more details .
*/
2008-06-03 03:06:16 +00:00
if ( housespec - > min_year < 1930 ) housespec - > min_year = 1930 ;
2007-07-04 12:52:43 +00:00
_loaded_newgrf_features . has_newhouses = true ;
} break ;
case 0x09 : // Building flags
housespec - > building_flags = ( BuildingFlags ) grf_load_byte ( & buf ) ;
break ;
case 0x0A : { // Availability years
2007-03-19 11:27:30 +00:00
uint16 years = grf_load_word ( & buf ) ;
2008-06-03 03:06:16 +00:00
housespec - > min_year = GB ( years , 0 , 8 ) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB ( years , 0 , 8 ) ;
housespec - > max_year = GB ( years , 8 , 8 ) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB ( years , 8 , 8 ) ;
2007-07-04 12:52:43 +00:00
} break ;
case 0x0B : // Population
housespec - > population = grf_load_byte ( & buf ) ;
break ;
case 0x0C : // Mail generation multiplier
housespec - > mail_generation = grf_load_byte ( & buf ) ;
break ;
case 0x0D : // Passenger acceptance
case 0x0E : // Mail acceptance
housespec - > cargo_acceptance [ prop - 0x0D ] = grf_load_byte ( & buf ) ;
break ;
case 0x0F : { // Goods/candy, food/fizzy drinks acceptance
2007-03-19 11:27:30 +00:00
int8 goods = grf_load_byte ( & buf ) ;
2007-03-20 02:24:14 +00:00
/* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance.
* Else , we have " standard " 3 rd cargo type , goods or candy , for toyland once more */
2008-05-29 15:13:28 +00:00
CargoID cid = ( goods > = 0 ) ? ( ( _settings_game . game_creation . landscape = = LT_TOYLAND ) ? CT_CANDY : CT_GOODS ) :
( ( _settings_game . game_creation . landscape = = LT_TOYLAND ) ? CT_FIZZY_DRINKS : CT_FOOD ) ;
2007-03-20 02:24:14 +00:00
2007-08-10 08:57:04 +00:00
/* Make sure the cargo type is valid in this climate. */
if ( ! GetCargo ( cid ) - > IsValid ( ) ) goods = 0 ;
housespec - > accepts_cargo [ 2 ] = cid ;
2007-07-04 12:52:43 +00:00
housespec - > cargo_acceptance [ 2 ] = abs ( goods ) ; // but we do need positive value here
} break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x10 : // Local authority rating decrease on removal
housespec - > remove_rating_decrease = grf_load_word ( & buf ) ;
break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x11 : // Removal cost multiplier
housespec - > removal_cost = grf_load_byte ( & buf ) ;
break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x12 : // Building name ID
2008-04-17 11:47:22 +00:00
housespec - > building_name = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & housespec - > building_name ] = _cur_grffile - > grfid ;
2007-07-04 12:52:43 +00:00
break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x13 : // Building availability mask
housespec - > building_availability = ( HouseZones ) grf_load_word ( & buf ) ;
break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x14 : // House callback flags
housespec - > callback_mask = grf_load_byte ( & buf ) ;
break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x15 : { // House override byte
2007-03-19 11:27:30 +00:00
byte override = grf_load_byte ( & buf ) ;
/* The house being overridden must be an original house. */
if ( override > = NEW_HOUSE_OFFSET ) {
2007-07-04 12:57:07 +00:00
grfmsg ( 2 , " TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring. " , override , hid + i ) ;
2007-07-04 12:52:43 +00:00
continue ;
2007-03-19 11:27:30 +00:00
}
2007-11-12 20:40:58 +00:00
_house_mngr . Add ( hid + i , _cur_grffile - > grfid , override ) ;
2007-07-04 12:52:43 +00:00
} break ;
case 0x16 : // Periodic refresh multiplier
housespec - > processing_time = grf_load_byte ( & buf ) ;
break ;
case 0x17 : // Four random colours to use
for ( uint j = 0 ; j < 4 ; j + + ) housespec - > random_colour [ j ] = grf_load_byte ( & buf ) ;
break ;
case 0x18 : // Relative probability of appearing
housespec - > probability = grf_load_byte ( & buf ) ;
break ;
case 0x19 : // Extra flags
housespec - > extra_flags = ( HouseExtraFlags ) grf_load_byte ( & buf ) ;
break ;
case 0x1A : // Animation frames
housespec - > animation_frames = grf_load_byte ( & buf ) ;
break ;
case 0x1B : // Animation speed
2007-11-19 18:38:10 +00:00
housespec - > animation_speed = Clamp ( grf_load_byte ( & buf ) , 2 , 16 ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x1C : // Class of the building type
housespec - > class_id = AllocateHouseClassID ( grf_load_byte ( & buf ) , _cur_grffile - > grfid ) ;
break ;
case 0x1D : // Callback flags 2
housespec - > callback_mask | = ( grf_load_byte ( & buf ) < < 8 ) ;
break ;
case 0x1E : { // Accepted cargo types
2007-04-13 21:18:48 +00:00
uint32 cargotypes = grf_load_dword ( & buf ) ;
/* Check if the cargo types should not be changed */
if ( cargotypes = = 0xFFFFFFFF ) break ;
for ( uint j = 0 ; j < 3 ; j + + ) {
/* Get the cargo number from the 'list' */
uint8 cargo_part = GB ( cargotypes , 8 * j , 8 ) ;
CargoID cargo = GetCargoTranslation ( cargo_part , _cur_grffile ) ;
if ( cargo = = CT_INVALID ) {
/* Disable acceptance of invalid cargo type */
2007-07-04 12:52:43 +00:00
housespec - > cargo_acceptance [ j ] = 0 ;
2007-04-13 21:18:48 +00:00
} else {
2007-07-04 12:52:43 +00:00
housespec - > accepts_cargo [ j ] = cargo ;
2007-04-13 21:18:48 +00:00
}
}
2007-07-04 12:52:43 +00:00
} break ;
2007-03-19 11:27:30 +00:00
2007-07-04 12:52:43 +00:00
case 0x1F : // Minimum life span
housespec - > minimum_life = grf_load_byte ( & buf ) ;
break ;
2007-05-10 16:03:06 +00:00
2007-10-25 23:24:28 +00:00
case 0x20 : { // @todo Cargo acceptance watch list
byte count = grf_load_byte ( & buf ) ;
for ( byte j = 0 ; j < count ; j + + ) grf_load_byte ( & buf ) ;
ret = true ;
} break ;
2008-06-10 00:42:19 +00:00
case 0x21 : // long introduction year
housespec - > min_year = grf_load_word ( & buf ) ;
break ;
case 0x22 : // long maximum year
housespec - > max_year = grf_load_word ( & buf ) ;
break ;
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2007-03-19 11:27:30 +00:00
}
* bufp = buf ;
return ret ;
}
2005-10-12 07:27:56 +00:00
static bool GlobalVarChangeInfo ( uint gvid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
switch ( prop ) {
2007-07-04 13:30:33 +00:00
case 0x08 : { // Cost base factor
2005-10-12 07:27:56 +00:00
byte factor = grf_load_byte ( & buf ) ;
2005-10-12 09:54:29 +00:00
uint price = gvid + i ;
2005-10-12 07:27:56 +00:00
2005-10-12 09:54:29 +00:00
if ( price < NUM_PRICES ) {
SetPriceBaseMultiplier ( price , factor ) ;
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GlobalVarChangeInfo: Price %d out of range, ignoring " , price ) ;
2005-10-12 09:54:29 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-04-11 10:53:07 +00:00
2008-02-03 20:23:59 +00:00
case 0x09 : // Cargo translation table
/* This is loaded during the reservation stage, so just skip it here. */
/* Each entry is 4 bytes. */
buf + = 4 ;
break ;
2007-02-24 19:36:47 +00:00
2007-07-04 12:52:43 +00:00
case 0x0A : { // Currency display names
2006-09-20 00:34:06 +00:00
uint curidx = GetNewgrfCurrencyIdConverted ( gvid + i ) ;
StringID newone = GetGRFStringID ( _cur_grffile - > grfid , grf_load_word ( & buf ) ) ;
2006-08-25 00:41:10 +00:00
2006-09-01 02:56:02 +00:00
if ( ( newone ! = STR_UNDEFINED ) & & ( curidx < NUM_CURRENCY ) ) {
_currency_specs [ curidx ] . name = newone ;
2006-08-25 00:41:10 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-08-25 00:41:10 +00:00
2007-07-04 12:52:43 +00:00
case 0x0B : { // Currency multipliers
2006-09-20 00:34:06 +00:00
uint curidx = GetNewgrfCurrencyIdConverted ( gvid + i ) ;
2006-08-25 00:41:10 +00:00
uint32 rate = grf_load_dword ( & buf ) ;
if ( curidx < NUM_CURRENCY ) {
2006-09-15 02:52:17 +00:00
/* TTDPatch uses a multiple of 1000 for its conversion calculations,
* which OTTD does not . For this reason , divide grf value by 1000 ,
* to be compatible */
_currency_specs [ curidx ] . rate = rate / 1000 ;
2006-08-25 00:41:10 +00:00
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring " , curidx ) ;
2006-08-25 00:41:10 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-08-25 00:41:10 +00:00
2007-07-04 12:52:43 +00:00
case 0x0C : { // Currency options
2006-09-20 00:34:06 +00:00
uint curidx = GetNewgrfCurrencyIdConverted ( gvid + i ) ;
2006-08-25 00:41:10 +00:00
uint16 options = grf_load_word ( & buf ) ;
if ( curidx < NUM_CURRENCY ) {
_currency_specs [ curidx ] . separator = GB ( options , 0 , 8 ) ;
2006-09-15 02:52:17 +00:00
/* By specifying only one bit, we prevent errors,
* since newgrf specs said that only 0 and 1 can be set for symbol_pos */
_currency_specs [ curidx ] . symbol_pos = GB ( options , 8 , 1 ) ;
2006-08-25 00:41:10 +00:00
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GlobalVarChangeInfo: Currency option %d out of range, ignoring " , curidx ) ;
2006-08-25 00:41:10 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-08-25 00:41:10 +00:00
2007-07-04 12:52:43 +00:00
case 0x0D : { // Currency prefix symbol
2006-09-20 00:34:06 +00:00
uint curidx = GetNewgrfCurrencyIdConverted ( gvid + i ) ;
2006-08-25 00:41:10 +00:00
uint32 tempfix = grf_load_dword ( & buf ) ;
if ( curidx < NUM_CURRENCY ) {
2007-07-04 13:30:33 +00:00
memcpy ( _currency_specs [ curidx ] . prefix , & tempfix , 4 ) ;
2006-08-25 00:41:10 +00:00
_currency_specs [ curidx ] . prefix [ 4 ] = 0 ;
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GlobalVarChangeInfo: Currency symbol %d out of range, ignoring " , curidx ) ;
2006-08-25 00:41:10 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-08-25 00:41:10 +00:00
2007-07-04 12:52:43 +00:00
case 0x0E : { // Currency suffix symbol
2006-09-20 00:34:06 +00:00
uint curidx = GetNewgrfCurrencyIdConverted ( gvid + i ) ;
2006-08-25 00:41:10 +00:00
uint32 tempfix = grf_load_dword ( & buf ) ;
if ( curidx < NUM_CURRENCY ) {
2007-04-18 22:10:36 +00:00
memcpy ( & _currency_specs [ curidx ] . suffix , & tempfix , 4 ) ;
2006-08-25 00:41:10 +00:00
_currency_specs [ curidx ] . suffix [ 4 ] = 0 ;
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GlobalVarChangeInfo: Currency symbol %d out of range, ignoring " , curidx ) ;
2006-08-25 00:41:10 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-08-25 00:41:10 +00:00
2007-07-04 12:52:43 +00:00
case 0x0F : { // Euro introduction dates
2006-09-20 00:34:06 +00:00
uint curidx = GetNewgrfCurrencyIdConverted ( gvid + i ) ;
2006-08-25 00:41:10 +00:00
Year year_euro = grf_load_word ( & buf ) ;
if ( curidx < NUM_CURRENCY ) {
_currency_specs [ curidx ] . to_euro = year_euro ;
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GlobalVarChangeInfo: Euro intro date %d out of range, ignoring " , curidx ) ;
2006-08-25 00:41:10 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2007-07-04 13:30:33 +00:00
case 0x10 : // Snow line height table
2007-07-04 12:52:43 +00:00
if ( numinfo > 1 | | IsSnowLineSet ( ) ) {
grfmsg ( 1 , " GlobalVarChangeInfo: The snowline can only be set once (%d) " , numinfo ) ;
} else if ( len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS ) {
grfmsg ( 1 , " GlobalVarChangeInfo: Not enough entries set in the snowline table (%d) " , len ) ;
} else {
byte table [ SNOW_LINE_MONTHS ] [ SNOW_LINE_DAYS ] ;
for ( uint i = 0 ; i < SNOW_LINE_MONTHS ; i + + ) {
for ( uint j = 0 ; j < SNOW_LINE_DAYS ; j + + ) {
table [ i ] [ j ] = grf_load_byte ( & buf ) ;
}
2007-03-20 13:47:00 +00:00
}
2007-07-04 12:52:43 +00:00
SetSnowLine ( table ) ;
2007-03-20 13:47:00 +00:00
}
2007-07-04 12:52:43 +00:00
break ;
2007-03-20 13:47:00 +00:00
2008-04-29 21:31:29 +00:00
case 0x11 : // GRF match for engine allocation
/* This is loaded during the reservation stage, so just skip it here. */
/* Each entry is 8 bytes. */
buf + = 8 ;
break ;
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2005-10-12 07:27:56 +00:00
}
2006-04-11 10:53:07 +00:00
2005-10-12 07:27:56 +00:00
* bufp = buf ;
return ret ;
}
2007-03-22 23:19:40 +00:00
static bool CargoChangeInfo ( uint cid , int numinfo , int prop , byte * * bufp , int len )
{
2007-07-04 12:52:43 +00:00
byte * buf = * bufp ;
bool ret = false ;
2007-03-22 23:19:40 +00:00
if ( cid + numinfo > NUM_CARGO ) {
grfmsg ( 2 , " CargoChangeInfo: Cargo type %d out of range (max %d) " , cid + numinfo , NUM_CARGO - 1 ) ;
return false ;
}
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
CargoSpec * cs = & _cargo [ cid + i ] ;
2007-03-22 23:19:40 +00:00
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : /* Bit number of cargo */
cs - > bitnum = grf_load_byte ( & buf ) ;
2007-03-22 23:19:40 +00:00
if ( cs - > IsValid ( ) ) {
2008-07-30 18:23:12 +00:00
cs - > grffile = _cur_grffile ;
2007-11-20 13:35:54 +00:00
SetBit ( _cargo_mask , cid + i ) ;
2007-03-22 23:19:40 +00:00
} else {
2007-11-19 21:32:20 +00:00
ClrBit ( _cargo_mask , cid + i ) ;
2007-03-22 23:19:40 +00:00
}
2007-07-04 12:52:43 +00:00
break ;
case 0x09 : /* String ID for cargo type name */
2008-04-17 11:47:22 +00:00
cs - > name = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & cs - > name ] = _cur_grffile - > grfid ;
2007-07-04 12:52:43 +00:00
break ;
2007-07-17 20:32:27 +00:00
case 0x0A : /* String for 1 unit of cargo */
2008-04-17 11:47:22 +00:00
cs - > name_single = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & cs - > name_single ] = _cur_grffile - > grfid ;
2007-07-04 12:52:43 +00:00
break ;
case 0x0B :
/* String for units of cargo. This is different in OpenTTD to TTDPatch
* ( e . g . 10 tonnes of coal ) */
2008-04-17 11:47:22 +00:00
cs - > units_volume = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & cs - > units_volume ] = _cur_grffile - > grfid ;
2007-07-04 12:52:43 +00:00
break ;
case 0x0C : /* String for quantity of cargo (e.g. 10 tonnes of coal) */
2008-04-17 11:47:22 +00:00
cs - > quantifier = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & cs - > quantifier ] = _cur_grffile - > grfid ;
2007-07-04 12:52:43 +00:00
break ;
case 0x0D : /* String for two letter cargo abbreviation */
2008-04-17 11:47:22 +00:00
cs - > abbrev = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & cs - > abbrev ] = _cur_grffile - > grfid ;
2007-07-04 12:52:43 +00:00
break ;
case 0x0E : /* Sprite ID for cargo icon */
cs - > sprite = grf_load_word ( & buf ) ;
break ;
case 0x0F : /* Weight of one unit of cargo */
cs - > weight = grf_load_byte ( & buf ) ;
break ;
case 0x10 : /* Used for payment calculation */
cs - > transit_days [ 0 ] = grf_load_byte ( & buf ) ;
break ;
case 0x11 : /* Used for payment calculation */
cs - > transit_days [ 1 ] = grf_load_byte ( & buf ) ;
break ;
case 0x12 : /* Base cargo price */
cs - > initial_payment = grf_load_dword ( & buf ) ;
break ;
case 0x13 : /* Colour for station rating bars */
cs - > rating_colour = MapDOSColour ( grf_load_byte ( & buf ) ) ;
break ;
case 0x14 : /* Colour for cargo graph */
cs - > legend_colour = MapDOSColour ( grf_load_byte ( & buf ) ) ;
break ;
case 0x15 : /* Freight status */
2007-07-04 13:30:33 +00:00
cs - > is_freight = ( grf_load_byte ( & buf ) ! = 0 ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x16 : /* Cargo classes */
cs - > classes = grf_load_word ( & buf ) ;
break ;
case 0x17 : /* Cargo label */
cs - > label = grf_load_dword ( & buf ) ;
cs - > label = BSWAP32 ( cs - > label ) ;
break ;
case 0x18 : { /* Town growth substitute type */
2007-03-22 23:19:40 +00:00
uint8 substitute_type = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
2007-03-22 23:19:40 +00:00
switch ( substitute_type ) {
2007-07-04 12:52:43 +00:00
case 0x00 : cs - > town_effect = TE_PASSENGERS ; break ;
case 0x02 : cs - > town_effect = TE_MAIL ; break ;
case 0x05 : cs - > town_effect = TE_GOODS ; break ;
case 0x09 : cs - > town_effect = TE_WATER ; break ;
case 0x0B : cs - > town_effect = TE_FOOD ; break ;
2007-03-22 23:19:40 +00:00
default :
grfmsg ( 1 , " CargoChangeInfo: Unknown town growth substitute value %d, setting to none. " , substitute_type ) ;
2007-07-04 12:52:43 +00:00
case 0xFF : cs - > town_effect = TE_NONE ; break ;
2007-03-22 23:19:40 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2007-03-22 23:19:40 +00:00
2007-07-04 12:52:43 +00:00
case 0x19 : /* Town growth coefficient */
cs - > multipliertowngrowth = grf_load_word ( & buf ) ;
break ;
2007-03-22 23:19:40 +00:00
2007-07-04 12:52:43 +00:00
case 0x1A : /* Bitmask of callbacks to use */
cs - > callback_mask = grf_load_byte ( & buf ) ;
break ;
2007-03-22 23:19:40 +00:00
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2007-03-22 23:19:40 +00:00
}
* bufp = buf ;
return ret ;
}
2006-09-27 18:17:01 +00:00
static bool SoundEffectChangeInfo ( uint sid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
if ( _cur_grffile - > sound_offset = = 0 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " SoundEffectChangeInfo: No effects defined, skipping " ) ;
2006-09-27 18:17:01 +00:00
return false ;
}
2007-07-04 12:52:43 +00:00
for ( int i = 0 ; i < numinfo ; i + + ) {
uint sound = sid + i + _cur_grffile - > sound_offset - GetNumOriginalSounds ( ) ;
2006-09-27 18:17:01 +00:00
2007-07-04 12:52:43 +00:00
if ( sound > = GetNumSounds ( ) ) {
grfmsg ( 1 , " SoundEffectChangeInfo: Sound %d not defined (max %d) " , sound , GetNumSounds ( ) ) ;
continue ;
}
2006-09-27 18:17:01 +00:00
2007-07-04 12:52:43 +00:00
switch ( prop ) {
case 0x08 : // Relative volume
GetSound ( sound ) - > volume = grf_load_byte ( & buf ) ;
break ;
2006-09-27 18:17:01 +00:00
2007-07-04 12:52:43 +00:00
case 0x09 : // Priority
GetSound ( sound ) - > priority = grf_load_byte ( & buf ) ;
break ;
2006-09-27 18:17:01 +00:00
2007-07-04 12:52:43 +00:00
case 0x0A : { // Override old sound
2006-09-27 18:17:01 +00:00
uint orig_sound = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
if ( orig_sound > = GetNumSounds ( ) ) {
grfmsg ( 1 , " SoundEffectChangeInfo: Original sound %d not defined (max %d) " , orig_sound , GetNumSounds ( ) ) ;
2006-09-27 18:17:01 +00:00
} else {
FileEntry * newfe = GetSound ( sound ) ;
FileEntry * oldfe = GetSound ( orig_sound ) ;
/* Literally copy the data of the new sound over the original */
2006-11-05 08:24:52 +00:00
* oldfe = * newfe ;
2006-09-27 18:17:01 +00:00
}
2007-07-04 12:52:43 +00:00
} break ;
2006-09-27 18:17:01 +00:00
2007-07-04 12:52:43 +00:00
default :
ret = true ;
break ;
}
2006-09-27 18:17:01 +00:00
}
* bufp = buf ;
return ret ;
}
2007-07-10 00:10:19 +00:00
static bool IndustrytilesChangeInfo ( uint indtid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
if ( indtid + numinfo > NUM_INDUSTRYTILES ) {
grfmsg ( 1 , " IndustryTilesChangeInfo: Too many industry tiles loaded (%u), max (%u). Ignoring. " , indtid + numinfo , NUM_INDUSTRYTILES ) ;
return false ;
}
/* Allocate industry tile specs if they haven't been allocated already. */
if ( _cur_grffile - > indtspec = = NULL ) {
_cur_grffile - > indtspec = CallocT < IndustryTileSpec * > ( NUM_INDUSTRYTILES ) ;
}
for ( int i = 0 ; i < numinfo ; i + + ) {
IndustryTileSpec * tsp = _cur_grffile - > indtspec [ indtid + i ] ;
if ( prop ! = 0x08 & & tsp = = NULL ) {
grfmsg ( 2 , " IndustryTilesChangeInfo: Attempt to modify undefined industry tile %u. Ignoring. " , indtid + i ) ;
continue ;
}
switch ( prop ) {
case 0x08 : { // Substitute industry tile type
IndustryTileSpec * * tilespec = & _cur_grffile - > indtspec [ indtid + i ] ;
byte subs_id = grf_load_byte ( & buf ) ;
2007-08-21 00:29:10 +00:00
if ( subs_id > = NEW_INDUSTRYTILEOFFSET ) {
2007-07-10 00:10:19 +00:00
/* The substitute id must be one of the original industry tile. */
grfmsg ( 2 , " IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring. " , subs_id , indtid + i ) ;
return false ;
}
/* Allocate space for this industry. */
if ( * tilespec = = NULL ) {
int tempid ;
* tilespec = CallocT < IndustryTileSpec > ( 1 ) ;
tsp = * tilespec ;
memcpy ( tsp , & _industry_tile_specs [ subs_id ] , sizeof ( _industry_tile_specs [ subs_id ] ) ) ;
tsp - > enabled = true ;
2007-12-18 21:25:44 +00:00
/* A copied tile should not have the animation infos copied too.
* The anim_state should be left untouched , though
* It is up to the author to animate them himself */
tsp - > anim_production = INDUSTRYTILE_NOANIM ;
tsp - > anim_next = INDUSTRYTILE_NOANIM ;
2007-07-10 00:10:19 +00:00
tsp - > grf_prop . local_id = indtid + i ;
tsp - > grf_prop . subst_id = subs_id ;
tsp - > grf_prop . grffile = _cur_grffile ;
tempid = _industile_mngr . AddEntityID ( indtid + i , _cur_grffile - > grfid , subs_id ) ; // pre-reserve the tile slot
}
} break ;
case 0x09 : { // Industry tile override
byte ovrid = grf_load_byte ( & buf ) ;
/* The industry being overridden must be an original industry. */
if ( ovrid > = NEW_INDUSTRYTILEOFFSET ) {
grfmsg ( 2 , " IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring. " , ovrid , indtid + i ) ;
return false ;
}
2007-11-12 20:40:58 +00:00
_industile_mngr . Add ( indtid + i , _cur_grffile - > grfid , ovrid ) ;
2007-07-10 00:10:19 +00:00
} break ;
case 0x0A : // Tile acceptance
case 0x0B :
case 0x0C : {
uint16 acctp = grf_load_word ( & buf ) ;
2007-12-01 02:47:10 +00:00
tsp - > accepts_cargo [ prop - 0x0A ] = GetCargoTranslation ( GB ( acctp , 0 , 8 ) , _cur_grffile ) ;
2007-09-26 02:11:30 +00:00
tsp - > acceptance [ prop - 0x0A ] = GB ( acctp , 8 , 8 ) ;
2007-07-10 00:10:19 +00:00
} break ;
case 0x0D : // Land shape flags
tsp - > slopes_refused = ( Slope ) grf_load_byte ( & buf ) ;
break ;
case 0x0E : // Callback flags
tsp - > callback_flags = grf_load_byte ( & buf ) ;
break ;
case 0x0F : // Animation information
2007-07-11 15:03:29 +00:00
tsp - > animation_info = grf_load_word ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
case 0x10 : // Animation speed
2007-07-11 15:03:29 +00:00
tsp - > animation_speed = grf_load_byte ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
case 0x11 : // Triggers for callback 25
2007-07-11 15:03:29 +00:00
tsp - > animation_triggers = grf_load_byte ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
case 0x12 : // Special flags
2007-07-11 15:03:29 +00:00
tsp - > animation_special_flags = grf_load_byte ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
default :
ret = true ;
break ;
}
}
* bufp = buf ;
return ret ;
}
static bool IndustriesChangeInfo ( uint indid , int numinfo , int prop , byte * * bufp , int len )
{
byte * buf = * bufp ;
bool ret = false ;
if ( indid + numinfo > NUM_INDUSTRYTYPES ) {
grfmsg ( 1 , " IndustriesChangeInfo: Too many industries loaded (%u), max (%u). Ignoring. " , indid + numinfo , NUM_INDUSTRYTYPES ) ;
return false ;
}
grfmsg ( 1 , " IndustriesChangeInfo: newid %u " , indid ) ;
/* Allocate industry specs if they haven't been allocated already. */
if ( _cur_grffile - > industryspec = = NULL ) {
_cur_grffile - > industryspec = CallocT < IndustrySpec * > ( NUM_INDUSTRYTYPES ) ;
}
for ( int i = 0 ; i < numinfo ; i + + ) {
IndustrySpec * indsp = _cur_grffile - > industryspec [ indid + i ] ;
if ( prop ! = 0x08 & & indsp = = NULL ) {
grfmsg ( 2 , " IndustriesChangeInfo: Attempt to modify undefined industry %u. Ignoring. " , indid + i ) ;
continue ;
}
switch ( prop ) {
case 0x08 : { // Substitute industry type
IndustrySpec * * indspec = & _cur_grffile - > industryspec [ indid + i ] ;
byte subs_id = grf_load_byte ( & buf ) ;
if ( subs_id = = 0xFF ) {
/* Instead of defining a new industry, a substitute industry id
* of 0xFF disables the old industry with the current id . */
_industry_specs [ indid + i ] . enabled = false ;
continue ;
} else if ( subs_id > = NEW_INDUSTRYOFFSET ) {
/* The substitute id must be one of the original industry. */
grfmsg ( 2 , " _industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring. " , subs_id , indid + i ) ;
return false ;
}
/* Allocate space for this industry.
* Only need to do it once . If ever it is called again , it should not
* do anything */
if ( * indspec = = NULL ) {
* indspec = CallocT < IndustrySpec > ( 1 ) ;
indsp = * indspec ;
memcpy ( indsp , & _origin_industry_specs [ subs_id ] , sizeof ( _industry_specs [ subs_id ] ) ) ;
indsp - > enabled = true ;
indsp - > grf_prop . local_id = indid + i ;
indsp - > grf_prop . subst_id = subs_id ;
indsp - > grf_prop . grffile = _cur_grffile ;
2007-10-13 00:49:13 +00:00
/* If the grf industry needs to check its surounding upon creation, it should
* rely on callbacks , not on the original placement functions */
indsp - > check_proc = CHECK_NOTHING ;
2007-07-10 00:10:19 +00:00
}
} break ;
case 0x09 : { // Industry type override
byte ovrid = grf_load_byte ( & buf ) ;
/* The industry being overridden must be an original industry. */
if ( ovrid > = NEW_INDUSTRYOFFSET ) {
grfmsg ( 2 , " IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring. " , ovrid , indid + i ) ;
return false ;
}
indsp - > grf_prop . override = ovrid ;
2007-11-12 20:40:58 +00:00
_industry_mngr . Add ( indid + i , _cur_grffile - > grfid , ovrid ) ;
2007-07-10 00:10:19 +00:00
} break ;
case 0x0A : { // Set industry layout(s)
indsp - > num_table = grf_load_byte ( & buf ) ; // Number of layaouts
uint32 defsize = grf_load_dword ( & buf ) ; // Total size of the definition
IndustryTileTable * * tile_table = CallocT < IndustryTileTable * > ( indsp - > num_table ) ; // Table with tiles to compose an industry
IndustryTileTable * itt = CallocT < IndustryTileTable > ( defsize ) ; // Temporary array to read the tile layouts from the GRF
int size ;
IndustryTileTable * copy_from ;
for ( byte j = 0 ; j < indsp - > num_table ; j + + ) {
for ( int k = 0 ; ; k + + ) {
itt [ k ] . ti . x = grf_load_byte ( & buf ) ; // Offsets from northermost tile
if ( itt [ k ] . ti . x = = 0xFE & & k = = 0 ) {
/* This means we have to borrow the layout from an old industry */
IndustryType type = grf_load_byte ( & buf ) ; //industry holding required layout
byte laynbr = grf_load_byte ( & buf ) ; //layout number to borrow
copy_from = ( IndustryTileTable * ) _origin_industry_specs [ type ] . table [ laynbr ] ;
for ( size = 1 ; ; size + + ) {
2007-10-17 02:50:18 +00:00
if ( copy_from [ size - 1 ] . ti . x = = - 0x80 & & copy_from [ size - 1 ] . ti . y = = 0 ) break ;
2007-07-10 00:10:19 +00:00
}
break ;
}
itt [ k ] . ti . y = grf_load_byte ( & buf ) ; // Or table definition finalisation
if ( itt [ k ] . ti . x = = 0 & & itt [ k ] . ti . y = = 0x80 ) {
/* Not the same terminator. The one we are using is rather
x = - 80 , y = x . So , adjust it . */
itt [ k ] . ti . x = - 0x80 ;
itt [ k ] . ti . y = 0 ;
itt [ k ] . gfx = 0 ;
size = k + 1 ;
copy_from = itt ;
break ;
}
itt [ k ] . gfx = grf_load_byte ( & buf ) ;
if ( itt [ k ] . gfx = = 0xFE ) {
/* Use a new tile from this GRF */
int local_tile_id = grf_load_word ( & buf ) ;
/* Read the ID from the _industile_mngr. */
int tempid = _industile_mngr . GetID ( local_tile_id , _cur_grffile - > grfid ) ;
if ( tempid = = INVALID_INDUSTRYTILE ) {
grfmsg ( 2 , " IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring. " , local_tile_id , indid ) ;
} else {
/* Declared as been valid, can be used */
itt [ k ] . gfx = tempid ;
size = k + 1 ;
copy_from = itt ;
}
2007-09-26 01:27:51 +00:00
} else if ( itt [ k ] . gfx = = 0xFF ) {
itt [ k ] . ti . x = ( int8 ) GB ( itt [ k ] . ti . x , 0 , 8 ) ;
itt [ k ] . ti . y = ( int8 ) GB ( itt [ k ] . ti . y , 0 , 8 ) ;
2007-09-26 02:20:58 +00:00
}
2007-07-10 00:10:19 +00:00
}
tile_table [ j ] = CallocT < IndustryTileTable > ( size ) ;
memcpy ( tile_table [ j ] , copy_from , sizeof ( * copy_from ) * size ) ;
}
/* Install final layout construction in the industry spec */
indsp - > table = tile_table ;
2007-11-20 13:35:54 +00:00
SetBit ( indsp - > cleanup_flag , 1 ) ;
2007-07-10 00:10:19 +00:00
free ( itt ) ;
} break ;
case 0x0B : // Industry production flags
indsp - > life_type = ( IndustryLifeType ) grf_load_byte ( & buf ) ;
break ;
case 0x0C : // Industry closure message
2008-04-17 11:47:22 +00:00
indsp - > closure_text = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & indsp - > closure_text ] = _cur_grffile - > grfid ;
2007-07-10 00:10:19 +00:00
break ;
case 0x0D : // Production increase message
2008-04-17 11:47:22 +00:00
indsp - > production_up_text = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & indsp - > production_up_text ] = _cur_grffile - > grfid ;
2007-07-10 00:10:19 +00:00
break ;
case 0x0E : // Production decrease message
2008-04-17 11:47:22 +00:00
indsp - > production_down_text = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & indsp - > production_down_text ] = _cur_grffile - > grfid ;
2007-07-10 00:10:19 +00:00
break ;
case 0x0F : // Fund cost multiplier
indsp - > cost_multiplier = grf_load_byte ( & buf ) ;
break ;
case 0x10 : // Production cargo types
for ( byte j = 0 ; j < 2 ; j + + ) {
2007-12-01 02:47:10 +00:00
indsp - > produced_cargo [ j ] = GetCargoTranslation ( grf_load_byte ( & buf ) , _cur_grffile ) ;
2007-07-10 00:10:19 +00:00
}
break ;
case 0x11 : // Acceptance cargo types
for ( byte j = 0 ; j < 3 ; j + + ) {
2007-12-01 02:47:10 +00:00
indsp - > accepts_cargo [ j ] = GetCargoTranslation ( grf_load_byte ( & buf ) , _cur_grffile ) ;
2007-07-10 00:10:19 +00:00
}
grf_load_byte ( & buf ) ; // Unnused, eat it up
break ;
case 0x12 : // Production multipliers
case 0x13 :
indsp - > production_rate [ prop - 0x12 ] = grf_load_byte ( & buf ) ;
break ;
case 0x14 : // Minimal amount of cargo distributed
indsp - > minimal_cargo = grf_load_byte ( & buf ) ;
break ;
case 0x15 : { // Random sound effects
indsp - > number_of_sounds = grf_load_byte ( & buf ) ;
uint8 * sounds = MallocT < uint8 > ( indsp - > number_of_sounds ) ;
for ( uint8 j = 0 ; j < indsp - > number_of_sounds ; j + + ) sounds [ j ] = grf_load_byte ( & buf ) ;
indsp - > random_sounds = sounds ;
2007-11-20 13:35:54 +00:00
SetBit ( indsp - > cleanup_flag , 0 ) ;
2007-07-10 00:10:19 +00:00
} break ;
case 0x16 : // Conflicting industry types
for ( byte j = 0 ; j < 3 ; j + + ) indsp - > conflicting [ j ] = grf_load_byte ( & buf ) ;
break ;
case 0x17 : // Probability in random game
2008-05-29 15:13:28 +00:00
indsp - > appear_creation [ _settings_game . game_creation . landscape ] = grf_load_byte ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
case 0x18 : // Probability during gameplay
2008-05-29 15:13:28 +00:00
indsp - > appear_ingame [ _settings_game . game_creation . landscape ] = grf_load_byte ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
case 0x19 : // Map color
indsp - > map_colour = MapDOSColour ( grf_load_byte ( & buf ) ) ;
break ;
case 0x1A : // Special industry flags to define special behavior
2007-10-19 21:14:38 +00:00
indsp - > behaviour = ( IndustryBehaviour ) grf_load_dword ( & buf ) ;
2007-07-10 00:10:19 +00:00
break ;
case 0x1B : // New industry text ID
2008-04-17 11:47:22 +00:00
indsp - > new_industry_text = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & indsp - > new_industry_text ] = _cur_grffile - > grfid ;
2007-07-10 00:10:19 +00:00
break ;
case 0x1C : // Input cargo multipliers for the three input cargo types
case 0x1D :
case 0x1E : {
uint32 multiples = grf_load_dword ( & buf ) ;
2008-04-18 04:37:06 +00:00
indsp - > input_cargo_multiplier [ prop - 0x1C ] [ 0 ] = GB ( multiples , 0 , 15 ) ;
indsp - > input_cargo_multiplier [ prop - 0x1C ] [ 1 ] = GB ( multiples , 15 , 15 ) ;
2007-07-10 00:10:19 +00:00
} break ;
case 0x1F : // Industry name
2008-04-17 11:47:22 +00:00
indsp - > name = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & indsp - > name ] = _cur_grffile - > grfid ;
2007-07-10 00:10:19 +00:00
break ;
case 0x20 : // Prospecting success chance
indsp - > prospecting_chance = grf_load_dword ( & buf ) ;
break ;
case 0x21 : // Callback flags
case 0x22 : { // Callback additional flags
byte aflag = grf_load_byte ( & buf ) ;
SB ( indsp - > callback_flags , ( prop - 0x21 ) * 8 , 8 , aflag ) ;
} break ;
2007-11-27 17:13:49 +00:00
case 0x23 : // removal cost multiplier
indsp - > removal_cost_multiplier = grf_load_dword ( & buf ) ;
break ;
2008-02-02 03:23:26 +00:00
case 0x24 : // name for nearby station
2008-04-17 11:47:22 +00:00
indsp - > station_name = grf_load_word ( & buf ) ;
_string_to_grf_mapping [ & indsp - > station_name ] = _cur_grffile - > grfid ;
2008-02-02 03:23:26 +00:00
break ;
2007-07-10 00:10:19 +00:00
default :
ret = true ;
break ;
}
}
* bufp = buf ;
return ret ;
}
2004-11-12 15:15:56 +00:00
/* Action 0x00 */
2008-05-08 13:20:54 +00:00
static void FeatureChangeInfo ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
byte * bufend = buf + len ;
/* <00> <feature> <num-props> <num-info> <id> (<property <new-info>)...
*
* B feature 0 , 1 , 2 or 3 for trains , road vehicles , ships or planes
* 4 for defining new train station sets
* B num - props how many properties to change per vehicle / station
* B num - info how many vehicles / stations to change
2007-11-16 02:25:56 +00:00
* E id ID of first vehicle / station to change , if num - info is
2004-08-09 17:04:08 +00:00
* greater than one , this one and the following
* vehicles / stations will be changed
* B property what property to change , depends on the feature
* V new - info new bytes of info ( variable size ; depends on properties ) */
2004-11-14 10:03:21 +00:00
/* TODO: Bridges, town houses. */
2004-08-09 17:04:08 +00:00
2005-09-20 09:38:09 +00:00
static const VCI_Handler handler [ ] = {
2006-05-12 00:27:12 +00:00
/* GSF_TRAIN */ RailVehicleChangeInfo ,
/* GSF_ROAD */ RoadVehicleChangeInfo ,
/* GSF_SHIP */ ShipVehicleChangeInfo ,
/* GSF_AIRCRAFT */ AircraftVehicleChangeInfo ,
/* GSF_STATION */ StationChangeInfo ,
2008-01-21 20:41:04 +00:00
/* GSF_CANAL */ CanalChangeInfo ,
2006-05-12 00:27:12 +00:00
/* GSF_BRIDGE */ BridgeChangeInfo ,
2007-03-19 11:27:30 +00:00
/* GSF_TOWNHOUSE */ TownHouseChangeInfo ,
2008-02-03 20:23:59 +00:00
/* GSF_GLOBALVAR */ GlobalVarChangeInfo ,
2007-07-10 00:10:19 +00:00
/* GSF_INDUSTRYTILES */ IndustrytilesChangeInfo ,
/* GSF_INDUSTRIES */ IndustriesChangeInfo ,
2007-03-22 23:19:40 +00:00
/* GSF_CARGOS */ NULL , /* Cargo is handled during reservation */
2006-09-27 18:17:01 +00:00
/* GSF_SOUNDFX */ SoundEffectChangeInfo ,
2004-08-09 17:04:08 +00:00
} ;
2004-11-12 18:43:12 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 6 , " FeatureChangeInfo " ) ) return ;
2006-05-02 09:18:51 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 feature = grf_load_byte ( & buf ) ;
uint8 numprops = grf_load_byte ( & buf ) ;
2007-03-11 02:53:44 +00:00
uint numinfo = grf_load_byte ( & buf ) ;
2007-11-16 02:25:56 +00:00
uint engine = grf_load_extended ( & buf ) ;
2004-11-12 15:36:49 +00:00
2006-12-26 17:36:18 +00:00
grfmsg ( 6 , " FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d " ,
2004-11-13 18:01:33 +00:00
feature , numprops , engine , numinfo ) ;
2005-09-20 17:33:57 +00:00
if ( feature > = lengthof ( handler ) | | handler [ feature ] = = NULL ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " FeatureChangeInfo: Unsupported feature %d, skipping " , feature ) ;
2004-11-14 10:03:21 +00:00
return ;
}
2004-11-12 15:36:49 +00:00
while ( numprops - - & & buf < bufend ) {
uint8 prop = grf_load_byte ( & buf ) ;
2005-09-13 09:23:23 +00:00
bool ignoring = false ;
switch ( feature ) {
case GSF_TRAIN :
case GSF_ROAD :
case GSF_SHIP :
2007-07-04 12:52:43 +00:00
case GSF_AIRCRAFT : {
bool handled = true ;
for ( uint i = 0 ; i < numinfo ; i + + ) {
2008-04-29 21:31:29 +00:00
Engine * e = GetNewEngine ( _cur_grffile , ( VehicleType ) feature , engine + i ) ;
EngineInfo * ei = & e - > info ;
2007-07-04 12:52:43 +00:00
/* Common properties for vehicles */
switch ( prop ) {
case 0x00 : // Introduction date
ei - > base_intro = grf_load_word ( & buf ) + DAYS_TILL_ORIGINAL_BASE_YEAR ;
break ;
case 0x02 : // Decay speed
2008-06-05 12:08:20 +00:00
ei - > decay_speed = grf_load_byte ( & buf ) ;
2007-07-04 12:52:43 +00:00
break ;
case 0x03 : // Vehicle life
ei - > lifelength = grf_load_byte ( & buf ) ;
break ;
case 0x04 : // Model life
ei - > base_life = grf_load_byte ( & buf ) ;
break ;
case 0x06 : // Climates available
ei - > climates = grf_load_byte ( & buf ) ;
2008-04-29 21:31:29 +00:00
// XXX sometimes a grf wants hidden vehicles :o
if ( ei - > climates = = 0 ) ei - > climates = 0x80 ;
2007-07-04 12:52:43 +00:00
break ;
case 0x07 : // Loading speed
/* Hyronymus explained me what does
* this mean and insists on having a
* credit ; - ) . - - pasky */
ei - > load_amount = grf_load_byte ( & buf ) ;
break ;
default :
handled = false ;
break ;
}
2005-09-13 09:23:23 +00:00
}
2007-07-04 12:52:43 +00:00
if ( handled ) break ;
} /* FALL THROUGH */
2004-08-09 17:04:08 +00:00
2005-09-13 09:23:23 +00:00
default :
2007-03-10 09:55:11 +00:00
if ( handler [ feature ] ( engine , numinfo , prop , & buf , bufend - buf ) ) {
2005-09-13 09:23:23 +00:00
ignoring = true ;
2007-03-10 09:55:11 +00:00
}
2005-09-13 09:23:23 +00:00
break ;
2004-08-09 17:04:08 +00:00
}
2005-09-13 09:23:23 +00:00
2007-12-15 03:42:41 +00:00
if ( ignoring ) grfmsg ( 1 , " FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented) " , prop , feature ) ;
2004-08-09 17:04:08 +00:00
}
}
2007-01-04 19:24:42 +00:00
/* Action 0x00 (GLS_SAFETYSCAN) */
2008-05-08 13:20:54 +00:00
static void SafeChangeInfo ( byte * buf , size_t len )
2007-01-04 19:24:42 +00:00
{
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 6 , " SafeChangeInfo " ) ) return ;
2007-01-04 19:24:42 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 feature = grf_load_byte ( & buf ) ;
uint8 numprops = grf_load_byte ( & buf ) ;
2007-11-16 02:25:56 +00:00
grf_load_byte ( & buf ) ; // num-info
grf_load_extended ( & buf ) ; // id
2007-01-04 19:24:42 +00:00
if ( feature = = GSF_BRIDGE & & numprops = = 1 ) {
uint8 prop = grf_load_byte ( & buf ) ;
/* Bridge property 0x0D is redefinition of sprite layout tables, which
* is considered safe . */
if ( prop = = 0x0D ) return ;
}
2007-11-20 13:35:54 +00:00
SetBit ( _cur_grfconfig - > flags , GCF_UNSAFE ) ;
2007-01-04 19:24:42 +00:00
/* Skip remainder of GRF */
_skip_sprites = - 1 ;
}
2007-03-22 23:19:40 +00:00
/* Action 0x00 (GLS_RESERVE) */
2008-05-08 13:20:54 +00:00
static void ReserveChangeInfo ( byte * buf , size_t len )
2007-03-22 23:19:40 +00:00
{
byte * bufend = buf + len ;
2008-02-03 20:23:59 +00:00
if ( ! check_length ( len , 6 , " ReserveChangeInfo " ) ) return ;
2007-03-22 23:19:40 +00:00
buf + + ;
uint8 feature = grf_load_byte ( & buf ) ;
2007-11-22 22:37:06 +00:00
if ( feature ! = GSF_CARGOS & & feature ! = GSF_GLOBALVAR ) return ;
2007-03-22 23:19:40 +00:00
uint8 numprops = grf_load_byte ( & buf ) ;
uint8 numinfo = grf_load_byte ( & buf ) ;
2007-11-16 02:25:56 +00:00
uint8 index = grf_load_extended ( & buf ) ;
2007-03-22 23:19:40 +00:00
while ( numprops - - & & buf < bufend ) {
uint8 prop = grf_load_byte ( & buf ) ;
2007-11-22 22:37:06 +00:00
bool ignoring = false ;
2007-03-22 23:19:40 +00:00
2007-11-22 22:37:06 +00:00
switch ( feature ) {
default : NOT_REACHED ( ) ;
case GSF_CARGOS :
ignoring = CargoChangeInfo ( index , numinfo , prop , & buf , bufend - buf ) ;
break ;
case GSF_GLOBALVAR :
2008-02-03 20:23:59 +00:00
switch ( prop ) {
case 0x09 : // Cargo Translation Table
if ( index ! = 0 ) {
grfmsg ( 1 , " ReserveChangeInfo: Cargo translation table must start at zero " ) ;
return ;
}
free ( _cur_grffile - > cargo_list ) ;
_cur_grffile - > cargo_max = numinfo ;
_cur_grffile - > cargo_list = MallocT < CargoLabel > ( numinfo ) ;
for ( uint i = 0 ; i < numinfo ; i + + ) {
CargoLabel cl = grf_load_dword ( & buf ) ;
_cur_grffile - > cargo_list [ i ] = BSWAP32 ( cl ) ;
}
break ;
2008-04-29 21:31:29 +00:00
case 0x11 : // GRF match for engine allocation
for ( uint i = 0 ; i < numinfo ; i + + ) {
uint32 s = grf_load_dword ( & buf ) ;
uint32 t = grf_load_dword ( & buf ) ;
SetNewGRFOverride ( s , t ) ;
}
break ;
2008-02-03 20:23:59 +00:00
}
2007-11-22 22:37:06 +00:00
break ;
2007-03-22 23:19:40 +00:00
}
2007-11-22 22:37:06 +00:00
if ( ignoring ) grfmsg ( 2 , " ReserveChangeInfo: Ignoring property 0x%02X (not implemented) " , prop ) ;
2007-03-22 23:19:40 +00:00
}
}
2005-06-01 11:34:37 +00:00
/**
* Creates a spritegroup representing a callback result
* @ param value The value that was used to represent this callback result
* @ return A spritegroup representing that callback result
*/
2006-10-19 10:40:21 +00:00
static const SpriteGroup * NewCallBackResultSpriteGroup ( uint16 value )
2005-06-01 11:34:37 +00:00
{
2006-04-20 20:51:57 +00:00
SpriteGroup * group = AllocateSpriteGroup ( ) ;
2005-06-01 11:34:37 +00:00
2005-10-04 19:52:26 +00:00
group - > type = SGT_CALLBACK ;
2005-06-01 11:34:37 +00:00
2007-03-21 03:06:21 +00:00
/* Old style callback results have the highest byte 0xFF so signify it is a callback result
* New style ones only have the highest bit set ( allows 15 - bit results , instead of just 8 ) */
2006-02-18 14:41:24 +00:00
if ( ( value > > 8 ) = = 0xFF ) {
value & = ~ 0xFF00 ;
} else {
2005-06-01 11:34:37 +00:00
value & = ~ 0x8000 ;
2006-02-18 14:41:24 +00:00
}
2005-06-01 11:34:37 +00:00
2005-10-04 19:52:26 +00:00
group - > g . callback . result = value ;
2005-06-01 11:34:37 +00:00
return group ;
}
2004-08-09 17:04:08 +00:00
2005-10-04 20:38:26 +00:00
/**
* Creates a spritegroup representing a sprite number result .
2007-04-17 20:23:13 +00:00
* @ param sprite The sprite number .
* @ param num_sprites The number of sprites per set .
2005-10-04 20:38:26 +00:00
* @ return A spritegroup representing the sprite number result .
*/
2006-10-19 10:40:21 +00:00
static const SpriteGroup * NewResultSpriteGroup ( SpriteID sprite , byte num_sprites )
2005-10-04 20:38:26 +00:00
{
2006-04-20 20:51:57 +00:00
SpriteGroup * group = AllocateSpriteGroup ( ) ;
2005-10-04 20:38:26 +00:00
group - > type = SGT_RESULT ;
2006-04-26 20:44:28 +00:00
group - > g . result . sprite = sprite ;
group - > g . result . num_sprites = num_sprites ;
2005-10-04 20:38:26 +00:00
return group ;
}
2004-11-12 15:15:56 +00:00
/* Action 0x01 */
2008-05-08 13:20:54 +00:00
static void NewSpriteSet ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <01> <feature> <num-sets> <num-ent>
*
* B feature feature to define sprites for
* 0 , 1 , 2 , 3 : veh - type , 4 : train stations
* B num - sets number of sprite sets
2005-08-15 22:48:33 +00:00
* E num - ent how many entries per sprite set
2004-08-09 17:04:08 +00:00
* For vehicles , this is the number of different
* vehicle directions in each sprite set
* Set num - dirs = 8 , unless your sprites are symmetric .
* In that case , use num - dirs = 4.
2007-03-10 09:55:11 +00:00
*/
2004-08-09 17:04:08 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 4 , " NewSpriteSet " ) ) return ;
2005-08-15 22:48:33 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 feature = grf_load_byte ( & buf ) ;
uint8 num_sets = grf_load_byte ( & buf ) ;
uint16 num_ents = grf_load_extended ( & buf ) ;
2004-08-09 17:04:08 +00:00
2005-08-15 11:39:13 +00:00
_cur_grffile - > spriteset_start = _cur_spriteid ;
2004-11-14 09:07:15 +00:00
_cur_grffile - > spriteset_feature = feature ;
2005-08-15 11:39:13 +00:00
_cur_grffile - > spriteset_numsets = num_sets ;
_cur_grffile - > spriteset_numents = num_ents ;
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d) " ,
2005-08-15 11:39:13 +00:00
_cur_spriteid , feature , num_sets , num_ents , num_sets * num_ents
) ;
2008-01-14 11:18:43 +00:00
for ( int i = 0 ; i < num_sets * num_ents ; i + + ) {
2006-04-15 16:40:54 +00:00
_nfo_line + + ;
2007-11-24 10:19:56 +00:00
LoadNextSprite ( _cur_spriteid + + , _file_index , _nfo_line ) ;
2005-08-15 11:39:13 +00:00
}
2004-08-09 17:04:08 +00:00
}
2007-05-05 10:47:35 +00:00
/* Action 0x01 (SKIP) */
2008-05-08 13:20:54 +00:00
static void SkipAct1 ( byte * buf , size_t len )
2007-05-05 10:47:35 +00:00
{
if ( ! check_length ( len , 4 , " SkipAct1 " ) ) return ;
buf + + ;
grf_load_byte ( & buf ) ;
uint8 num_sets = grf_load_byte ( & buf ) ;
uint16 num_ents = grf_load_extended ( & buf ) ;
_skip_sprites = num_sets * num_ents ;
grfmsg ( 3 , " SkipAct1: Skipping %d sprites " , _skip_sprites ) ;
}
2006-04-26 19:42:05 +00:00
/* Helper function to either create a callback or link to a previously
* defined spritegroup . */
2006-10-19 10:40:21 +00:00
static const SpriteGroup * GetGroupFromGroupID ( byte setid , byte type , uint16 groupid )
2006-04-26 19:42:05 +00:00
{
2007-11-19 21:02:30 +00:00
if ( HasBit ( groupid , 15 ) ) return NewCallBackResultSpriteGroup ( groupid ) ;
2006-04-26 19:42:05 +00:00
if ( groupid > = _cur_grffile - > spritegroups_count | | _cur_grffile - > spritegroups [ groupid ] = = NULL ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty " , setid , type , groupid ) ;
2006-04-26 19:42:05 +00:00
return NULL ;
}
return _cur_grffile - > spritegroups [ groupid ] ;
}
/* Helper function to either create a callback or a result sprite group. */
2006-10-19 10:40:21 +00:00
static const SpriteGroup * CreateGroupFromGroupID ( byte feature , byte setid , byte type , uint16 spriteid , uint16 num_sprites )
2006-04-26 19:42:05 +00:00
{
2007-11-19 21:02:30 +00:00
if ( HasBit ( spriteid , 15 ) ) return NewCallBackResultSpriteGroup ( spriteid ) ;
2006-04-26 19:42:05 +00:00
2006-04-26 20:18:29 +00:00
if ( spriteid > = _cur_grffile - > spriteset_numsets ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid, max %u " , setid , type , spriteid , _cur_grffile - > spriteset_numsets ) ;
2006-04-26 20:18:29 +00:00
return NULL ;
}
2006-04-26 19:42:05 +00:00
/* Check if the sprite is within range. This can fail if the Action 0x01
* is skipped , as TTDPatch mandates that Action 0x02 s must be processed .
* We don ' t have that rule , but must live by the Patch . . . */
if ( _cur_grffile - > spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " CreateGroupFromGroupID(0x%02X:0x%02X): Real Sprite IDs 0x%04X - 0x%04X do not (all) exist (max 0x%04X), leaving empty " ,
2006-04-26 19:42:05 +00:00
setid , type ,
_cur_grffile - > spriteset_start + spriteid * num_sprites ,
_cur_grffile - > spriteset_start + spriteid * num_sprites + num_sprites - 1 , _cur_spriteid - 1 ) ;
return NULL ;
}
2006-05-10 06:23:43 +00:00
if ( feature ! = _cur_grffile - > spriteset_feature ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping " ,
2007-06-13 06:42:43 +00:00
setid , type ,
2006-05-10 06:23:43 +00:00
_cur_grffile - > spriteset_feature , feature ) ;
return NULL ;
}
2006-04-26 19:42:05 +00:00
return NewResultSpriteGroup ( _cur_grffile - > spriteset_start + spriteid * num_sprites , num_sprites ) ;
}
2004-11-12 15:15:56 +00:00
/* Action 0x02 */
2008-05-08 13:20:54 +00:00
static void NewSpriteGroup ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...>
*
* B feature see action 1
* B set - id ID of this particular definition
* B type / num - entries
* if 80 or greater , this is a randomized or variational
* list definition , see below
* otherwise it specifies a number of entries , the exact
* meaning depends on the feature
* V feature - specific - data ( huge mess , don ' t even look it up - - pasky ) */
2006-04-23 09:46:23 +00:00
SpriteGroup * group = NULL ;
byte * bufend = buf + len ;
2004-08-09 17:04:08 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 5 , " NewSpriteGroup " ) ) return ;
2006-04-23 09:46:23 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 feature = grf_load_byte ( & buf ) ;
uint8 setid = grf_load_byte ( & buf ) ;
uint8 type = grf_load_byte ( & buf ) ;
2004-08-09 17:04:08 +00:00
2005-09-22 20:35:20 +00:00
if ( setid > = _cur_grffile - > spritegroups_count ) {
2007-03-21 03:06:21 +00:00
/* Allocate memory for new sprite group references. */
2007-01-11 17:29:39 +00:00
_cur_grffile - > spritegroups = ReallocT ( _cur_grffile - > spritegroups , setid + 1 ) ;
2007-03-21 03:06:21 +00:00
/* Initialise new space to NULL */
2005-10-04 19:52:26 +00:00
for ( ; _cur_grffile - > spritegroups_count < ( setid + 1 ) ; _cur_grffile - > spritegroups_count + + )
_cur_grffile - > spritegroups [ _cur_grffile - > spritegroups_count ] = NULL ;
2005-09-22 20:35:20 +00:00
}
2006-04-23 09:46:23 +00:00
switch ( type ) {
/* Deterministic Sprite Group */
case 0x81 : // Self scope, byte
case 0x82 : // Parent scope, byte
2006-04-26 20:44:28 +00:00
case 0x85 : // Self scope, word
case 0x86 : // Parent scope, word
case 0x89 : // Self scope, dword
case 0x8A : // Parent scope, dword
2006-04-23 09:46:23 +00:00
{
2006-04-26 20:44:28 +00:00
byte varadjust ;
byte varsize ;
2006-04-23 09:46:23 +00:00
2006-04-26 20:44:28 +00:00
/* Check we can load the var size parameter */
2007-01-10 19:20:25 +00:00
if ( ! check_length ( bufend - buf , 1 , " NewSpriteGroup (Deterministic) (1) " ) ) return ;
2006-04-23 09:46:23 +00:00
group = AllocateSpriteGroup ( ) ;
group - > type = SGT_DETERMINISTIC ;
2007-11-19 21:02:30 +00:00
group - > g . determ . var_scope = HasBit ( type , 1 ) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF ;
2006-04-26 20:44:28 +00:00
switch ( GB ( type , 2 , 2 ) ) {
2006-04-27 06:33:21 +00:00
default : NOT_REACHED ( ) ;
2006-04-26 20:44:28 +00:00
case 0 : group - > g . determ . size = DSG_SIZE_BYTE ; varsize = 1 ; break ;
case 1 : group - > g . determ . size = DSG_SIZE_WORD ; varsize = 2 ; break ;
case 2 : group - > g . determ . size = DSG_SIZE_DWORD ; varsize = 4 ; break ;
2006-04-23 09:46:23 +00:00
}
2004-11-14 18:18:28 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( bufend - buf , 5 + varsize , " NewSpriteGroup (Deterministic) (2) " ) ) return ;
2006-04-26 20:44:28 +00:00
/* Loop through the var adjusts. Unfortunately we don't know how many we have
* from the outset , so we shall have to keep reallocing . */
do {
DeterministicSpriteGroupAdjust * adjust ;
if ( group - > g . determ . num_adjusts > 0 ) {
2007-01-10 19:20:25 +00:00
if ( ! check_length ( bufend - buf , 2 + varsize + 3 , " NewSpriteGroup (Deterministic) (3) " ) ) return ;
2006-04-26 20:44:28 +00:00
}
group - > g . determ . num_adjusts + + ;
2007-01-11 17:29:39 +00:00
group - > g . determ . adjusts = ReallocT ( group - > g . determ . adjusts , group - > g . determ . num_adjusts ) ;
2006-04-26 20:44:28 +00:00
adjust = & group - > g . determ . adjusts [ group - > g . determ . num_adjusts - 1 ] ;
/* The first var adjust doesn't have an operation specified, so we set it to add. */
2007-01-10 18:56:51 +00:00
adjust - > operation = group - > g . determ . num_adjusts = = 1 ? DSGA_OP_ADD : ( DeterministicSpriteGroupAdjustOperation ) grf_load_byte ( & buf ) ;
2006-04-26 20:44:28 +00:00
adjust - > variable = grf_load_byte ( & buf ) ;
2007-01-12 11:20:34 +00:00
if ( adjust - > variable = = 0x7E ) {
/* Link subroutine group */
adjust - > subroutine = GetGroupFromGroupID ( setid , type , grf_load_byte ( & buf ) ) ;
} else {
2007-11-24 10:38:43 +00:00
adjust - > parameter = IsInsideMM ( adjust - > variable , 0x60 , 0x80 ) ? grf_load_byte ( & buf ) : 0 ;
2007-01-12 11:20:34 +00:00
}
2006-04-26 20:44:28 +00:00
varadjust = grf_load_byte ( & buf ) ;
adjust - > shift_num = GB ( varadjust , 0 , 5 ) ;
2007-01-10 18:56:51 +00:00
adjust - > type = ( DeterministicSpriteGroupAdjustType ) GB ( varadjust , 6 , 2 ) ;
2006-04-26 20:44:28 +00:00
adjust - > and_mask = grf_load_var ( varsize , & buf ) ;
if ( adjust - > type ! = DSGA_TYPE_NONE ) {
adjust - > add_val = grf_load_var ( varsize , & buf ) ;
adjust - > divmod_val = grf_load_var ( varsize , & buf ) ;
} else {
adjust - > add_val = 0 ;
adjust - > divmod_val = 0 ;
}
/* Continue reading var adjusts while bit 5 is set. */
2007-11-19 21:02:30 +00:00
} while ( HasBit ( varadjust , 5 ) ) ;
2006-04-26 20:44:28 +00:00
group - > g . determ . num_ranges = grf_load_byte ( & buf ) ;
2007-05-20 16:17:03 +00:00
if ( group - > g . determ . num_ranges > 0 ) group - > g . determ . ranges = CallocT < DeterministicSpriteGroupRange > ( group - > g . determ . num_ranges ) ;
2006-04-23 09:46:23 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( bufend - buf , 2 + ( 2 + 2 * varsize ) * group - > g . determ . num_ranges , " NewSpriteGroup (Deterministic) " ) ) return ;
2006-04-26 20:44:28 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < group - > g . determ . num_ranges ; i + + ) {
2006-04-26 20:44:28 +00:00
group - > g . determ . ranges [ i ] . group = GetGroupFromGroupID ( setid , type , grf_load_word ( & buf ) ) ;
group - > g . determ . ranges [ i ] . low = grf_load_var ( varsize , & buf ) ;
group - > g . determ . ranges [ i ] . high = grf_load_var ( varsize , & buf ) ;
2006-04-23 09:46:23 +00:00
}
2004-11-14 23:14:44 +00:00
2006-04-26 20:44:28 +00:00
group - > g . determ . default_group = GetGroupFromGroupID ( setid , type , grf_load_word ( & buf ) ) ;
2006-04-23 09:46:23 +00:00
break ;
2004-11-14 18:18:28 +00:00
}
2006-04-23 09:46:23 +00:00
/* Randomized Sprite Group */
case 0x80 : // Self scope
case 0x83 : // Parent scope
2008-03-27 21:36:16 +00:00
case 0x84 : // Relative scope
2006-04-23 09:46:23 +00:00
{
2008-03-27 21:36:16 +00:00
if ( ! check_length ( bufend - buf , HasBit ( type , 2 ) ? 8 : 7 , " NewSpriteGroup (Randomized) (1) " ) ) return ;
2004-11-17 08:52:47 +00:00
2006-04-23 09:46:23 +00:00
group = AllocateSpriteGroup ( ) ;
group - > type = SGT_RANDOMIZED ;
2007-11-19 21:02:30 +00:00
group - > g . random . var_scope = HasBit ( type , 1 ) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF ;
2004-11-17 08:52:47 +00:00
2008-03-28 02:10:25 +00:00
if ( HasBit ( type , 2 ) ) {
if ( feature < = GSF_AIRCRAFT ) group - > g . random . var_scope = VSG_SCOPE_RELATIVE ;
2008-03-27 21:36:16 +00:00
group - > g . random . count = grf_load_byte ( & buf ) ;
}
2007-03-10 09:55:11 +00:00
uint8 triggers = grf_load_byte ( & buf ) ;
2006-04-26 20:44:28 +00:00
group - > g . random . triggers = GB ( triggers , 0 , 7 ) ;
2007-11-19 21:02:30 +00:00
group - > g . random . cmp_mode = HasBit ( triggers , 7 ) ? RSG_CMP_ALL : RSG_CMP_ANY ;
2006-04-26 20:44:28 +00:00
group - > g . random . lowest_randbit = grf_load_byte ( & buf ) ;
group - > g . random . num_groups = grf_load_byte ( & buf ) ;
2007-01-11 17:29:39 +00:00
group - > g . random . groups = CallocT < const SpriteGroup * > ( group - > g . random . num_groups ) ;
2004-11-17 08:52:47 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( bufend - buf , 2 * group - > g . random . num_groups , " NewSpriteGroup (Randomized) (2) " ) ) return ;
2004-11-17 08:52:47 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < group - > g . random . num_groups ; i + + ) {
2006-04-26 20:44:28 +00:00
group - > g . random . groups [ i ] = GetGroupFromGroupID ( setid , type , grf_load_word ( & buf ) ) ;
2006-04-23 09:46:23 +00:00
}
2004-11-17 08:52:47 +00:00
2006-04-23 09:46:23 +00:00
break ;
}
2004-11-17 08:52:47 +00:00
2006-04-26 20:44:28 +00:00
/* Neither a variable or randomized sprite group... must be a real group */
2006-04-23 09:46:23 +00:00
default :
{
2006-05-10 06:23:43 +00:00
2006-04-26 20:44:28 +00:00
switch ( feature ) {
case GSF_TRAIN :
case GSF_ROAD :
case GSF_SHIP :
case GSF_AIRCRAFT :
case GSF_STATION :
2007-05-06 18:14:33 +00:00
case GSF_CANAL :
2007-03-23 20:55:45 +00:00
case GSF_CARGOS :
2006-04-26 20:44:28 +00:00
{
byte sprites = _cur_grffile - > spriteset_numents ;
byte num_loaded = type ;
byte num_loading = grf_load_byte ( & buf ) ;
if ( _cur_grffile - > spriteset_start = = 0 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 0 , " NewSpriteGroup: No sprite set to work on! Skipping " ) ;
2006-04-26 20:44:28 +00:00
return ;
}
2006-04-23 09:46:23 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( bufend - buf , 2 * num_loaded + 2 * num_loading , " NewSpriteGroup (Real) (1) " ) ) return ;
2004-08-09 17:04:08 +00:00
2006-04-26 20:44:28 +00:00
group = AllocateSpriteGroup ( ) ;
group - > type = SGT_REAL ;
2004-08-09 17:04:08 +00:00
2006-04-26 20:44:28 +00:00
group - > g . real . num_loaded = num_loaded ;
group - > g . real . num_loading = num_loading ;
2007-01-11 17:29:39 +00:00
if ( num_loaded > 0 ) group - > g . real . loaded = CallocT < const SpriteGroup * > ( num_loaded ) ;
if ( num_loading > 0 ) group - > g . real . loading = CallocT < const SpriteGroup * > ( num_loading ) ;
2004-11-12 15:36:49 +00:00
2006-12-26 17:36:18 +00:00
grfmsg ( 6 , " NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading " ,
2006-04-26 20:44:28 +00:00
setid , sprites , num_loaded , num_loading ) ;
2006-04-23 09:46:23 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < num_loaded ; i + + ) {
2006-04-26 20:44:28 +00:00
uint16 spriteid = grf_load_word ( & buf ) ;
2006-05-10 06:23:43 +00:00
group - > g . real . loaded [ i ] = CreateGroupFromGroupID ( feature , setid , type , spriteid , sprites ) ;
2006-12-26 17:36:18 +00:00
grfmsg ( 8 , " NewSpriteGroup: + rg->loaded[%i] = subset %u " , i , spriteid ) ;
2006-04-26 20:44:28 +00:00
}
2006-04-23 09:46:23 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < num_loading ; i + + ) {
2006-04-26 20:44:28 +00:00
uint16 spriteid = grf_load_word ( & buf ) ;
2006-05-10 06:23:43 +00:00
group - > g . real . loading [ i ] = CreateGroupFromGroupID ( feature , setid , type , spriteid , sprites ) ;
2006-12-26 17:36:18 +00:00
grfmsg ( 8 , " NewSpriteGroup: + rg->loading[%i] = subset %u " , i , spriteid ) ;
2006-04-26 20:44:28 +00:00
}
2006-04-23 09:46:23 +00:00
2006-04-26 20:44:28 +00:00
break ;
}
2004-08-09 17:04:08 +00:00
2007-07-05 16:39:56 +00:00
case GSF_TOWNHOUSE :
case GSF_INDUSTRYTILES : {
2007-03-19 11:27:30 +00:00
byte sprites = _cur_grffile - > spriteset_numents ;
byte num_sprites = max ( ( uint8 ) 1 , type ) ;
uint i ;
group = AllocateSpriteGroup ( ) ;
group - > type = SGT_TILELAYOUT ;
group - > g . layout . num_sprites = sprites ;
group - > g . layout . dts = CallocT < DrawTileSprites > ( 1 ) ;
/* Groundsprite */
2008-02-15 18:40:42 +00:00
group - > g . layout . dts - > ground . sprite = grf_load_word ( & buf ) ;
group - > g . layout . dts - > ground . pal = grf_load_word ( & buf ) ;
2008-02-16 03:01:05 +00:00
2007-03-19 11:27:30 +00:00
/* Remap transparent/colour modifier bits */
2008-02-16 03:01:05 +00:00
MapSpriteMappingRecolour ( & group - > g . layout . dts - > ground ) ;
2008-02-15 18:40:42 +00:00
if ( HasBit ( group - > g . layout . dts - > ground . pal , 15 ) ) {
2007-03-19 11:27:30 +00:00
/* Bit 31 set means this is a custom sprite, so rewrite it to the
* last spriteset defined . */
2008-02-15 18:40:42 +00:00
SpriteID sprite = _cur_grffile - > spriteset_start + GB ( group - > g . layout . dts - > ground . sprite , 0 , 14 ) * sprites ;
SB ( group - > g . layout . dts - > ground . sprite , 0 , SPRITE_WIDTH , sprite ) ;
ClrBit ( group - > g . layout . dts - > ground . pal , 15 ) ;
2007-03-19 11:27:30 +00:00
}
group - > g . layout . dts - > seq = CallocT < DrawTileSeqStruct > ( num_sprites + 1 ) ;
for ( i = 0 ; i < num_sprites ; i + + ) {
DrawTileSeqStruct * seq = ( DrawTileSeqStruct * ) & group - > g . layout . dts - > seq [ i ] ;
2008-02-15 18:34:26 +00:00
seq - > image . sprite = grf_load_word ( & buf ) ;
seq - > image . pal = grf_load_word ( & buf ) ;
2007-03-19 11:27:30 +00:00
seq - > delta_x = grf_load_byte ( & buf ) ;
seq - > delta_y = grf_load_byte ( & buf ) ;
2008-02-16 03:01:05 +00:00
MapSpriteMappingRecolour ( & seq - > image ) ;
2008-02-15 18:34:26 +00:00
if ( HasBit ( seq - > image . pal , 15 ) ) {
2007-03-19 11:27:30 +00:00
/* Bit 31 set means this is a custom sprite, so rewrite it to the
* last spriteset defined . */
2008-02-15 18:34:26 +00:00
SpriteID sprite = _cur_grffile - > spriteset_start + GB ( seq - > image . sprite , 0 , 14 ) * sprites ;
SB ( seq - > image . sprite , 0 , SPRITE_WIDTH , sprite ) ;
ClrBit ( seq - > image . pal , 15 ) ;
2007-03-19 11:27:30 +00:00
}
if ( type > 0 ) {
seq - > delta_z = grf_load_byte ( & buf ) ;
if ( ( byte ) seq - > delta_z = = 0x80 ) continue ;
}
seq - > size_x = grf_load_byte ( & buf ) ;
seq - > size_y = grf_load_byte ( & buf ) ;
seq - > size_z = grf_load_byte ( & buf ) ;
}
/* Set the terminator value. */
( ( DrawTileSeqStruct * ) group - > g . layout . dts - > seq ) [ i ] . delta_x = ( byte ) 0x80 ;
break ;
}
2007-07-05 05:41:56 +00:00
case GSF_INDUSTRIES : {
if ( type > 1 ) {
grfmsg ( 1 , " NewSpriteGroup: Unsupported industry production version %d, skipping " , type ) ;
break ;
}
group = AllocateSpriteGroup ( ) ;
group - > type = SGT_INDUSTRY_PRODUCTION ;
group - > g . indprod . version = type ;
if ( type = = 0 ) {
for ( uint i = 0 ; i < 3 ; i + + ) {
group - > g . indprod . substract_input [ i ] = grf_load_word ( & buf ) ;
}
for ( uint i = 0 ; i < 2 ; i + + ) {
group - > g . indprod . add_output [ i ] = grf_load_word ( & buf ) ;
}
group - > g . indprod . again = grf_load_byte ( & buf ) ;
} else {
for ( uint i = 0 ; i < 3 ; i + + ) {
group - > g . indprod . substract_input [ i ] = grf_load_byte ( & buf ) ;
}
for ( uint i = 0 ; i < 2 ; i + + ) {
group - > g . indprod . add_output [ i ] = grf_load_byte ( & buf ) ;
}
group - > g . indprod . again = grf_load_byte ( & buf ) ;
}
break ;
}
2006-04-26 20:44:28 +00:00
/* Loading of Tile Layout and Production Callback groups would happen here */
2006-12-26 17:36:18 +00:00
default : grfmsg ( 1 , " NewSpriteGroup: Unsupported feature %d, skipping " , feature ) ;
2006-04-26 20:44:28 +00:00
}
2005-10-04 20:38:26 +00:00
}
2004-08-09 17:04:08 +00:00
}
2005-09-22 20:35:20 +00:00
_cur_grffile - > spritegroups [ setid ] = group ;
2004-08-09 17:04:08 +00:00
}
2007-02-24 19:36:47 +00:00
static CargoID TranslateCargo ( uint8 feature , uint8 ctype )
{
/* Special cargo types for purchase list and stations */
2007-02-24 23:36:40 +00:00
if ( feature = = GSF_STATION & & ctype = = 0xFE ) return CT_DEFAULT_NA ;
if ( ctype = = 0xFF ) return CT_PURCHASE ;
2007-02-24 19:36:47 +00:00
2007-03-23 00:03:08 +00:00
if ( _cur_grffile - > cargo_max = = 0 ) {
/* No cargo table, so use bitnum values */
if ( ctype > = 32 ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " TranslateCargo: Cargo bitnum %d out of range (max 31), skipping. " , ctype ) ;
2007-03-23 00:03:08 +00:00
return CT_INVALID ;
}
for ( CargoID c = 0 ; c < NUM_CARGO ; c + + ) {
const CargoSpec * cs = GetCargo ( c ) ;
if ( ! cs - > IsValid ( ) ) continue ;
if ( cs - > bitnum = = ctype ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 6 , " TranslateCargo: Cargo bitnum %d mapped to cargo type %d. " , ctype , c ) ;
2007-03-23 00:03:08 +00:00
return c ;
}
}
2007-04-16 20:56:19 +00:00
grfmsg ( 5 , " TranslateCargo: Cargo bitnum %d not available in this climate, skipping. " , ctype ) ;
2007-03-23 00:03:08 +00:00
return CT_INVALID ;
}
2007-02-24 19:36:47 +00:00
/* Check if the cargo type is out of bounds of the cargo translation table */
2007-03-23 00:03:08 +00:00
if ( ctype > = _cur_grffile - > cargo_max ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " TranslateCargo: Cargo type %d out of range (max %d), skipping. " , ctype , _cur_grffile - > cargo_max - 1 ) ;
2007-02-24 19:36:47 +00:00
return CT_INVALID ;
}
/* Look up the cargo label from the translation table */
2007-03-23 00:03:08 +00:00
CargoLabel cl = _cur_grffile - > cargo_list [ ctype ] ;
2007-02-24 19:36:47 +00:00
if ( cl = = 0 ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 5 , " TranslateCargo: Cargo type %d not available in this climate, skipping. " , ctype ) ;
2007-02-24 19:36:47 +00:00
return CT_INVALID ;
}
ctype = GetCargoIDByLabel ( cl ) ;
if ( ctype = = CT_INVALID ) {
2007-04-16 20:56:19 +00:00
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 ) ) ;
2007-02-24 19:36:47 +00:00
return CT_INVALID ;
}
2007-04-16 20:56:19 +00:00
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 ) ;
2007-02-24 19:36:47 +00:00
return ctype ;
}
2004-08-09 17:04:08 +00:00
2008-06-02 19:35:30 +00:00
static bool IsValidGroupID ( uint16 groupid , const char * function )
{
if ( groupid > = _cur_grffile - > spritegroups_count | | _cur_grffile - > spritegroups [ groupid ] = = NULL ) {
grfmsg ( 1 , " %s: Spriteset 0x%04X out of range (maximum 0x%02X) or empty, skipping. " , function , groupid , _cur_grffile - > spritegroups_count - 1 ) ;
return false ;
}
return true ;
}
2008-06-02 19:52:41 +00:00
static void VehicleMapSpriteGroup ( byte * buf , byte feature , uint8 idcount )
2007-03-23 20:01:25 +00:00
{
2008-01-05 15:39:22 +00:00
static EngineID * last_engines ;
static uint last_engines_count ;
2008-06-02 19:52:41 +00:00
bool wagover = false ;
/* Test for 'wagon override' flag */
if ( HasBit ( idcount , 7 ) ) {
wagover = true ;
/* Strip off the flag */
idcount = GB ( idcount , 0 , 7 ) ;
2004-11-12 15:36:49 +00:00
2004-11-13 12:21:32 +00:00
if ( last_engines_count = = 0 ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 0 , " VehicleMapSpriteGroup: WagonOverride: No engine to do override with " ) ;
2004-11-13 12:21:32 +00:00
return ;
}
2007-03-23 20:01:25 +00:00
2007-04-16 20:56:19 +00:00
grfmsg ( 6 , " VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons " ,
2004-11-13 18:08:45 +00:00
last_engines_count , idcount ) ;
2008-06-02 19:52:41 +00:00
} else {
if ( last_engines_count ! = idcount ) {
last_engines = ReallocT ( last_engines , idcount ) ;
last_engines_count = idcount ;
}
2004-11-13 12:21:32 +00:00
}
2004-11-14 13:59:11 +00:00
2008-06-10 21:59:22 +00:00
EngineID * engines = AllocaM ( EngineID , idcount ) ;
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-12 09:25:04 +00:00
engines [ i ] = GetNewEngine ( _cur_grffile , ( VehicleType ) feature , grf_load_extended ( & buf ) ) - > index ;
2008-06-02 19:52:41 +00:00
if ( ! wagover ) last_engines [ i ] = engines [ i ] ;
}
2004-08-09 17:04:08 +00:00
2008-06-02 19:52:41 +00:00
uint8 cidcount = grf_load_byte ( & buf ) ;
for ( uint c = 0 ; c < cidcount ; c + + ) {
uint8 ctype = grf_load_byte ( & buf ) ;
uint16 groupid = grf_load_word ( & buf ) ;
if ( ! IsValidGroupID ( groupid , " VehicleMapSpriteGroup " ) ) continue ;
2004-11-13 18:08:45 +00:00
2008-06-02 19:52:41 +00:00
grfmsg ( 8 , " VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X " , c , ctype , groupid ) ;
2004-08-09 17:04:08 +00:00
2008-06-02 19:52:41 +00:00
ctype = TranslateCargo ( feature , ctype ) ;
if ( ctype = = CT_INVALID ) continue ;
2004-11-13 18:08:45 +00:00
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
EngineID engine = engines [ i ] ;
grfmsg ( 7 , " VehicleMapSpriteGroup: [%d] Engine %d... " , i , engine ) ;
2006-12-18 10:46:06 +00:00
2004-11-13 18:08:45 +00:00
if ( wagover ) {
2006-10-17 14:52:55 +00:00
SetWagonOverrideSprites ( engine , ctype , _cur_grffile - > spritegroups [ groupid ] , last_engines , last_engines_count ) ;
2004-11-12 15:36:49 +00:00
} else {
2005-09-22 20:35:20 +00:00
SetCustomEngineSprites ( engine , ctype , _cur_grffile - > spritegroups [ groupid ] ) ;
2004-08-09 17:04:08 +00:00
}
}
2004-11-12 15:36:49 +00:00
}
2004-08-09 17:04:08 +00:00
2008-06-02 19:52:41 +00:00
uint16 groupid = grf_load_word ( & buf ) ;
if ( ! IsValidGroupID ( groupid , " VehicleMapSpriteGroup " ) ) return ;
2004-08-09 17:04:08 +00:00
2008-06-02 19:52:41 +00:00
grfmsg ( 8 , " -- Default group id 0x%04X " , groupid ) ;
2004-11-13 18:08:45 +00:00
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
EngineID engine = engines [ i ] ;
2004-08-09 17:04:08 +00:00
2008-06-02 19:52:41 +00:00
if ( wagover ) {
SetWagonOverrideSprites ( engine , CT_DEFAULT , _cur_grffile - > spritegroups [ groupid ] , last_engines , last_engines_count ) ;
} else {
SetCustomEngineSprites ( engine , CT_DEFAULT , _cur_grffile - > spritegroups [ groupid ] ) ;
SetEngineGRF ( engine , _cur_grffile ) ;
2004-08-09 17:04:08 +00:00
}
}
}
2007-03-23 20:01:25 +00:00
2008-06-02 19:52:41 +00:00
static void CanalMapSpriteGroup ( byte * buf , uint8 idcount )
2007-05-06 18:14:33 +00:00
{
2008-06-10 21:59:22 +00:00
CanalFeature * cfs = AllocaM ( CanalFeature , idcount ) ;
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
cfs [ i ] = ( CanalFeature ) grf_load_byte ( & buf ) ;
}
uint8 cidcount = grf_load_byte ( & buf ) ;
buf + = cidcount * 3 ;
uint16 groupid = grf_load_word ( & buf ) ;
2008-06-02 19:35:30 +00:00
if ( ! IsValidGroupID ( groupid , " CanalMapSpriteGroup " ) ) return ;
2007-05-06 18:14:33 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-02 19:52:41 +00:00
CanalFeature cf = cfs [ i ] ;
2007-05-06 18:14:33 +00:00
if ( cf > = CF_END ) {
grfmsg ( 1 , " CanalMapSpriteGroup: Canal subset %d out of range, skipping " , cf ) ;
continue ;
}
2008-07-30 18:23:12 +00:00
_water_feature [ cf ] . grffile = _cur_grffile ;
2008-01-21 20:41:04 +00:00
_water_feature [ cf ] . group = _cur_grffile - > spritegroups [ groupid ] ;
2007-05-06 18:14:33 +00:00
}
}
2008-06-02 19:52:41 +00:00
static void StationMapSpriteGroup ( byte * buf , uint8 idcount )
2007-03-23 20:01:25 +00:00
{
2008-06-10 21:59:22 +00:00
uint8 * stations = AllocaM ( uint8 , idcount ) ;
2007-03-23 20:01:25 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-02 19:52:41 +00:00
stations [ i ] = grf_load_byte ( & buf ) ;
}
2007-10-09 15:28:40 +00:00
2008-06-02 19:52:41 +00:00
uint8 cidcount = grf_load_byte ( & buf ) ;
for ( uint c = 0 ; c < cidcount ; c + + ) {
uint8 ctype = grf_load_byte ( & buf ) ;
uint16 groupid = grf_load_word ( & buf ) ;
if ( ! IsValidGroupID ( groupid , " StationMapSpriteGroup " ) ) continue ;
2007-10-09 15:28:40 +00:00
2008-06-02 19:52:41 +00:00
ctype = TranslateCargo ( GSF_STATION , ctype ) ;
if ( ctype = = CT_INVALID ) continue ;
2007-03-23 20:01:25 +00:00
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
StationSpec * statspec = _cur_grffile - > stations [ stations [ i ] ] ;
2007-03-23 20:01:25 +00:00
2008-06-02 19:52:41 +00:00
if ( statspec = = NULL ) {
grfmsg ( 1 , " StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping " , stations [ i ] ) ;
return ;
}
2007-03-23 20:01:25 +00:00
statspec - > spritegroup [ ctype ] = _cur_grffile - > spritegroups [ groupid ] ;
}
}
2008-06-02 19:52:41 +00:00
uint16 groupid = grf_load_word ( & buf ) ;
if ( ! IsValidGroupID ( groupid , " StationMapSpriteGroup " ) ) return ;
2007-03-23 20:01:25 +00:00
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
StationSpec * statspec = _cur_grffile - > stations [ stations [ i ] ] ;
2007-03-23 20:01:25 +00:00
2008-06-02 19:52:41 +00:00
if ( statspec = = NULL ) {
grfmsg ( 1 , " StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping " , stations [ i ] ) ;
continue ;
2007-03-23 20:01:25 +00:00
}
2008-06-02 19:52:41 +00:00
statspec - > spritegroup [ CT_DEFAULT ] = _cur_grffile - > spritegroups [ groupid ] ;
statspec - > grffile = _cur_grffile ;
statspec - > localidx = stations [ i ] ;
SetCustomStationSpec ( statspec ) ;
2007-03-23 20:01:25 +00:00
}
}
2008-06-02 19:52:41 +00:00
static void TownHouseMapSpriteGroup ( byte * buf , uint8 idcount )
2007-03-23 20:01:25 +00:00
{
2008-06-10 21:59:22 +00:00
uint8 * houses = AllocaM ( uint8 , idcount ) ;
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
houses [ i ] = grf_load_byte ( & buf ) ;
}
/* Skip the cargo type section, we only care about the default group */
uint8 cidcount = grf_load_byte ( & buf ) ;
buf + = cidcount * 3 ;
uint16 groupid = grf_load_word ( & buf ) ;
2008-06-02 19:35:30 +00:00
if ( ! IsValidGroupID ( groupid , " TownHouseMapSpriteGroup " ) ) return ;
2007-03-23 20:01:25 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-02 19:52:41 +00:00
HouseSpec * hs = _cur_grffile - > housespec [ houses [ i ] ] ;
2007-03-23 20:01:25 +00:00
if ( hs = = NULL ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " TownHouseMapSpriteGroup: Too many houses defined, skipping " ) ;
2007-03-23 20:01:25 +00:00
return ;
}
hs - > spritegroup = _cur_grffile - > spritegroups [ groupid ] ;
}
}
2008-06-02 19:52:41 +00:00
static void IndustryMapSpriteGroup ( byte * buf , uint8 idcount )
2007-07-10 00:10:19 +00:00
{
2008-06-10 21:59:22 +00:00
uint8 * industries = AllocaM ( uint8 , idcount ) ;
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
industries [ i ] = grf_load_byte ( & buf ) ;
}
/* Skip the cargo type section, we only care about the default group */
uint8 cidcount = grf_load_byte ( & buf ) ;
buf + = cidcount * 3 ;
uint16 groupid = grf_load_word ( & buf ) ;
2008-06-02 19:35:30 +00:00
if ( ! IsValidGroupID ( groupid , " IndustryMapSpriteGroup " ) ) return ;
2007-07-10 00:10:19 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-02 19:52:41 +00:00
IndustrySpec * indsp = _cur_grffile - > industryspec [ industries [ i ] ] ;
2007-07-10 00:10:19 +00:00
if ( indsp = = NULL ) {
grfmsg ( 1 , " IndustryMapSpriteGroup: Too many industries defined, skipping " ) ;
return ;
}
indsp - > grf_prop . spritegroup = _cur_grffile - > spritegroups [ groupid ] ;
}
}
2008-06-02 19:52:41 +00:00
static void IndustrytileMapSpriteGroup ( byte * buf , uint8 idcount )
2007-07-10 00:10:19 +00:00
{
2008-06-10 21:59:22 +00:00
uint8 * indtiles = AllocaM ( uint8 , idcount ) ;
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
indtiles [ i ] = grf_load_byte ( & buf ) ;
}
/* Skip the cargo type section, we only care about the default group */
uint8 cidcount = grf_load_byte ( & buf ) ;
buf + = cidcount * 3 ;
uint16 groupid = grf_load_word ( & buf ) ;
2008-06-02 19:35:30 +00:00
if ( ! IsValidGroupID ( groupid , " IndustrytileMapSpriteGroup " ) ) return ;
2007-07-10 00:10:19 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-02 19:52:41 +00:00
IndustryTileSpec * indtsp = _cur_grffile - > indtspec [ indtiles [ i ] ] ;
2007-07-10 00:10:19 +00:00
if ( indtsp = = NULL ) {
grfmsg ( 1 , " IndustrytileMapSpriteGroup: Too many industry tiles defined, skipping " ) ;
return ;
}
indtsp - > grf_prop . spritegroup = _cur_grffile - > spritegroups [ groupid ] ;
}
}
2007-03-23 20:55:45 +00:00
2008-06-02 19:52:41 +00:00
static void CargoMapSpriteGroup ( byte * buf , uint8 idcount )
2007-03-23 20:55:45 +00:00
{
2008-06-10 21:59:22 +00:00
CargoID * cargos = AllocaM ( CargoID , idcount ) ;
2008-06-02 19:52:41 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
cargos [ i ] = grf_load_byte ( & buf ) ;
}
/* Skip the cargo type section, we only care about the default group */
uint8 cidcount = grf_load_byte ( & buf ) ;
buf + = cidcount * 3 ;
uint16 groupid = grf_load_word ( & buf ) ;
2008-06-02 19:35:30 +00:00
if ( ! IsValidGroupID ( groupid , " CargoMapSpriteGroup " ) ) return ;
2007-03-23 20:55:45 +00:00
for ( uint i = 0 ; i < idcount ; i + + ) {
2008-06-02 19:52:41 +00:00
CargoID cid = cargos [ i ] ;
2007-03-23 20:55:45 +00:00
if ( cid > = NUM_CARGO ) {
2008-06-02 19:52:41 +00:00
grfmsg ( 1 , " CargoMapSpriteGroup: Cargo ID %d out of range, skipping " , cid ) ;
2007-03-23 20:55:45 +00:00
continue ;
}
CargoSpec * cs = & _cargo [ cid ] ;
2008-07-30 18:23:12 +00:00
cs - > grffile = _cur_grffile ;
2007-03-23 20:55:45 +00:00
cs - > group = _cur_grffile - > spritegroups [ groupid ] ;
}
}
2007-03-23 20:01:25 +00:00
/* Action 0x03 */
2008-05-08 13:20:54 +00:00
static void FeatureMapSpriteGroup ( byte * buf , size_t len )
2007-03-23 20:01:25 +00:00
{
/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
* id - list : = [ < id > ] [ id - list ]
* cargo - list : = < cargo - type > < cid > [ cargo - list ]
*
* B feature see action 0
* B n - id bits 0 - 6 : how many IDs this definition applies to
* bit 7 : if set , this is a wagon override definition ( see below )
* B ids the IDs for which this definition applies
* B num - cid number of cargo IDs ( sprite group IDs ) in this definition
* can be zero , in that case the def - cid is used always
* B cargo - type type of this cargo type ( e . g . mail = 2 , wood = 7 , see below )
* W cid cargo ID ( sprite group ID ) for this type of cargo
* W def - cid default cargo ID ( sprite group ID ) */
2008-02-12 13:23:57 +00:00
if ( _cur_grffile - > spritegroups = = 0 ) {
grfmsg ( 1 , " FeatureMapSpriteGroup: No sprite groups to work on! Skipping " ) ;
return ;
}
2007-03-23 20:01:25 +00:00
if ( ! check_length ( len , 6 , " FeatureMapSpriteGroup " ) ) return ;
2008-06-02 19:52:41 +00:00
buf + + ;
uint8 feature = grf_load_byte ( & buf ) ;
uint8 idcount = grf_load_byte ( & buf ) ;
2007-03-23 20:01:25 +00:00
/* If idcount is zero, this is a feature callback */
if ( idcount = = 0 ) {
2008-06-02 19:52:41 +00:00
/* Skip number of cargo ids? */
grf_load_byte ( & buf ) ;
uint16 groupid = grf_load_word ( & buf ) ;
2008-02-12 13:23:57 +00:00
grfmsg ( 6 , " FeatureMapSpriteGroup: Adding generic feature callback for feature %d " , feature ) ;
AddGenericCallback ( feature , _cur_grffile , _cur_grffile - > spritegroups [ groupid ] ) ;
2007-03-23 20:01:25 +00:00
return ;
}
2008-06-02 19:52:41 +00:00
grfmsg ( 6 , " FeatureMapSpriteGroup: Feature %d, %d ids " , feature , idcount ) ;
2007-03-23 20:01:25 +00:00
switch ( feature ) {
case GSF_TRAIN :
case GSF_ROAD :
case GSF_SHIP :
case GSF_AIRCRAFT :
2008-06-02 19:52:41 +00:00
VehicleMapSpriteGroup ( buf , feature , idcount ) ;
2007-03-23 20:01:25 +00:00
return ;
2007-05-06 18:14:33 +00:00
case GSF_CANAL :
2008-06-02 19:52:41 +00:00
CanalMapSpriteGroup ( buf , idcount ) ;
2007-05-06 18:14:33 +00:00
return ;
2007-03-23 20:01:25 +00:00
case GSF_STATION :
2008-06-02 19:52:41 +00:00
StationMapSpriteGroup ( buf , idcount ) ;
2007-03-23 20:01:25 +00:00
return ;
case GSF_TOWNHOUSE :
2008-06-02 19:52:41 +00:00
TownHouseMapSpriteGroup ( buf , idcount ) ;
2007-03-23 20:01:25 +00:00
return ;
2007-07-10 00:10:19 +00:00
case GSF_INDUSTRIES :
2008-06-02 19:52:41 +00:00
IndustryMapSpriteGroup ( buf , idcount ) ;
2007-07-10 00:10:19 +00:00
return ;
case GSF_INDUSTRYTILES :
2008-06-02 19:52:41 +00:00
IndustrytileMapSpriteGroup ( buf , idcount ) ;
2007-07-10 00:10:19 +00:00
return ;
2007-03-23 20:55:45 +00:00
case GSF_CARGOS :
2008-06-02 19:52:41 +00:00
CargoMapSpriteGroup ( buf , idcount ) ;
2007-03-23 20:55:45 +00:00
return ;
2007-03-23 20:01:25 +00:00
default :
grfmsg ( 1 , " FeatureMapSpriteGroup: Unsupported feature %d, skipping " , feature ) ;
return ;
}
}
2004-11-12 15:15:56 +00:00
/* Action 0x04 */
2008-05-08 13:20:54 +00:00
static void FeatureNewName ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
*
2006-04-21 03:00:20 +00:00
* B veh - type see action 0 ( as 00. .07 , + 0 A
* But IF veh - type = 48 , then generic text
* B language - id If bit 6 is set , This is the extended language scheme ,
with up to 64 language .
Otherwise , it is a mapping where set bits have meaning
0 = american , 1 = english , 2 = german , 3 = french , 4 = spanish
Bit 7 set means this is a generic text , not a vehicle one ( or else )
2004-08-09 17:04:08 +00:00
* B num - veh number of vehicles which are getting a new name
2005-08-15 22:48:33 +00:00
* B / W offset number of the first vehicle that gets a new name
2006-04-21 03:00:20 +00:00
* Byte : ID of vehicle to change
* Word : ID of string to change / add
2004-08-09 17:04:08 +00:00
* S data new texts , each of them zero - terminated , after
* which the next name begins . */
2007-03-10 09:55:11 +00:00
2006-04-23 18:37:53 +00:00
bool new_scheme = _cur_grffile - > grf_version > = 7 ;
2004-08-09 17:04:08 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 6 , " FeatureNewName " ) ) return ;
2005-08-15 22:48:33 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 feature = grf_load_byte ( & buf ) ;
uint8 lang = grf_load_byte ( & buf ) ;
uint8 num = grf_load_byte ( & buf ) ;
2007-11-19 21:02:30 +00:00
bool generic = HasBit ( lang , 7 ) ;
2008-06-12 09:25:04 +00:00
uint16 id ;
if ( generic ) {
id = grf_load_word ( & buf ) ;
} else if ( feature < = GSF_AIRCRAFT ) {
id = grf_load_extended ( & buf ) ;
} else {
id = grf_load_byte ( & buf ) ;
}
2006-10-28 18:42:57 +00:00
2007-11-19 21:32:20 +00:00
ClrBit ( lang , 7 ) ;
2005-08-15 22:48:33 +00:00
2007-03-10 09:55:11 +00:00
uint16 endid = id + num ;
2004-08-09 17:04:08 +00:00
2006-12-26 17:36:18 +00:00
grfmsg ( 6 , " FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X " ,
2004-11-13 18:08:45 +00:00
id , endid , feature , lang ) ;
2006-10-28 18:42:57 +00:00
len - = generic ? 6 : 5 ;
2004-11-12 15:36:49 +00:00
for ( ; id < endid & & len > 0 ; id + + ) {
2007-02-20 17:52:43 +00:00
const char * name = grf_load_string ( & buf , len ) ;
size_t name_length = strlen ( name ) + 1 ;
len - = ( int ) name_length ;
2004-11-12 15:36:49 +00:00
2007-05-11 19:22:43 +00:00
grfmsg ( 8 , " FeatureNewName: 0x%04X <- %s " , id , name ) ;
2006-04-21 03:00:20 +00:00
2007-05-11 19:22:43 +00:00
switch ( feature ) {
case GSF_TRAIN :
case GSF_ROAD :
case GSF_SHIP :
case GSF_AIRCRAFT :
2008-06-03 09:58:13 +00:00
if ( ! generic ) {
2008-04-29 21:31:29 +00:00
Engine * e = GetNewEngine ( _cur_grffile , ( VehicleType ) feature , id ) ;
StringID string = AddGRFString ( _cur_grffile - > grfid , e - > index , lang , new_scheme , name , e - > info . string_id ) ;
e - > info . string_id = string ;
2007-05-11 19:22:43 +00:00
} else {
AddGRFString ( _cur_grffile - > grfid , id , lang , new_scheme , name , id ) ;
2006-04-21 20:59:04 +00:00
}
2007-05-11 19:22:43 +00:00
break ;
2006-04-21 03:00:20 +00:00
2007-07-06 20:36:32 +00:00
case GSF_INDUSTRIES : {
AddGRFString ( _cur_grffile - > grfid , id , lang , new_scheme , name , STR_UNDEFINED ) ;
break ;
}
2007-05-11 19:22:43 +00:00
case GSF_TOWNHOUSE :
default :
switch ( GB ( id , 8 , 8 ) ) {
case 0xC4 : // Station class name
if ( _cur_grffile - > stations = = NULL | | _cur_grffile - > stations [ GB ( id , 0 , 8 ) ] = = NULL ) {
grfmsg ( 1 , " FeatureNewName: Attempt to name undefined station 0x%X, ignoring " , GB ( id , 0 , 8 ) ) ;
} else {
StationClassID sclass = _cur_grffile - > stations [ GB ( id , 0 , 8 ) ] - > sclass ;
SetStationClassName ( sclass , AddGRFString ( _cur_grffile - > grfid , id , lang , new_scheme , name , STR_UNDEFINED ) ) ;
2007-03-19 11:27:30 +00:00
}
2007-05-11 19:22:43 +00:00
break ;
2007-03-19 11:27:30 +00:00
2007-05-11 19:22:43 +00:00
case 0xC5 : // Station name
if ( _cur_grffile - > stations = = NULL | | _cur_grffile - > stations [ GB ( id , 0 , 8 ) ] = = NULL ) {
grfmsg ( 1 , " FeatureNewName: Attempt to name undefined station 0x%X, ignoring " , GB ( id , 0 , 8 ) ) ;
} else {
_cur_grffile - > stations [ GB ( id , 0 , 8 ) ] - > name = AddGRFString ( _cur_grffile - > grfid , id , lang , new_scheme , name , STR_UNDEFINED ) ;
}
break ;
2006-09-01 02:56:02 +00:00
2007-05-11 19:22:43 +00:00
case 0xC9 : // House name
if ( _cur_grffile - > housespec = = NULL | | _cur_grffile - > housespec [ GB ( id , 0 , 8 ) ] = = NULL ) {
grfmsg ( 1 , " FeatureNewName: Attempt to name undefined house 0x%X, ignoring. " , GB ( id , 0 , 8 ) ) ;
} else {
2008-04-17 11:47:22 +00:00
_cur_grffile - > housespec [ GB ( id , 0 , 8 ) ] - > building_name = AddGRFString ( _cur_grffile - > grfid , id , lang , new_scheme , name , STR_UNDEFINED ) ;
2007-05-11 19:22:43 +00:00
}
break ;
case 0xD0 :
2008-02-29 08:40:49 +00:00
case 0xD1 :
case 0xD2 :
case 0xD3 :
2007-05-11 19:22:43 +00:00
case 0xDC :
AddGRFString ( _cur_grffile - > grfid , id , lang , new_scheme , name , STR_UNDEFINED ) ;
break ;
default :
grfmsg ( 7 , " FeatureNewName: Unsupported ID (0x%04X) " , id ) ;
break ;
}
break ;
2006-04-21 03:00:20 +00:00
2006-04-23 18:37:06 +00:00
#if 0
2006-04-21 03:00:20 +00:00
case GSF_CANAL :
case GSF_BRIDGE :
AddGRFString ( _cur_spriteid , id , lang , name ) ;
2007-04-18 22:10:36 +00:00
switch ( GB ( id , 8 , 8 ) ) {
2007-03-21 03:06:21 +00:00
case 0xC9 : // House name
2006-04-21 03:00:20 +00:00
default :
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " FeatureNewName: Unsupported ID (0x%04X) " , id ) ;
2006-04-21 03:00:20 +00:00
}
break ;
default :
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " FeatureNewName: Unsupported feature (0x%02X) " , feature ) ;
2006-04-21 03:00:20 +00:00
break ;
# endif
2004-11-13 18:08:45 +00:00
}
2004-08-09 17:04:08 +00:00
}
}
2007-11-15 07:42:25 +00:00
/**
* Sanitize incoming sprite offsets for Action 5 graphics replacements .
* @ param num the number of sprites to load .
* @ param offset offset from the base .
* @ param max_sprites the maximum number of sprites that can be loaded in this action 5.
* @ param name used for error warnings .
* @ return the number of sprites that is going to be skipped
*/
static uint16 SanitizeSpriteOffset ( uint16 & num , uint16 offset , int max_sprites , const char * name )
{
if ( offset > = max_sprites ) {
grfmsg ( 1 , " GraphicsNew: %s sprite offset must be less than %i, skipping " , name , max_sprites ) ;
uint orig_num = num ;
num = 0 ;
return orig_num ;
}
if ( offset + num > max_sprites ) {
grfmsg ( 4 , " GraphicsNew: %s sprite overflow, truncating... " , name ) ;
uint orig_num = num ;
num = max ( max_sprites - offset , 0 ) ;
return orig_num - num ;
}
return 0 ;
}
2004-11-12 15:15:56 +00:00
/* Action 0x05 */
2008-05-08 13:20:54 +00:00
static void GraphicsNew ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <05> <graphics-type> <num-sprites> <other data...>
*
* B graphics - type What set of graphics the sprites define .
2005-08-15 22:48:33 +00:00
* E num - sprites How many sprites are in this set ?
2004-08-09 17:04:08 +00:00
* V other data Graphics type specific data . Currently unused . */
/* TODO */
2004-11-12 15:15:56 +00:00
2008-01-10 18:02:15 +00:00
enum Action5BlockType {
A5BLOCK_FIXED , ///< Only allow replacing a whole block of sprites. (TTDP compatible)
A5BLOCK_ALLOW_OFFSET , ///< Allow replacing any subset by specifiing an offset.
A5BLOCK_INVALID , ///< unknown/not-implemented type
} ;
struct Action5Type {
Action5BlockType block_type ; ///< How is this Action5 type processed?
SpriteID sprite_base ; ///< Load the sprites starting from this sprite.
uint16 min_sprites ; ///< If the Action5 contains less sprites, the whole block will be ignored.
uint16 max_sprites ; ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used.
const char * name ; ///< Name for error messages.
} ;
static const Action5Type action5_types [ ] = {
/* Note: min_sprites should not be changed. Therefore these constants are directly here and not in sprites.h */
2008-06-11 14:55:02 +00:00
/* 0x00 */ { A5BLOCK_INVALID , 0 , 0 , 0 , " Type 0x00 " } ,
/* 0x01 */ { A5BLOCK_INVALID , 0 , 0 , 0 , " Type 0x01 " } ,
/* 0x02 */ { A5BLOCK_INVALID , 0 , 0 , 0 , " Type 0x02 " } ,
/* 0x03 */ { A5BLOCK_INVALID , 0 , 0 , 0 , " Type 0x03 " } ,
/* 0x04 */ { A5BLOCK_FIXED , SPR_SIGNALS_BASE , 48 , PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT , " Signal graphics " } ,
/* 0x05 */ { A5BLOCK_FIXED , SPR_ELRAIL_BASE , 48 , ELRAIL_SPRITE_COUNT , " Catenary graphics " } ,
/* 0x06 */ { A5BLOCK_FIXED , SPR_SLOPES_BASE , 74 , NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT , " Foundation graphics " } ,
/* 0x07 */ { A5BLOCK_INVALID , 0 , 75 , 0 , " TTDP GUI graphics " } , // Not used by OTTD.
/* 0x08 */ { A5BLOCK_FIXED , SPR_CANALS_BASE , 65 , CANALS_SPRITE_COUNT , " Canal graphics " } ,
/* 0x09 */ { A5BLOCK_FIXED , SPR_ONEWAY_BASE , 6 , ONEWAY_SPRITE_COUNT , " One way road graphics " } ,
/* 0x0A */ { A5BLOCK_FIXED , SPR_2CCMAP_BASE , 256 , TWOCCMAP_SPRITE_COUNT , " 2CC colour maps " } ,
/* 0x0B */ { A5BLOCK_FIXED , SPR_TRAMWAY_BASE , 113 , TRAMWAY_SPRITE_COUNT , " Tramway graphics " } ,
/* 0x0C */ { A5BLOCK_INVALID , 0 , 133 , 0 , " Snowy temperate tree " } , // Not yet used by OTTD.
/* 0x0D */ { A5BLOCK_FIXED , SPR_SHORE_BASE , 16 , SPR_SHORE_SPRITE_COUNT , " Shore graphics " } ,
/* 0x0E */ { A5BLOCK_INVALID , 0 , 0 , 0 , " New Signals graphics " } , // Not yet used by OTTD.
/* 0x0F */ { A5BLOCK_FIXED , SPR_TRACKS_FOR_SLOPES_BASE , 12 , TRACKS_FOR_SLOPES_SPRITE_COUNT , " Sloped rail track " } ,
/* 0x10 */ { A5BLOCK_FIXED , SPR_AIRPORTX_BASE , 15 , AIRPORTX_SPRITE_COUNT , " Airport graphics " } ,
/* 0x11 */ { A5BLOCK_FIXED , SPR_ROADSTOP_BASE , 8 , ROADSTOP_SPRITE_COUNT , " Road stop graphics " } ,
/* 0x12 */ { A5BLOCK_FIXED , SPR_AQUEDUCT_BASE , 8 , AQUEDUCT_SPRITE_COUNT , " Aqueduct graphics " } ,
/* 0x13 */ { A5BLOCK_FIXED , SPR_AUTORAIL_BASE , 55 , AUTORAIL_SPRITE_COUNT , " Autorail graphics " } ,
/* 0x14 */ { A5BLOCK_ALLOW_OFFSET , SPR_FLAGS_BASE , 1 , FLAGS_SPRITE_COUNT , " Flag graphics " } ,
/* 0x15 */ { A5BLOCK_ALLOW_OFFSET , SPR_OPENTTD_BASE , 1 , OPENTTD_SPRITE_COUNT , " OpenTTD GUI graphics " } ,
2008-01-10 18:02:15 +00:00
} ;
2004-11-12 15:15:56 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 2 , " GraphicsNew " ) ) return ;
2005-08-15 22:48:33 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 type = grf_load_byte ( & buf ) ;
uint16 num = grf_load_extended ( & buf ) ;
2007-11-19 21:02:30 +00:00
uint16 offset = HasBit ( type , 7 ) ? grf_load_extended ( & buf ) : 0 ;
2007-11-19 21:32:20 +00:00
ClrBit ( type , 7 ) ; // Clear the high bit as that only indicates whether there is an offset.
2004-11-12 15:15:56 +00:00
2008-01-10 18:02:15 +00:00
if ( ( type = = 0x0D ) & & ( num = = 10 ) & & _cur_grffile - > is_ottdfile ) {
/* Special not-TTDP-compatible case used in openttd(d/w).grf
* Missing shore sprites and initialisation of SPR_SHORE_BASE */
grfmsg ( 2 , " GraphicsNew: Loading 10 missing shore sprites from openttd(d/w).grf. " ) ;
2008-06-03 10:22:42 +00:00
LoadNextSprite ( SPR_SHORE_BASE + 0 , _file_index , _nfo_line + + ) ; // SLOPE_STEEP_S
LoadNextSprite ( SPR_SHORE_BASE + 5 , _file_index , _nfo_line + + ) ; // SLOPE_STEEP_W
LoadNextSprite ( SPR_SHORE_BASE + 7 , _file_index , _nfo_line + + ) ; // SLOPE_WSE
LoadNextSprite ( SPR_SHORE_BASE + 10 , _file_index , _nfo_line + + ) ; // SLOPE_STEEP_N
LoadNextSprite ( SPR_SHORE_BASE + 11 , _file_index , _nfo_line + + ) ; // SLOPE_NWS
LoadNextSprite ( SPR_SHORE_BASE + 13 , _file_index , _nfo_line + + ) ; // SLOPE_ENW
LoadNextSprite ( SPR_SHORE_BASE + 14 , _file_index , _nfo_line + + ) ; // SLOPE_SEN
LoadNextSprite ( SPR_SHORE_BASE + 15 , _file_index , _nfo_line + + ) ; // SLOPE_STEEP_E
LoadNextSprite ( SPR_SHORE_BASE + 16 , _file_index , _nfo_line + + ) ; // SLOPE_EW
LoadNextSprite ( SPR_SHORE_BASE + 17 , _file_index , _nfo_line + + ) ; // SLOPE_NS
2008-01-24 14:49:40 +00:00
if ( _loaded_newgrf_features . shore = = SHORE_REPLACE_NONE ) _loaded_newgrf_features . shore = SHORE_REPLACE_ONLY_NEW ;
2008-01-10 18:02:15 +00:00
return ;
}
2007-11-15 07:42:25 +00:00
2008-01-10 18:02:15 +00:00
/* Supported type? */
if ( ( type > = lengthof ( action5_types ) ) | | ( action5_types [ type ] . block_type = = A5BLOCK_INVALID ) ) {
grfmsg ( 2 , " GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring) " , type , num ) ;
_skip_sprites = num ;
return ;
}
2007-11-15 07:42:25 +00:00
2008-01-10 18:02:15 +00:00
const Action5Type * action5_type = & action5_types [ type ] ;
2007-11-15 07:42:25 +00:00
2008-01-10 18:02:15 +00:00
/* Ignore offset if not allowed */
if ( ( action5_type - > block_type ! = A5BLOCK_ALLOW_OFFSET ) & & ( offset ! = 0 ) ) {
grfmsg ( 1 , " GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset. " , action5_type - > name , type ) ;
offset = 0 ;
2006-04-23 15:57:34 +00:00
}
2008-01-10 18:02:15 +00:00
/* Ignore action5 if too few sprites are specified. (for TTDP compatibility)
* This does not make sense , if < offset > is allowed */
if ( ( action5_type - > block_type = = A5BLOCK_FIXED ) & & ( num < action5_type - > min_sprites ) ) {
grfmsg ( 1 , " GraphicsNew: %s (type 0x%02X) count must be at least %d. Only %d were specified. Skipping. " , action5_type - > name , type , action5_type - > min_sprites , num ) ;
_skip_sprites = num ;
return ;
2006-05-01 16:54:18 +00:00
}
2006-04-23 15:57:34 +00:00
2008-01-10 18:02:15 +00:00
/* Load at most max_sprites sprites. Skip remaining sprites. (for compatibility with TTDP and future extentions) */
uint16 skip_num = SanitizeSpriteOffset ( num , offset , action5_type - > max_sprites , action5_type - > name ) ;
SpriteID replace = action5_type - > sprite_base + offset ;
/* Load <num> sprites starting from <replace>, then skip <skip_num> sprites. */
grfmsg ( 2 , " GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X " , offset , offset + num - 1 , action5_type - > name , type , replace ) ;
2006-04-23 15:57:34 +00:00
for ( ; num > 0 ; num - - ) {
_nfo_line + + ;
2007-11-24 10:19:56 +00:00
LoadNextSprite ( replace = = 0 ? _cur_spriteid + + : replace + + , _file_index , _nfo_line ) ;
2006-04-23 15:57:34 +00:00
}
2007-11-15 07:42:25 +00:00
2008-01-24 14:49:40 +00:00
if ( type = = 0x0D ) _loaded_newgrf_features . shore = SHORE_REPLACE_ACTION_5 ;
2007-11-15 07:42:25 +00:00
_skip_sprites = skip_num ;
2004-08-09 17:04:08 +00:00
}
2007-04-26 06:49:32 +00:00
/* Action 0x05 (SKIP) */
2008-05-08 13:20:54 +00:00
static void SkipAct5 ( byte * buf , size_t len )
2007-04-26 06:49:32 +00:00
{
if ( ! check_length ( len , 2 , " SkipAct5 " ) ) return ;
buf + + ;
/* Ignore type byte */
grf_load_byte ( & buf ) ;
/* Skip the sprites of this action */
_skip_sprites = grf_load_extended ( & buf ) ;
grfmsg ( 3 , " SkipAct5: Skipping %d sprites " , _skip_sprites ) ;
}
2008-02-12 15:43:10 +00:00
/**
* Reads a variable common to VarAction2 and Action7 / 9 / D .
*
* Returns VarAction2 variable ' param ' resp . Action7 / 9 / D variable ' 0x80 + param ' .
* If a variable is not accessible from all four actions , it is handled in the action specific functions .
*
* @ param param variable number ( as for VarAction2 , for Action7 / 9 / D you have to subtract 0x80 first ) .
* @ param value returns the value of the variable .
* @ return true iff the variable is known and the value is returned in ' value ' .
*/
bool GetGlobalVariable ( byte param , uint32 * value )
2006-05-10 21:34:57 +00:00
{
switch ( param ) {
2008-02-12 15:43:10 +00:00
case 0x00 : // current date
* value = max ( _date - DAYS_TILL_ORIGINAL_BASE_YEAR , 0 ) ;
return true ;
case 0x01 : // current year
* value = Clamp ( _cur_year , ORIGINAL_BASE_YEAR , ORIGINAL_MAX_YEAR ) - ORIGINAL_BASE_YEAR ;
return true ;
2008-06-20 21:14:10 +00:00
case 0x02 : { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24)
YearMonthDay ymd ;
ConvertDateToYMD ( _date , & ymd ) ;
Date start_of_year = ConvertYMDToDate ( ymd . year , 0 , 1 ) ;
* value = ymd . month | ( ymd . day - 1 ) < < 8 | ( IsLeapYear ( ymd . year ) ? 1 < < 15 : 0 ) | ( _date - start_of_year ) < < 16 ;
2008-02-12 15:43:10 +00:00
return true ;
2008-06-20 21:14:10 +00:00
}
2008-02-12 15:43:10 +00:00
case 0x03 : // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
2008-05-29 15:13:28 +00:00
* value = _settings_game . game_creation . landscape ;
2008-02-12 15:43:10 +00:00
return true ;
case 0x06 : // road traffic side, bit 4 clear=left, set=right
2008-05-29 15:13:28 +00:00
* value = _settings_game . vehicle . road_side < < 4 ;
2008-02-12 15:43:10 +00:00
return true ;
case 0x09 : // date fraction
* value = _date_fract ;
return true ;
case 0x0A : // animation counter
* value = _tick_counter ;
return true ;
case 0x0B : { // TTDPatch version
uint major = 2 ;
uint minor = 6 ;
uint revision = 1 ; // special case: 2.0.1 is 2.0.10
uint build = 1382 ;
* value = ( major < < 24 ) | ( minor < < 20 ) | ( revision < < 16 ) | build ;
return true ;
}
case 0x0D : // TTD Version, 00=DOS, 01=Windows
2008-08-23 20:16:54 +00:00
* value = _use_palette ;
2008-02-12 15:43:10 +00:00
return true ;
case 0x0E : // Y-offset for train sprites
* value = _traininfo_vehicle_pitch ;
return true ;
case 0x0F : // Rail track type cost factors
* value = 0 ;
2008-08-24 23:10:23 +00:00
SB ( * value , 0 , 8 , GetRailTypeInfo ( RAILTYPE_RAIL ) - > cost_multiplier ) ; // normal rail
2008-05-29 15:13:28 +00:00
if ( _settings_game . vehicle . disable_elrails ) {
2008-02-12 15:43:10 +00:00
/* skip elrail multiplier - disabled */
2008-08-24 23:10:23 +00:00
SB ( * value , 8 , 8 , GetRailTypeInfo ( RAILTYPE_MONO ) - > cost_multiplier ) ; // monorail
2008-02-12 15:43:10 +00:00
} else {
2008-08-24 23:10:23 +00:00
SB ( * value , 8 , 8 , GetRailTypeInfo ( RAILTYPE_ELECTRIC ) - > cost_multiplier ) ; // electified railway
2008-02-12 15:43:10 +00:00
/* Skip monorail multiplier - no space in result */
}
2008-08-24 23:10:23 +00:00
SB ( * value , 16 , 8 , GetRailTypeInfo ( RAILTYPE_MAGLEV ) - > cost_multiplier ) ; // maglev
2008-02-12 15:43:10 +00:00
return true ;
case 0x11 : // current rail tool type
* value = 0 ;
return true ;
case 0x12 : // Game mode
* value = _game_mode ;
return true ;
/* case 0x13: // Tile refresh offset to left not implemented */
/* case 0x14: // Tile refresh offset to right not implemented */
/* case 0x15: // Tile refresh offset upwards not implemented */
/* case 0x16: // Tile refresh offset downwards not implemented */
/* case 0x17: // temperate snow line not implemented */
case 0x1A : // Always -1
* value = UINT_MAX ;
return true ;
case 0x1B : // Display options
* value = GB ( _display_opt , 0 , 6 ) ;
return true ;
case 0x1D : // TTD Platform, 00=TTDPatch, 01=OpenTTD
* value = 1 ;
return true ;
case 0x1E : // Miscellaneous GRF features
* value = _misc_grf_features ;
return true ;
/* case 0x1F: // locale dependent settings not implemented */
2006-12-18 15:34:12 +00:00
2008-02-12 15:43:10 +00:00
case 0x20 : // snow line height
2008-05-29 15:13:28 +00:00
* value = _settings_game . game_creation . landscape = = LT_ARCTIC ? GetSnowLine ( ) : 0xFF ;
2008-02-12 15:43:10 +00:00
return true ;
2006-05-10 21:34:57 +00:00
2008-05-04 21:53:36 +00:00
case 0x21 : // OpenTTD version
2008-02-12 15:43:10 +00:00
* value = _openttd_newgrf_version ;
return true ;
2008-03-27 17:06:35 +00:00
case 0x22 : // difficulty level
2008-05-29 15:13:28 +00:00
* value = _settings_game . difficulty . diff_level ;
2008-03-27 17:06:35 +00:00
return true ;
2008-06-04 00:17:48 +00:00
case 0x23 : // long format date
* value = _date ;
return true ;
case 0x24 : // long format year
* value = _cur_year ;
return true ;
2008-02-12 15:43:10 +00:00
default : return false ;
}
}
static uint32 GetParamVal ( byte param , uint32 * cond_val )
{
/* First handle variable common with VarAction2 */
uint32 value ;
if ( GetGlobalVariable ( param - 0x80 , & value ) ) return value ;
/* Non-common variable */
switch ( param ) {
2007-06-07 07:20:44 +00:00
case 0x84 : { // GRF loading stage
uint32 res = 0 ;
2007-11-20 13:35:54 +00:00
if ( _cur_stage > GLS_INIT ) SetBit ( res , 0 ) ;
if ( _cur_stage = = GLS_RESERVE ) SetBit ( res , 8 ) ;
if ( _cur_stage = = GLS_ACTIVATION ) SetBit ( res , 9 ) ;
2007-06-07 07:20:44 +00:00
return res ;
}
2006-05-10 21:34:57 +00:00
2007-03-21 03:06:21 +00:00
case 0x85 : // TTDPatch flags, only for bit tests
2006-05-11 09:54:11 +00:00
if ( cond_val = = NULL ) {
/* Supported in Action 0x07 and 0x09, not 0x0D */
return 0 ;
} else {
uint32 param_val = _ttdpatch_flags [ * cond_val / 0x20 ] ;
* cond_val % = 0x20 ;
return param_val ;
}
2006-05-10 21:34:57 +00:00
2007-03-21 03:06:21 +00:00
case 0x88 : // GRF ID check
2006-05-10 21:34:57 +00:00
return 0 ;
2008-02-12 15:43:10 +00:00
/* case 0x99: Global ID offest not implemented */
2007-10-21 14:59:05 +00:00
2006-05-10 21:34:57 +00:00
default :
/* GRF Parameter */
if ( param < 0x80 ) return _cur_grffile - > param [ param ] ;
/* In-game variable. */
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " Unsupported in-game variable 0x%02X " , param ) ;
2007-01-10 18:56:51 +00:00
return UINT_MAX ;
2006-05-10 21:34:57 +00:00
}
}
2006-05-23 20:59:01 +00:00
/* Action 0x06 */
2008-05-08 13:20:54 +00:00
static void CfgApply ( byte * buf , size_t len )
2006-05-23 20:59:01 +00:00
{
/* <06> <param-num> <param-size> <offset> ... <FF>
*
* B param - num Number of parameter to substitute ( First = " zero " )
* Ignored if that parameter was not specified in newgrf . cfg
* B param - size How many bytes to replace . If larger than 4 , the
* bytes of the following parameter are used . In that
* case , nothing is applied unless * all * parameters
* were specified .
* B offset Offset into data from beginning of next sprite
* to place where parameter is to be stored . */
/* Preload the next sprite */
2008-05-27 21:41:00 +00:00
size_t pos = FioGetPos ( ) ;
2006-05-23 20:59:01 +00:00
uint16 num = FioReadWord ( ) ;
uint8 type = FioReadByte ( ) ;
2008-08-19 09:08:45 +00:00
byte * preload_sprite = NULL ;
2006-05-23 20:59:01 +00:00
/* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */
if ( type = = 0xFF ) {
2008-08-19 09:08:45 +00:00
preload_sprite = MallocT < byte > ( num ) ;
FioReadBlock ( preload_sprite , num ) ;
2006-05-23 20:59:01 +00:00
}
/* Reset the file position to the start of the next sprite */
FioSeekTo ( pos , SEEK_SET ) ;
if ( type ! = 0xFF ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " CfgApply: Ignoring (next sprite is real, unsupported) " ) ;
2008-08-19 09:08:45 +00:00
free ( preload_sprite ) ;
2006-05-23 20:59:01 +00:00
return ;
}
2008-08-19 09:08:45 +00:00
GRFLocation location ( _cur_grfconfig - > grfid , _nfo_line + 1 ) ;
GRFLineToSpriteOverride : : iterator it = _grf_line_to_action6_sprite_override . find ( location ) ;
if ( it ! = _grf_line_to_action6_sprite_override . end ( ) ) {
free ( preload_sprite ) ;
preload_sprite = _grf_line_to_action6_sprite_override [ location ] ;
} else {
_grf_line_to_action6_sprite_override [ location ] = preload_sprite ;
}
2006-05-23 20:59:01 +00:00
/* Now perform the Action 0x06 on our data. */
buf + + ;
for ( ; ; ) {
uint i ;
uint param_num ;
uint param_size ;
uint offset ;
bool add_value ;
/* Read the parameter to apply. 0xFF indicates no more data to change. */
param_num = grf_load_byte ( & buf ) ;
if ( param_num = = 0xFF ) break ;
/* Get the size of the parameter to use. If the size covers multiple
* double words , sequential parameter values are used . */
param_size = grf_load_byte ( & buf ) ;
/* Bit 7 of param_size indicates we should add to the original value
* instead of replacing it . */
2007-11-19 21:02:30 +00:00
add_value = HasBit ( param_size , 7 ) ;
2006-05-23 20:59:01 +00:00
param_size = GB ( param_size , 0 , 7 ) ;
/* Where to apply the data to within the pseudo sprite data. */
offset = grf_load_extended ( & buf ) ;
/* If the parameter is a GRF parameter (not an internal variable) check
* if it ( and all further sequential parameters ) has been defined . */
if ( param_num < 0x80 & & ( param_num + ( param_size - 1 ) / 4 ) > = _cur_grffile - > param_end ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " CfgApply: Ignoring (param %d not set) " , ( param_num + ( param_size - 1 ) / 4 ) ) ;
2006-05-23 20:59:01 +00:00
break ;
}
2006-12-26 17:36:18 +00:00
grfmsg ( 8 , " CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X " , param_size , param_num , offset ) ;
2006-05-23 20:59:01 +00:00
2007-05-19 22:37:24 +00:00
bool carry = false ;
2006-05-23 20:59:01 +00:00
for ( i = 0 ; i < param_size ; i + + ) {
uint32 value = GetParamVal ( param_num + i / 4 , NULL ) ;
2007-05-19 22:37:24 +00:00
/* Reset carry flag for each iteration of the variable (only really
* matters if param_size is greater than 4 ) */
if ( i = = 0 ) carry = false ;
2006-05-23 20:59:01 +00:00
if ( add_value ) {
2008-08-19 09:08:45 +00:00
uint new_value = preload_sprite [ offset + i ] + GB ( value , ( i % 4 ) * 8 , 8 ) + ( carry ? 1 : 0 ) ;
preload_sprite [ offset + i ] = GB ( new_value , 0 , 8 ) ;
2007-05-19 22:37:24 +00:00
/* Check if the addition overflowed */
carry = new_value > = 256 ;
2006-05-23 20:59:01 +00:00
} else {
2008-08-19 09:08:45 +00:00
preload_sprite [ offset + i ] = GB ( value , ( i % 4 ) * 8 , 8 ) ;
2006-05-23 20:59:01 +00:00
}
}
}
}
2008-06-19 10:20:45 +00:00
/**
* Disable a static NewGRF when it is influencing another ( non - static )
* NewGRF as this could cause desyncs .
*
* We could just tell the NewGRF querying that the file doesn ' t exist ,
* but that might give unwanted results . Disabling the NewGRF gives the
* best result as no NewGRF author can complain about that .
* @ param c the NewGRF to disable .
*/
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs ( GRFConfig * c )
{
if ( c - > error ! = NULL ) {
free ( c - > error - > custom_message ) ;
free ( c - > error - > data ) ;
free ( c - > error ) ;
}
c - > status = GCS_DISABLED ;
c - > error = CallocT < GRFError > ( 1 ) ;
c - > error - > data = strdup ( _cur_grfconfig - > name ) ;
c - > error - > severity = STR_NEWGRF_ERROR_MSG_FATAL ;
c - > error - > message = STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
_skip_sprites = - 1 ;
2008-06-19 10:20:45 +00:00
}
2004-11-12 15:15:56 +00:00
/* Action 0x07 */
/* Action 0x09 */
2008-05-08 13:20:54 +00:00
static void SkipIf ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
*
* B param - num
* B param - size
* B condition - type
* V value
* B num - sprites */
/* TODO: More params. More condition types. */
2005-08-13 16:23:07 +00:00
uint32 cond_val = 0 ;
2006-05-10 21:34:57 +00:00
uint32 mask = 0 ;
2004-11-12 18:43:12 +00:00
bool result ;
2004-11-12 15:36:49 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 6 , " SkipIf " ) ) return ;
2006-05-02 09:18:51 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 param = grf_load_byte ( & buf ) ;
uint8 paramsize = grf_load_byte ( & buf ) ;
uint8 condtype = grf_load_byte ( & buf ) ;
2004-11-12 15:36:49 +00:00
2004-11-12 17:27:30 +00:00
if ( condtype < 2 ) {
2005-04-01 10:43:20 +00:00
/* Always 1 for bit tests, the given value should be ignored. */
2004-11-12 17:27:30 +00:00
paramsize = 1 ;
}
2005-04-01 10:43:20 +00:00
switch ( paramsize ) {
2006-05-10 21:34:57 +00:00
case 4 : cond_val = grf_load_dword ( & buf ) ; mask = 0xFFFFFFFF ; break ;
case 2 : cond_val = grf_load_word ( & buf ) ; mask = 0x0000FFFF ; break ;
case 1 : cond_val = grf_load_byte ( & buf ) ; mask = 0x000000FF ; break ;
2005-04-01 10:43:20 +00:00
default : break ;
}
2004-11-12 17:27:30 +00:00
2006-05-10 21:34:57 +00:00
if ( param < 0x80 & & _cur_grffile - > param_end < = param ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " SkipIf: Param %d undefined, skipping test " , param ) ;
2006-05-10 21:34:57 +00:00
return ;
}
2005-08-13 16:23:07 +00:00
2007-03-10 09:55:11 +00:00
uint32 param_val = GetParamVal ( param , & cond_val ) ;
2006-05-10 21:34:57 +00:00
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X " , condtype , param_val , cond_val ) ;
2006-12-04 13:45:20 +00:00
2007-10-30 17:24:04 +00:00
/*
* Parameter ( variable in specs ) 0x88 can only have GRF ID checking
* conditions , except conditions 0x0B and 0x0C ( cargo availability )
* as those ignore the parameter . So , when the condition type is
* either of those , the specific variable 0x88 code is skipped , so
* the " general " code for the cargo availability conditions kicks in .
*/
if ( param = = 0x88 & & condtype ! = 0x0B & & condtype ! = 0x0C ) {
2007-01-01 01:40:56 +00:00
/* GRF ID checks */
2006-12-04 13:45:20 +00:00
2008-06-19 10:20:45 +00:00
GRFConfig * c = GetGRFConfig ( cond_val ) ;
if ( c ! = NULL & & HasBit ( c - > flags , GCF_STATIC ) & & ! HasBit ( _cur_grfconfig - > flags , GCF_STATIC ) & & c - > status ! = GCS_DISABLED & & _networking ) {
DisableStaticNewGRFInfluencingNonStaticNewGRFs ( c ) ;
c = NULL ;
}
2006-12-04 13:45:20 +00:00
2007-01-01 01:40:56 +00:00
if ( condtype ! = 10 & & c = = NULL ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " SkipIf: GRFID 0x%08X unknown, skipping test " , BSWAP32 ( cond_val ) ) ;
2007-01-01 01:40:56 +00:00
return ;
2006-12-04 13:45:20 +00:00
}
2007-01-01 01:40:56 +00:00
switch ( condtype ) {
2007-10-30 17:24:04 +00:00
/* Tests 0x06 to 0x0A are only for param 0x88, GRFID checks */
case 0x06 : // Is GRFID active?
2007-03-06 19:33:28 +00:00
result = c - > status = = GCS_ACTIVATED ;
2007-01-01 01:40:56 +00:00
break ;
2006-12-04 13:45:20 +00:00
2007-10-30 17:24:04 +00:00
case 0x07 : // Is GRFID non-active?
2007-03-06 19:33:28 +00:00
result = c - > status ! = GCS_ACTIVATED ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x08 : // GRFID is not but will be active?
2007-03-06 19:33:28 +00:00
result = c - > status = = GCS_INITIALISED ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x09 : // GRFID is or will be active?
2007-03-06 19:33:28 +00:00
result = c - > status = = GCS_ACTIVATED | | c - > status = = GCS_INITIALISED ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x0A : // GRFID is not nor will be active
2007-01-01 01:40:56 +00:00
/* This is the only condtype that doesn't get ignored if the GRFID is not found */
2007-03-06 19:33:28 +00:00
result = c = = NULL | | c - > flags = = GCS_DISABLED | | c - > status = = GCS_NOT_FOUND ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
default : grfmsg ( 1 , " SkipIf: Unsupported GRF condition type %02X. Ignoring " , condtype ) ; return ;
2006-12-04 13:45:20 +00:00
}
2007-01-01 01:40:56 +00:00
} else {
/* Parameter or variable tests */
switch ( condtype ) {
2007-10-30 17:24:04 +00:00
case 0x00 : result = ! ! ( param_val & ( 1 < < cond_val ) ) ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x01 : result = ! ( param_val & ( 1 < < cond_val ) ) ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x02 : result = ( param_val & mask ) = = cond_val ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x03 : result = ( param_val & mask ) ! = cond_val ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x04 : result = ( param_val & mask ) < cond_val ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x05 : result = ( param_val & mask ) > cond_val ;
2007-01-01 01:40:56 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x0B : result = GetCargoIDByLabel ( BSWAP32 ( cond_val ) ) = = CT_INVALID ;
2007-05-19 19:13:12 +00:00
break ;
2007-10-30 17:24:04 +00:00
case 0x0C : result = GetCargoIDByLabel ( BSWAP32 ( cond_val ) ) ! = CT_INVALID ;
2007-05-19 19:13:12 +00:00
break ;
2006-12-04 13:45:20 +00:00
2007-10-30 17:24:04 +00:00
default : grfmsg ( 1 , " SkipIf: Unsupported condition type %02X. Ignoring " , condtype ) ; return ;
2007-01-01 01:40:56 +00:00
}
2004-11-12 15:36:49 +00:00
}
2004-08-09 17:04:08 +00:00
2005-03-30 12:30:24 +00:00
if ( ! result ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 2 , " SkipIf: Not skipping sprites, test was false " ) ;
2004-11-12 15:36:49 +00:00
return ;
2004-11-12 17:27:30 +00:00
}
2007-03-10 09:55:11 +00:00
uint8 numsprites = grf_load_byte ( & buf ) ;
2006-04-15 21:27:59 +00:00
/* numsprites can be a GOTO label if it has been defined in the GRF
* file . The jump will always be the first matching label that follows
* the current nfo_line . If no matching label is found , the first matching
* label in the file is used . */
2007-03-10 09:55:11 +00:00
GRFLabel * choice = NULL ;
for ( GRFLabel * label = _cur_grffile - > label ; label ! = NULL ; label = label - > next ) {
2006-04-15 21:27:59 +00:00
if ( label - > label ! = numsprites ) continue ;
/* Remember a goto before the current line */
if ( choice = = NULL ) choice = label ;
/* If we find a label here, this is definitely good */
if ( label - > nfo_line > _nfo_line ) {
choice = label ;
break ;
}
}
if ( choice ! = NULL ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 2 , " SkipIf: Jumping to label 0x%0X at line %d, test was true " , choice - > label , choice - > nfo_line ) ;
2006-04-15 21:27:59 +00:00
FioSeekTo ( choice - > pos , SEEK_SET ) ;
_nfo_line = choice - > nfo_line ;
return ;
}
2007-04-16 20:56:19 +00:00
grfmsg ( 2 , " SkipIf: Skipping %d sprites, test was true " , numsprites ) ;
2004-11-12 15:36:49 +00:00
_skip_sprites = numsprites ;
if ( _skip_sprites = = 0 ) {
/* Zero means there are no sprites to skip, so
* we use - 1 to indicate that all further
* sprites should be skipped . */
_skip_sprites = - 1 ;
2007-02-21 17:54:30 +00:00
/* If an action 8 hasn't been encountered yet, disable the grf. */
2007-12-16 22:21:34 +00:00
if ( _cur_grfconfig - > status ! = GCS_ACTIVATED ) {
2007-06-17 11:01:58 +00:00
_cur_grfconfig - > status = GCS_DISABLED ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
2007-06-17 11:01:58 +00:00
}
2004-08-09 17:04:08 +00:00
}
}
2006-12-10 21:39:38 +00:00
2007-01-03 11:33:54 +00:00
/* Action 0x08 (GLS_FILESCAN) */
2008-05-08 13:20:54 +00:00
static void ScanInfo ( byte * buf , size_t len )
2006-12-04 08:30:04 +00:00
{
2007-03-10 09:55:11 +00:00
if ( ! check_length ( len , 8 , " Info " ) ) return ;
buf + + ;
grf_load_byte ( & buf ) ;
uint32 grfid = grf_load_dword ( & buf ) ;
2006-12-04 08:30:04 +00:00
_cur_grfconfig - > grfid = grfid ;
2006-12-10 21:39:38 +00:00
2006-12-12 19:38:41 +00:00
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
2007-11-20 13:35:54 +00:00
if ( GB ( grfid , 24 , 8 ) = = 0xFF ) SetBit ( _cur_grfconfig - > flags , GCF_SYSTEM ) ;
2006-12-12 19:38:41 +00:00
2006-12-10 21:39:38 +00:00
len - = 6 ;
2007-03-10 09:55:11 +00:00
const char * name = grf_load_string ( & buf , len ) ;
2008-02-29 08:48:01 +00:00
_cur_grfconfig - > name = TranslateTTDPatchCodes ( grfid , name ) ;
2006-12-10 21:39:38 +00:00
2007-03-01 23:37:05 +00:00
len - = strlen ( name ) + 1 ;
if ( len > 0 ) {
2007-03-10 09:55:11 +00:00
const char * info = grf_load_string ( & buf , len ) ;
2008-02-29 08:48:01 +00:00
_cur_grfconfig - > info = TranslateTTDPatchCodes ( grfid , info ) ;
2006-12-10 21:39:38 +00:00
}
2006-12-04 08:30:04 +00:00
2006-12-12 19:38:41 +00:00
/* GLS_INFOSCAN only looks for the action 8, so we can skip the rest of the file */
2006-12-04 08:30:04 +00:00
_skip_sprites = - 1 ;
}
2006-04-23 18:03:55 +00:00
/* Action 0x08 */
2008-05-08 13:20:54 +00:00
static void GRFInfo ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <08> <version> <grf-id> <name> <info>
*
* B version newgrf version , currently 06
* 4 * B grf - id globally unique ID of this . grf file
* S name name of this . grf set
* S info string describing the set , and e . g . author and copyright */
2004-11-12 15:36:49 +00:00
2007-03-10 09:55:11 +00:00
if ( ! check_length ( len , 8 , " GRFInfo " ) ) return ;
buf + + ;
uint8 version = grf_load_byte ( & buf ) ;
uint32 grfid = grf_load_dword ( & buf ) ;
const char * name = grf_load_string ( & buf , len - 6 ) ;
2004-11-12 22:28:19 +00:00
_cur_grffile - > grfid = grfid ;
2006-04-23 18:03:55 +00:00
_cur_grffile - > grf_version = version ;
2007-06-05 21:41:31 +00:00
_cur_grfconfig - > status = _cur_stage < GLS_RESERVE ? GCS_INITIALISED : GCS_ACTIVATED ;
2004-11-12 22:28:19 +00:00
2006-05-01 21:45:35 +00:00
/* Do swap the GRFID for displaying purposes since people expect that */
2007-04-16 20:56:19 +00:00
DEBUG ( grf , 1 , " GRFInfo: Loaded GRFv%d set %08lX - %s " , version , BSWAP32 ( grfid ) , name ) ;
2004-08-09 17:04:08 +00:00
}
2006-04-23 18:03:55 +00:00
/* Action 0x0A */
2008-05-08 13:20:54 +00:00
static void SpriteReplace ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <0A> <num-sets> <set1> [<set2> ...]
* < set > : < num - sprites > < first - sprite >
*
* B num - sets How many sets of sprites to replace .
* Each set :
* B num - sprites How many sprites are in this set
* W first - sprite First sprite number to replace */
2004-11-12 18:47:19 +00:00
2007-03-21 03:06:21 +00:00
buf + + ; // skip action byte
2007-03-10 09:55:11 +00:00
uint8 num_sets = grf_load_byte ( & buf ) ;
2004-11-12 18:47:19 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < num_sets ; i + + ) {
2005-08-15 11:39:13 +00:00
uint8 num_sprites = grf_load_byte ( & buf ) ;
uint16 first_sprite = grf_load_word ( & buf ) ;
2004-11-14 13:59:11 +00:00
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " SpriteReplace: [Set %d] Changing %d sprites, beginning with %d " ,
2005-08-15 11:39:13 +00:00
i , num_sprites , first_sprite
) ;
2004-11-12 18:47:19 +00:00
2007-03-10 09:55:11 +00:00
for ( uint j = 0 ; j < num_sprites ; j + + ) {
2008-01-03 02:39:06 +00:00
int load_index = first_sprite + j ;
2006-04-15 16:40:54 +00:00
_nfo_line + + ;
2008-01-03 02:39:06 +00:00
LoadNextSprite ( load_index , _file_index , _nfo_line ) ; // XXX
2008-01-24 14:49:40 +00:00
/* Shore sprites now located at different addresses.
* So detect when the old ones get replaced . */
if ( IsInsideMM ( load_index , SPR_ORIGINALSHORE_START , SPR_ORIGINALSHORE_END + 1 ) ) {
if ( _loaded_newgrf_features . shore ! = SHORE_REPLACE_ACTION_5 ) _loaded_newgrf_features . shore = SHORE_REPLACE_ACTION_A ;
}
2004-11-12 18:47:19 +00:00
}
}
2004-08-09 17:04:08 +00:00
}
2007-04-26 06:49:32 +00:00
/* Action 0x0A (SKIP) */
2008-05-08 13:20:54 +00:00
static void SkipActA ( byte * buf , size_t len )
2007-04-26 06:49:32 +00:00
{
buf + + ;
uint8 num_sets = grf_load_byte ( & buf ) ;
for ( uint i = 0 ; i < num_sets ; i + + ) {
/* Skip the sprites this replaces */
_skip_sprites + = grf_load_byte ( & buf ) ;
/* But ignore where they go */
grf_load_word ( & buf ) ;
}
grfmsg ( 3 , " SkipActA: Skipping %d sprites " , _skip_sprites ) ;
}
2006-05-02 09:31:59 +00:00
/* Action 0x0B */
2008-05-08 13:20:54 +00:00
static void GRFLoadError ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>]
*
* B severity 00 : notice , contine loading grf file
* 01 : warning , continue loading grf file
* 02 : error , but continue loading grf file , and attempt
* loading grf again when loading or starting next game
* 03 : error , abort loading and prevent loading again in
* the future ( only when restarting the patch )
* B language - id see action 4 , use 1F for built - in error messages
* B message - id message to show , see below
* S message for custom messages ( message - id FF ) , text of the message
* not present for built - in messages .
* V data additional data for built - in ( or custom ) messages
2007-02-24 16:34:37 +00:00
* B parnum parameter numbers to be shown in the message ( maximum of 2 ) */
static const StringID msgstr [ ] = {
STR_NEWGRF_ERROR_VERSION_NUMBER ,
STR_NEWGRF_ERROR_DOS_OR_WINDOWS ,
STR_NEWGRF_ERROR_UNSET_SWITCH ,
STR_NEWGRF_ERROR_INVALID_PARAMETER ,
STR_NEWGRF_ERROR_LOAD_BEFORE ,
2007-10-21 14:59:05 +00:00
STR_NEWGRF_ERROR_LOAD_AFTER ,
STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER ,
2004-08-09 17:04:08 +00:00
} ;
2006-12-26 17:22:47 +00:00
2007-02-24 16:34:37 +00:00
static const StringID sevstr [ ] = {
STR_NEWGRF_ERROR_MSG_INFO ,
STR_NEWGRF_ERROR_MSG_WARNING ,
STR_NEWGRF_ERROR_MSG_ERROR ,
STR_NEWGRF_ERROR_MSG_FATAL
2006-12-26 17:22:47 +00:00
} ;
2004-08-09 17:04:08 +00:00
2007-02-24 16:34:37 +00:00
if ( ! check_length ( len , 6 , " GRFLoadError " ) ) return ;
/* For now we can only show one message per newgrf file. */
if ( _cur_grfconfig - > error ! = NULL ) return ;
2007-02-20 17:52:43 +00:00
2007-03-21 03:06:21 +00:00
buf + + ; // Skip the action byte.
2007-02-21 17:20:44 +00:00
byte severity = grf_load_byte ( & buf ) ;
2007-02-24 16:34:37 +00:00
byte lang = grf_load_byte ( & buf ) ;
2007-02-21 17:20:44 +00:00
byte message_id = grf_load_byte ( & buf ) ;
len - = 4 ;
2007-02-20 17:52:43 +00:00
2007-06-12 13:22:14 +00:00
/* Skip the error if it isn't valid for the current language. */
if ( ! CheckGrfLangID ( lang , _cur_grffile - > grf_version ) ) return ;
2007-02-21 17:20:44 +00:00
/* Skip the error until the activation stage unless bit 7 of the severity
* is set . */
2007-11-19 21:02:30 +00:00
if ( ! HasBit ( severity , 7 ) & & _cur_stage = = GLS_INIT ) {
2007-06-05 20:49:32 +00:00
grfmsg ( 7 , " GRFLoadError: Skipping non-fatal GRFLoadError in stage %d " , _cur_stage ) ;
2004-11-17 02:01:12 +00:00
return ;
2006-04-19 07:50:16 +00:00
}
2007-11-19 21:32:20 +00:00
ClrBit ( severity , 7 ) ;
2007-02-21 17:20:44 +00:00
if ( severity > = lengthof ( sevstr ) ) {
2007-02-24 16:34:37 +00:00
grfmsg ( 7 , " GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error). " , severity ) ;
2007-02-21 17:20:44 +00:00
severity = 2 ;
} else if ( severity = = 3 ) {
/* This is a fatal error, so make sure the GRF is deactivated and no
* more of it gets loaded . */
2007-03-06 19:33:28 +00:00
_cur_grfconfig - > status = GCS_DISABLED ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
2007-02-21 17:20:44 +00:00
_skip_sprites = - 1 ;
}
if ( message_id > = lengthof ( msgstr ) & & message_id ! = 0xFF ) {
2007-02-24 16:34:37 +00:00
grfmsg ( 7 , " GRFLoadError: Invalid message id. " ) ;
2007-02-21 17:20:44 +00:00
return ;
}
if ( len < = 1 ) {
2007-02-24 16:34:37 +00:00
grfmsg ( 7 , " GRFLoadError: No message data supplied. " ) ;
2007-02-21 17:20:44 +00:00
return ;
}
2004-11-17 02:01:12 +00:00
2007-02-24 16:34:37 +00:00
GRFError * error = CallocT < GRFError > ( 1 ) ;
error - > severity = sevstr [ severity ] ;
if ( message_id = = 0xFF ) {
/* This is a custom error message. */
const char * message = grf_load_string ( & buf , len ) ;
len - = ( strlen ( message ) + 1 ) ;
2008-02-29 08:48:01 +00:00
error - > custom_message = TranslateTTDPatchCodes ( _cur_grffile - > grfid , message ) ;
2007-02-24 16:34:37 +00:00
} else {
error - > message = msgstr [ message_id ] ;
}
if ( len > 0 ) {
const char * data = grf_load_string ( & buf , len ) ;
len - = ( strlen ( data ) + 1 ) ;
2008-02-29 08:48:01 +00:00
error - > data = TranslateTTDPatchCodes ( _cur_grffile - > grfid , data ) ;
2007-02-24 16:34:37 +00:00
}
2007-02-21 23:18:08 +00:00
2007-02-24 16:34:37 +00:00
/* Only two parameter numbers can be used in the string. */
uint i = 0 ;
for ( ; i < 2 & & len > 0 ; i + + ) {
error - > param_number [ i ] = grf_load_byte ( & buf ) ;
len - - ;
2007-02-21 23:18:08 +00:00
}
2007-02-24 16:34:37 +00:00
error - > num_params = i ;
2007-02-21 23:18:08 +00:00
2007-02-24 16:34:37 +00:00
_cur_grfconfig - > error = error ;
2004-08-09 17:04:08 +00:00
}
2006-05-02 09:31:59 +00:00
/* Action 0x0C */
2008-05-08 13:20:54 +00:00
static void GRFComment ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <0C> [<ignored...>]
*
* V ignored Anything following the 0 C is ignored */
2006-04-15 21:27:59 +00:00
if ( len = = 1 ) return ;
2008-05-08 13:20:54 +00:00
size_t text_len = len - 1 ;
2007-02-22 15:01:38 +00:00
const char * text = ( const char * ) ( buf + 1 ) ;
grfmsg ( 2 , " GRFComment: %.*s " , text_len , text ) ;
2004-08-09 17:04:08 +00:00
}
2007-01-04 19:24:42 +00:00
/* Action 0x0D (GLS_SAFETYSCAN) */
2008-05-08 13:20:54 +00:00
static void SafeParamSet ( byte * buf , size_t len )
2007-01-04 19:24:42 +00:00
{
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 5 , " SafeParamSet " ) ) return ;
2007-01-04 19:24:42 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 target = grf_load_byte ( & buf ) ;
2007-01-04 19:24:42 +00:00
/* Only writing GRF parameters is considered safe */
if ( target < 0x80 ) return ;
/* GRM could be unsafe, but as here it can only happen after other GRFs
* are loaded , it should be okay . If the GRF tried to use the slots it
* reserved , it would be marked unsafe anyway . GRM for ( e . g . bridge )
* sprites is considered safe . */
2007-11-20 13:35:54 +00:00
SetBit ( _cur_grfconfig - > flags , GCF_UNSAFE ) ;
2007-01-04 19:24:42 +00:00
/* Skip remainder of GRF */
_skip_sprites = - 1 ;
}
2007-04-20 21:19:28 +00:00
static uint32 GetPatchVariable ( uint8 param )
{
switch ( param ) {
/* start year - 1920 */
2008-05-29 15:13:28 +00:00
case 0x0B : return max ( _settings_game . game_creation . starting_year , ORIGINAL_BASE_YEAR ) - ORIGINAL_BASE_YEAR ;
2008-01-23 17:08:35 +00:00
2007-04-20 21:19:28 +00:00
/* freight trains weight factor */
2008-05-29 15:13:28 +00:00
case 0x0E : return _settings_game . vehicle . freight_trains ;
2008-01-23 17:08:35 +00:00
2007-04-20 21:19:28 +00:00
/* empty wagon speed increase */
case 0x0F : return 0 ;
2008-01-23 17:08:35 +00:00
2008-02-27 21:33:52 +00:00
/* plane speed factor; our patch option is reversed from TTDPatch's,
* the following is good for 1 x , 2 x and 4 x ( most common ? ) and . . .
* well not really for 3 x . */
case 0x10 :
2008-05-29 15:13:28 +00:00
switch ( _settings_game . vehicle . plane_speed ) {
2008-02-27 21:33:52 +00:00
default :
case 4 : return 1 ;
case 3 : return 2 ;
case 2 : return 2 ;
case 1 : return 4 ;
}
2008-01-23 17:08:35 +00:00
2007-04-20 21:19:28 +00:00
/* 2CC colormap base sprite */
case 0x11 : return SPR_2CCMAP_BASE ;
2008-01-23 17:08:35 +00:00
/* map size: format = -MABXYSS
* M : the type of map
* bit 0 : set : squared map . Bit 1 is now not relevant
* clear : rectangle map . Bit 1 will indicate the bigger edge of the map
* bit 1 : set : Y is the bigger edge . Bit 0 is clear
* clear : X is the bigger edge .
* A : minimum edge ( log2 ) of the map
* B : maximum edge ( log2 ) of the map
* XY : edges ( log2 ) of each side of the map .
* SS : combination of both X and Y , thus giving the size ( log2 ) of the map
*/
case 0x13 : {
byte map_bits = 0 ;
2008-01-23 17:40:37 +00:00
byte log_X = MapLogX ( ) - 6 ; // substraction is required to make the minimal size (64) zero based
2008-01-23 17:08:35 +00:00
byte log_Y = MapLogY ( ) - 6 ;
byte max_edge = max ( log_X , log_Y ) ;
if ( log_X = = log_Y ) { // we have a squared map, since both edges are identical
SetBit ( map_bits , 0 ) ;
} else {
if ( max_edge = = log_Y ) SetBit ( map_bits , 1 ) ; // edge Y been the biggest, mark it
}
return ( map_bits < < 24 ) | ( min ( log_X , log_Y ) < < 20 ) | ( max_edge < < 16 ) |
( log_X < < 12 ) | ( log_Y < < 8 ) | ( log_X + log_Y ) ;
}
2007-04-20 21:19:28 +00:00
default :
grfmsg ( 2 , " ParamSet: Unknown Patch variable 0x%02X. " , param ) ;
return 0 ;
}
}
2007-06-02 08:56:21 +00:00
static uint32 PerformGRM ( uint32 * grm , uint16 num_ids , uint16 count , uint8 op , uint8 target , const char * type )
{
uint start = 0 ;
uint size = 0 ;
if ( op = = 6 ) {
/* Return GRFID of set that reserved ID */
return grm [ _cur_grffile - > param [ target ] ] ;
}
/* With an operation of 2 or 3, we want to reserve a specific block of IDs */
if ( op = = 2 | | op = = 3 ) start = _cur_grffile - > param [ target ] ;
for ( uint i = start ; i < num_ids ; i + + ) {
if ( grm [ i ] = = 0 ) {
size + + ;
} else {
if ( op = = 2 | | op = = 3 ) break ;
start = i + 1 ;
size = 0 ;
}
if ( size = = count ) break ;
}
if ( size = = count ) {
/* Got the slot... */
if ( op = = 0 | | op = = 3 ) {
grfmsg ( 2 , " ParamSet: GRM: Reserving %d %s at %d " , count , type , start ) ;
for ( uint i = 0 ; i < count ; i + + ) grm [ start + i ] = _cur_grffile - > grfid ;
}
return start ;
}
/* Unable to allocate */
if ( op ! = 4 & & op ! = 5 ) {
/* Deactivate GRF */
grfmsg ( 0 , " ParamSet: GRM: Unable to allocate %d %s, deactivating " , count , type ) ;
_cur_grfconfig - > status = GCS_DISABLED ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
2007-06-02 08:56:21 +00:00
_skip_sprites = - 1 ;
return UINT_MAX ;
}
grfmsg ( 1 , " ParamSet: GRM: Unable to allocate %d %s " , count , type ) ;
return UINT_MAX ;
}
2004-11-12 15:15:56 +00:00
/* Action 0x0D */
2008-05-08 13:20:54 +00:00
static void ParamSet ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <0D> <target> <operation> <source1> <source2> [<data>]
*
* B target parameter number where result is stored
* B operation operation to perform , see below
* B source1 first source operand
* B source2 second source operand
* D data data to use in the calculation , not necessary
* if both source1 and source2 refer to actual parameters
*
* Operations
* 00 Set parameter equal to source1
* 01 Addition , source1 + source2
* 02 Subtraction , source1 - source2
* 03 Unsigned multiplication , source1 * source2 ( both unsigned )
* 04 Signed multiplication , source1 * source2 ( both signed )
* 05 Unsigned bit shift , source1 by source2 ( source2 taken to be a
* signed quantity ; left shift if positive and right shift if
* negative , source1 is unsigned )
* 06 Signed bit shift , source1 by source2
* ( source2 like in 05 , and source1 as well )
*/
2004-11-12 18:57:46 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 5 , " ParamSet " ) ) return ;
2004-11-14 22:31:57 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 target = grf_load_byte ( & buf ) ;
uint8 oper = grf_load_byte ( & buf ) ;
uint32 src1 = grf_load_byte ( & buf ) ;
uint32 src2 = grf_load_byte ( & buf ) ;
2004-11-12 18:57:46 +00:00
2007-03-10 09:55:11 +00:00
uint32 data = 0 ;
2005-08-15 21:19:28 +00:00
if ( len > = 8 ) data = grf_load_dword ( & buf ) ;
2004-11-14 13:59:11 +00:00
2004-11-12 18:57:46 +00:00
/* You can add 80 to the operation to make it apply only if the target
* is not defined yet . In this respect , a parameter is taken to be
* defined if any of the following applies :
* - it has been set to any value in the newgrf ( w ) . cfg parameter list
* - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by
* an earlier action D */
2007-11-19 21:02:30 +00:00
if ( HasBit ( oper , 7 ) ) {
2006-05-10 21:41:16 +00:00
if ( target < 0x80 & & target < _cur_grffile - > param_end ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " ParamSet: Param %u already defined, skipping " , target ) ;
2004-11-12 18:57:46 +00:00
return ;
2006-05-10 21:41:16 +00:00
}
2007-03-10 09:55:11 +00:00
oper = GB ( oper , 0 , 7 ) ;
2004-11-12 18:57:46 +00:00
}
2006-05-10 21:55:44 +00:00
if ( src2 = = 0xFE ) {
if ( GB ( data , 0 , 8 ) = = 0xFF ) {
if ( data = = 0x0000FFFF ) {
/* Patch variables */
2007-04-20 21:19:28 +00:00
src1 = GetPatchVariable ( src1 ) ;
2006-05-10 21:55:44 +00:00
} else {
/* GRF Resource Management */
2008-05-05 19:02:10 +00:00
uint8 op = src1 ;
uint8 feature = GB ( data , 8 , 8 ) ;
uint16 count = GB ( data , 16 , 16 ) ;
if ( _cur_stage = = GLS_RESERVE ) {
if ( feature = = 0x08 ) {
/* General sprites */
if ( op = = 0 ) {
/* Check if the allocated sprites will fit below the original sprite limit */
if ( _cur_spriteid + count > = 16384 ) {
grfmsg ( 0 , " ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order " , count ) ;
_cur_grfconfig - > status = GCS_DISABLED ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
2008-05-05 19:02:10 +00:00
_skip_sprites = - 1 ;
return ;
}
2006-10-27 13:15:21 +00:00
2008-05-05 19:02:10 +00:00
/* Reserve space at the current sprite ID */
grfmsg ( 4 , " ParamSet: GRM: Allocated %d sprites at %d " , count , _cur_spriteid ) ;
2008-05-06 17:24:27 +00:00
_grm_sprites [ GRFLocation ( _cur_grffile - > grfid , _nfo_line ) ] = _cur_spriteid ;
2008-05-05 19:02:10 +00:00
_cur_spriteid + = count ;
}
}
/* Ignore GRM result during reservation */
src1 = 0 ;
} else if ( _cur_stage = = GLS_ACTIVATION ) {
2006-10-27 13:15:21 +00:00
switch ( feature ) {
2007-03-21 03:06:21 +00:00
case 0x00 : // Trains
case 0x01 : // Road Vehicles
case 0x02 : // Ships
case 0x03 : // Aircraft
2008-05-29 15:13:28 +00:00
if ( ! _settings_game . vehicle . dynamic_engines ) {
2008-04-29 21:31:29 +00:00
src1 = PerformGRM ( & _grm_engines [ _engine_offsets [ feature ] ] , _engine_counts [ feature ] , count , op , target , " vehicles " ) ;
if ( _skip_sprites = = - 1 ) return ;
} else {
// GRM does not apply for dynamic engine allocation.
switch ( op ) {
case 2 :
case 3 :
src1 = _cur_grffile - > param [ target ] ;
break ;
default :
src1 = 0 ;
break ;
}
}
2006-10-27 13:15:21 +00:00
break ;
2007-03-21 03:06:21 +00:00
case 0x08 : // General sprites
2006-10-27 13:15:21 +00:00
switch ( op ) {
case 0 :
2008-05-05 19:02:10 +00:00
/* Return space reserved during reservation stage */
2008-05-06 17:24:27 +00:00
src1 = _grm_sprites [ GRFLocation ( _cur_grffile - > grfid , _nfo_line ) ] ;
2008-05-05 19:02:10 +00:00
grfmsg ( 4 , " ParamSet: GRM: Using pre-allocated sprites at %d " , src1 ) ;
2006-10-27 13:15:21 +00:00
break ;
case 1 :
src1 = _cur_spriteid ;
break ;
default :
2007-04-16 20:56:19 +00:00
grfmsg ( 1 , " ParamSet: GRM: Unsupported operation %d for general sprites " , op ) ;
2006-10-27 13:15:21 +00:00
return ;
}
break ;
2007-06-02 08:56:21 +00:00
case 0x0B : // Cargo
2007-10-07 08:48:31 +00:00
/* There are two ranges: one for cargo IDs and one for cargo bitmasks */
src1 = PerformGRM ( _grm_cargos , NUM_CARGO * 2 , count , op , target , " cargos " ) ;
2007-06-02 08:56:21 +00:00
if ( _skip_sprites = = - 1 ) return ;
break ;
2007-04-16 20:56:19 +00:00
default : grfmsg ( 1 , " ParamSet: GRM: Unsupported feature 0x%X " , feature ) ; return ;
2006-10-27 13:15:21 +00:00
}
2008-05-05 19:02:10 +00:00
} else {
/* Ignore GRM during initialization */
src1 = 0 ;
2006-10-27 13:15:21 +00:00
}
2006-05-10 21:55:44 +00:00
}
} else {
/* Read another GRF File's parameter */
const GRFFile * file = GetFileByGRFID ( data ) ;
2008-06-19 10:20:45 +00:00
GRFConfig * c = GetGRFConfig ( data ) ;
if ( c ! = NULL & & HasBit ( c - > status , GCF_STATIC ) & & ! HasBit ( _cur_grfconfig - > status , GCF_STATIC ) & & _networking ) {
/* Disable the read GRF if it is a static NewGRF. */
DisableStaticNewGRFInfluencingNonStaticNewGRFs ( c ) ;
src1 = 0 ;
} else if ( file = = NULL | | src1 > = file - > param_end | | ( c ! = NULL & & c - > status = = GCS_DISABLED ) ) {
2006-05-10 21:55:44 +00:00
src1 = 0 ;
} else {
src1 = file - > param [ src1 ] ;
}
}
2004-11-12 18:57:46 +00:00
} else {
2006-05-10 21:55:44 +00:00
/* The source1 and source2 operands refer to the grf parameter number
* like in action 6 and 7. In addition , they can refer to the special
* variables available in action 7 , or they can be FF to use the value
* of < data > . If referring to parameters that are undefined , a value
* of 0 is used instead . */
2006-05-11 09:54:11 +00:00
src1 = ( src1 = = 0xFF ) ? data : GetParamVal ( src1 , NULL ) ;
src2 = ( src2 = = 0xFF ) ? data : GetParamVal ( src2 , NULL ) ;
2004-11-12 18:57:46 +00:00
}
/* TODO: You can access the parameters of another GRF file by using
* source2 = FE , source1 = the other GRF ' s parameter number and data = GRF
* ID . This is only valid with operation 00 ( set ) . If the GRF ID
* cannot be found , a value of 0 is used for the parameter value
* instead . */
2007-03-10 09:55:11 +00:00
uint32 res ;
2004-11-12 18:57:46 +00:00
switch ( oper ) {
case 0x00 :
2005-08-15 21:19:28 +00:00
res = src1 ;
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2004-11-12 18:57:46 +00:00
case 0x01 :
2005-08-15 21:19:28 +00:00
res = src1 + src2 ;
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2004-11-12 18:57:46 +00:00
case 0x02 :
2005-08-15 21:19:28 +00:00
res = src1 - src2 ;
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2004-11-12 18:57:46 +00:00
case 0x03 :
2005-08-15 21:19:28 +00:00
res = src1 * src2 ;
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2004-11-12 18:57:46 +00:00
case 0x04 :
2005-08-15 21:19:28 +00:00
res = ( int32 ) src1 * ( int32 ) src2 ;
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2004-11-12 18:57:46 +00:00
case 0x05 :
2006-06-27 21:25:53 +00:00
if ( ( int32 ) src2 < 0 ) {
2005-08-15 21:19:28 +00:00
res = src1 > > - ( int32 ) src2 ;
2006-06-27 21:25:53 +00:00
} else {
2005-08-15 21:19:28 +00:00
res = src1 < < src2 ;
2006-06-27 21:25:53 +00:00
}
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2004-11-12 18:57:46 +00:00
case 0x06 :
2006-06-27 21:25:53 +00:00
if ( ( int32 ) src2 < 0 ) {
2005-08-15 21:19:28 +00:00
res = ( int32 ) src1 > > - ( int32 ) src2 ;
2006-06-27 21:25:53 +00:00
} else {
2005-08-15 21:19:28 +00:00
res = ( int32 ) src1 < < src2 ;
2006-06-27 21:25:53 +00:00
}
2004-11-12 18:57:46 +00:00
break ;
2005-08-15 21:19:28 +00:00
2007-03-21 03:06:21 +00:00
case 0x07 : // Bitwise AND
2005-09-21 19:07:58 +00:00
res = src1 & src2 ;
break ;
2007-03-21 03:06:21 +00:00
case 0x08 : // Bitwise OR
2005-09-21 19:07:58 +00:00
res = src1 | src2 ;
break ;
2007-03-21 03:06:21 +00:00
case 0x09 : // Unsigned division
2005-09-21 19:07:58 +00:00
if ( src2 = = 0 ) {
res = src1 ;
} else {
res = src1 / src2 ;
}
break ;
2007-03-21 03:06:21 +00:00
case 0x0A : // Signed divison
2005-09-21 19:07:58 +00:00
if ( src2 = = 0 ) {
res = src1 ;
} else {
res = ( int32 ) src1 / ( int32 ) src2 ;
}
break ;
2007-03-21 03:06:21 +00:00
case 0x0B : // Unsigned modulo
2005-09-21 19:07:58 +00:00
if ( src2 = = 0 ) {
res = src1 ;
} else {
res = src1 % src2 ;
}
break ;
2007-03-21 03:06:21 +00:00
case 0x0C : // Signed modulo
2005-09-21 19:07:58 +00:00
if ( src2 = = 0 ) {
res = src1 ;
} else {
res = ( int32 ) src1 % ( int32 ) src2 ;
}
break ;
2006-12-26 17:36:18 +00:00
default : grfmsg ( 0 , " ParamSet: Unknown operation %d, skipping " , oper ) ; return ;
2005-08-15 21:19:28 +00:00
}
switch ( target ) {
case 0x8E : // Y-Offset for train sprites
_traininfo_vehicle_pitch = res ;
break ;
2008-08-24 23:10:23 +00:00
case 0x8F : { // Rail track type cost factors
extern RailtypeInfo _railtypes [ RAILTYPE_END ] ;
_railtypes [ RAILTYPE_RAIL ] . cost_multiplier = GB ( res , 0 , 8 ) ;
2008-05-29 15:13:28 +00:00
if ( _settings_game . vehicle . disable_elrails ) {
2008-08-24 23:10:23 +00:00
_railtypes [ RAILTYPE_ELECTRIC ] . cost_multiplier = GB ( res , 0 , 8 ) ;
_railtypes [ RAILTYPE_MONO ] . cost_multiplier = GB ( res , 8 , 8 ) ;
2007-10-14 21:20:12 +00:00
} else {
2008-08-24 23:10:23 +00:00
_railtypes [ RAILTYPE_ELECTRIC ] . cost_multiplier = GB ( res , 8 , 8 ) ;
_railtypes [ RAILTYPE_MONO ] . cost_multiplier = GB ( res , 16 , 8 ) ;
2007-10-14 21:20:12 +00:00
}
2008-08-24 23:10:23 +00:00
_railtypes [ RAILTYPE_MAGLEV ] . cost_multiplier = GB ( res , 16 , 8 ) ;
2007-10-14 21:20:12 +00:00
break ;
2008-08-24 23:10:23 +00:00
}
2007-10-14 21:20:12 +00:00
/* @todo implement */
2005-08-15 21:19:28 +00:00
case 0x93 : // Tile refresh offset to left
case 0x94 : // Tile refresh offset to right
case 0x95 : // Tile refresh offset upwards
case 0x96 : // Tile refresh offset downwards
case 0x97 : // Snow line height
case 0x99 : // Global ID offset
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " ParamSet: Skipping unimplemented target 0x%02X " , target ) ;
2005-08-15 21:19:28 +00:00
break ;
2007-03-21 03:06:21 +00:00
case 0x9E : // Miscellaneous GRF features
2006-05-11 12:41:02 +00:00
_misc_grf_features = res ;
2006-05-14 20:58:12 +00:00
/* Set train list engine width */
2007-04-27 21:35:02 +00:00
_traininfo_vehicle_width = HasGrfMiscBit ( GMB_TRAIN_WIDTH_32_PIXELS ) ? 32 : 29 ;
2006-05-11 12:41:02 +00:00
break ;
2008-02-12 15:43:10 +00:00
case 0x9F : // locale-dependent settings
grfmsg ( 7 , " ParamSet: Skipping unimplemented target 0x%02X " , target ) ;
break ;
2005-08-15 21:19:28 +00:00
default :
if ( target < 0x80 ) {
_cur_grffile - > param [ target ] = res ;
if ( target + 1U > _cur_grffile - > param_end ) _cur_grffile - > param_end = target + 1 ;
} else {
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " ParamSet: Skipping unknown target 0x%02X " , target ) ;
2005-08-15 21:19:28 +00:00
}
break ;
2004-11-12 18:57:46 +00:00
}
2004-08-09 17:04:08 +00:00
}
2007-01-03 11:33:54 +00:00
/* Action 0x0E (GLS_SAFETYSCAN) */
2008-05-08 13:20:54 +00:00
static void SafeGRFInhibit ( byte * buf , size_t len )
2007-01-03 11:33:54 +00:00
{
/* <0E> <num> <grfids...>
*
* B num Number of GRFIDs that follow
* D grfids GRFIDs of the files to deactivate */
2007-03-10 09:55:11 +00:00
if ( ! check_length ( len , 2 , " GRFInhibit " ) ) return ;
buf + + ;
uint8 num = grf_load_byte ( & buf ) ;
if ( ! check_length ( len , 2 + 4 * num , " GRFInhibit " ) ) return ;
2007-01-03 11:33:54 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < num ; i + + ) {
2007-01-03 11:33:54 +00:00
uint32 grfid = grf_load_dword ( & buf ) ;
/* GRF is unsafe it if tries to deactivate other GRFs */
if ( grfid ! = _cur_grfconfig - > grfid ) {
2007-11-20 13:35:54 +00:00
SetBit ( _cur_grfconfig - > flags , GCF_UNSAFE ) ;
2007-01-03 11:33:54 +00:00
/* Skip remainder of GRF */
_skip_sprites = - 1 ;
return ;
}
}
}
2006-05-02 09:31:59 +00:00
/* Action 0x0E */
2008-05-08 13:20:54 +00:00
static void GRFInhibit ( byte * buf , size_t len )
2004-08-09 17:04:08 +00:00
{
/* <0E> <num> <grfids...>
*
* B num Number of GRFIDs that follow
* D grfids GRFIDs of the files to deactivate */
2004-11-12 22:39:00 +00:00
2007-03-10 09:55:11 +00:00
if ( ! check_length ( len , 2 , " GRFInhibit " ) ) return ;
buf + + ;
uint8 num = grf_load_byte ( & buf ) ;
if ( ! check_length ( len , 2 + 4 * num , " GRFInhibit " ) ) return ;
2004-11-12 22:39:00 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < num ; i + + ) {
2004-11-12 22:39:00 +00:00
uint32 grfid = grf_load_dword ( & buf ) ;
2006-12-14 15:14:29 +00:00
GRFConfig * file = GetGRFConfig ( grfid ) ;
2004-11-12 22:39:00 +00:00
/* Unset activation flag */
2006-12-24 19:20:28 +00:00
if ( file ! = NULL & & file ! = _cur_grfconfig ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " GRFInhibit: Deactivating file '%s' " , file - > filename ) ;
2007-03-06 19:33:28 +00:00
file - > status = GCS_DISABLED ;
2004-11-12 22:39:00 +00:00
}
}
2004-08-09 17:04:08 +00:00
}
2007-06-18 23:00:55 +00:00
/* Action 0x0F */
2008-05-08 13:20:54 +00:00
static void FeatureTownName ( byte * buf , size_t len )
2007-06-18 23:00:55 +00:00
{
/* <0F> <id> <style-name> <num-parts> <parts>
*
* B id ID of this definition in bottom 7 bits ( final definition if bit 7 set )
* V style - name Name of the style ( only for final definition )
* B num - parts Number of parts in this definition
* V parts The parts */
if ( ! check_length ( len , 1 , " FeatureTownName: definition ID " ) ) return ;
buf + + ; len - - ;
uint32 grfid = _cur_grffile - > grfid ;
GRFTownName * townname = AddGRFTownName ( grfid ) ;
byte id = grf_load_byte ( & buf ) ;
len - - ;
grfmsg ( 6 , " FeatureTownName: definition 0x%02X " , id & 0x7F ) ;
2007-11-19 21:02:30 +00:00
if ( HasBit ( id , 7 ) ) {
2007-06-18 23:00:55 +00:00
/* Final definition */
2007-11-19 21:32:20 +00:00
ClrBit ( id , 7 ) ;
2007-06-18 23:00:55 +00:00
bool new_scheme = _cur_grffile - > grf_version > = 7 ;
if ( ! check_length ( len , 1 , " FeatureTownName: lang_id " ) ) return ;
byte lang = grf_load_byte ( & buf ) ;
len - - ;
byte nb_gen = townname - > nb_gen ;
do {
2007-11-19 21:32:20 +00:00
ClrBit ( lang , 7 ) ;
2007-06-18 23:00:55 +00:00
if ( ! check_length ( len , 1 , " FeatureTownName: style name " ) ) return ;
const char * name = grf_load_string ( & buf , len ) ;
len - = strlen ( name ) + 1 ;
2008-02-29 08:48:01 +00:00
grfmsg ( 6 , " FeatureTownName: lang 0x%X -> '%s' " , lang , TranslateTTDPatchCodes ( grfid , name ) ) ;
2007-06-18 23:00:55 +00:00
townname - > name [ nb_gen ] = AddGRFString ( grfid , id , lang , new_scheme , name , STR_UNDEFINED ) ;
if ( ! check_length ( len , 1 , " FeatureTownName: lang_id " ) ) return ;
lang = grf_load_byte ( & buf ) ;
len - - ;
} while ( lang ! = 0 ) ;
townname - > id [ nb_gen ] = id ;
townname - > nb_gen + + ;
}
if ( ! check_length ( len , 1 , " FeatureTownName: number of parts " ) ) return ;
byte nb = grf_load_byte ( & buf ) ;
len - - ;
grfmsg ( 6 , " FeatureTownName: %d parts " , nb , nb ) ;
townname - > nbparts [ id ] = nb ;
townname - > partlist [ id ] = CallocT < NamePartList > ( nb ) ;
for ( int i = 0 ; i < nb ; i + + ) {
if ( ! check_length ( len , 3 , " FeatureTownName: parts header " ) ) return ;
byte nbtext = grf_load_byte ( & buf ) ;
townname - > partlist [ id ] [ i ] . bitstart = grf_load_byte ( & buf ) ;
townname - > partlist [ id ] [ i ] . bitcount = grf_load_byte ( & buf ) ;
townname - > partlist [ id ] [ i ] . maxprob = 0 ;
townname - > partlist [ id ] [ i ] . partcount = nbtext ;
townname - > partlist [ id ] [ i ] . parts = CallocT < NamePart > ( nbtext ) ;
len - = 3 ;
grfmsg ( 6 , " FeatureTownName: part %d contains %d texts and will use GB(seed, %d, %d) " , i , nbtext , townname - > partlist [ id ] [ i ] . bitstart , townname - > partlist [ id ] [ i ] . bitcount ) ;
for ( int j = 0 ; j < nbtext ; j + + ) {
if ( ! check_length ( len , 2 , " FeatureTownName: part " ) ) return ;
byte prob = grf_load_byte ( & buf ) ;
len - - ;
2007-11-19 21:02:30 +00:00
if ( HasBit ( prob , 7 ) ) {
2007-06-18 23:00:55 +00:00
byte ref_id = grf_load_byte ( & buf ) ;
len - - ;
if ( townname - > nbparts [ ref_id ] = = 0 ) {
grfmsg ( 0 , " FeatureTownName: definition 0x%02X doesn't exist, deactivating " , ref_id ) ;
DelGRFTownName ( grfid ) ;
_cur_grfconfig - > status = GCS_DISABLED ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
2007-06-18 23:00:55 +00:00
_skip_sprites = - 1 ;
return ;
}
grfmsg ( 6 , " FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d) " , i , j , ref_id , prob & 0x7F ) ;
townname - > partlist [ id ] [ i ] . parts [ j ] . data . id = ref_id ;
} else {
const char * text = grf_load_string ( & buf , len ) ;
len - = strlen ( text ) + 1 ;
2008-02-29 08:48:01 +00:00
townname - > partlist [ id ] [ i ] . parts [ j ] . data . text = TranslateTTDPatchCodes ( grfid , text ) ;
2007-06-18 23:00:55 +00:00
grfmsg ( 6 , " FeatureTownName: part %d, text %d, '%s' (with probability %d) " , i , j , townname - > partlist [ id ] [ i ] . parts [ j ] . data . text , prob ) ;
}
townname - > partlist [ id ] [ i ] . parts [ j ] . prob = prob ;
townname - > partlist [ id ] [ i ] . maxprob + = GB ( prob , 0 , 7 ) ;
}
grfmsg ( 6 , " FeatureTownName: part %d, total probability %d " , i , townname - > partlist [ id ] [ i ] . maxprob ) ;
}
}
2006-05-02 09:31:59 +00:00
/* Action 0x10 */
2008-05-08 13:20:54 +00:00
static void DefineGotoLabel ( byte * buf , size_t len )
2006-04-15 21:27:59 +00:00
{
/* <10> <label> [<comment>]
*
* B label The label to define
* V comment Optional comment - ignored */
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 1 , " DefineGotoLabel " ) ) return ;
2006-04-15 21:27:59 +00:00
buf + + ; len - - ;
2007-03-10 09:55:11 +00:00
GRFLabel * label = MallocT < GRFLabel > ( 1 ) ;
2006-04-15 21:27:59 +00:00
label - > label = grf_load_byte ( & buf ) ;
label - > nfo_line = _nfo_line ;
label - > pos = FioGetPos ( ) ;
label - > next = NULL ;
/* Set up a linked list of goto targets which we will search in an Action 0x7/0x9 */
if ( _cur_grffile - > label = = NULL ) {
_cur_grffile - > label = label ;
} else {
/* Attach the label to the end of the list */
GRFLabel * l ;
2008-03-15 13:21:31 +00:00
for ( l = _cur_grffile - > label ; l - > next ! = NULL ; l = l - > next ) { }
2006-04-15 21:27:59 +00:00
l - > next = label ;
}
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " DefineGotoLabel: GOTO target with label 0x%02X " , label - > label ) ;
2006-04-15 21:27:59 +00:00
}
2004-11-12 19:03:37 +00:00
2006-09-27 18:17:01 +00:00
/* Action 0x11 */
2008-05-08 13:20:54 +00:00
static void GRFSound ( byte * buf , size_t len )
2006-09-27 18:17:01 +00:00
{
/* <11> <num>
*
* W num Number of sound files that follow */
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 1 , " GRFSound " ) ) return ;
2006-09-27 18:17:01 +00:00
buf + + ;
2007-03-10 09:55:11 +00:00
uint16 num = grf_load_word ( & buf ) ;
2006-09-27 18:17:01 +00:00
_grf_data_blocks = num ;
_grf_data_type = GDT_SOUND ;
if ( _cur_grffile - > sound_offset = = 0 ) _cur_grffile - > sound_offset = GetNumSounds ( ) ;
}
2008-01-28 15:55:59 +00:00
/* Action 0x11 (SKIP) */
2008-05-08 13:20:54 +00:00
static void SkipAct11 ( byte * buf , size_t len )
2008-01-28 15:55:59 +00:00
{
/* <11> <num>
*
* W num Number of sound files that follow */
if ( ! check_length ( len , 1 , " SkipAct11 " ) ) return ;
buf + + ;
_skip_sprites = grf_load_word ( & buf ) ;
grfmsg ( 3 , " SkipAct11: Skipping %d sprites " , _skip_sprites ) ;
}
2006-10-12 07:42:37 +00:00
static void ImportGRFSound ( byte * buf , int len )
{
const GRFFile * file ;
FileEntry * se = AllocateFileEntry ( ) ;
uint32 grfid = grf_load_dword ( & buf ) ;
uint16 sound = grf_load_word ( & buf ) ;
file = GetFileByGRFID ( grfid ) ;
if ( file = = NULL | | file - > sound_offset = = 0 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " ImportGRFSound: Source file not available " ) ;
2006-10-12 07:42:37 +00:00
return ;
}
if ( file - > sound_offset + sound > = GetNumSounds ( ) ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " ImportGRFSound: Sound effect %d is invalid " , sound ) ;
2006-10-12 07:42:37 +00:00
return ;
}
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " ImportGRFSound: Copying sound %d (%d) from file %X " , sound , file - > sound_offset + sound , grfid ) ;
2006-10-12 07:42:37 +00:00
2006-11-05 08:24:52 +00:00
* se = * GetSound ( file - > sound_offset + sound ) ;
2006-10-12 07:42:37 +00:00
/* Reset volume and priority, which TTDPatch doesn't copy */
se - > volume = 128 ;
se - > priority = 0 ;
}
/* 'Action 0xFE' */
static void GRFImportBlock ( byte * buf , int len )
{
if ( _grf_data_blocks = = 0 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " GRFImportBlock: Unexpected import block, skipping " ) ;
2006-10-12 07:42:37 +00:00
return ;
}
buf + + ;
_grf_data_blocks - - ;
/* XXX 'Action 0xFE' isn't really specified. It is only mentioned for
* importing sounds , so this is probably all wrong . . . */
if ( grf_load_byte ( & buf ) ! = _grf_data_type ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " GRFImportBlock: Import type mismatch " ) ;
2006-10-12 07:42:37 +00:00
}
switch ( _grf_data_type ) {
case GDT_SOUND : ImportGRFSound ( buf , len - 1 ) ; break ;
default : NOT_REACHED ( ) ; break ;
}
}
2006-09-27 18:17:01 +00:00
static void LoadGRFSound ( byte * buf , int len )
{
byte * buf_start = buf ;
/* Allocate a sound entry. This is done even if the data is not loaded
* so that the indices used elsewhere are still correct . */
2007-03-10 09:55:11 +00:00
FileEntry * se = AllocateFileEntry ( ) ;
2006-09-27 18:17:01 +00:00
2006-12-26 17:22:47 +00:00
if ( grf_load_dword ( & buf ) ! = BSWAP32 ( ' RIFF ' ) ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " LoadGRFSound: Missing RIFF header " ) ;
2006-09-27 18:17:01 +00:00
return ;
}
/* Size of file -- we ignore this */
grf_load_dword ( & buf ) ;
2006-12-26 17:22:47 +00:00
if ( grf_load_dword ( & buf ) ! = BSWAP32 ( ' WAVE ' ) ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " LoadGRFSound: Invalid RIFF type " ) ;
2006-09-27 18:17:01 +00:00
return ;
}
for ( ; ; ) {
uint32 tag = grf_load_dword ( & buf ) ;
uint32 size = grf_load_dword ( & buf ) ;
switch ( tag ) {
2007-03-21 03:06:21 +00:00
case ' tmf ' : // 'fmt '
2006-09-27 18:17:01 +00:00
/* Audio format, must be 1 (PCM) */
if ( grf_load_word ( & buf ) ! = 1 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 1 , " LoadGRFSound: Invalid audio format " ) ;
2006-09-27 18:17:01 +00:00
return ;
}
se - > channels = grf_load_word ( & buf ) ;
se - > rate = grf_load_dword ( & buf ) ;
grf_load_dword ( & buf ) ;
grf_load_word ( & buf ) ;
se - > bits_per_sample = grf_load_word ( & buf ) ;
/* Consume any extra bytes */
for ( ; size > 16 ; size - - ) grf_load_byte ( & buf ) ;
break ;
2007-03-21 03:06:21 +00:00
case ' atad ' : // 'data'
2007-09-13 18:22:34 +00:00
se - > file_size = size ;
se - > file_offset = FioGetPos ( ) - ( len - ( buf - buf_start ) ) + 1 ;
se - > file_slot = _file_index ;
2006-09-27 18:17:01 +00:00
/* Set default volume and priority */
se - > volume = 0x80 ;
se - > priority = 0 ;
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " LoadGRFSound: channels %u, sample rate %u, bits per sample %u, length %u " , se - > channels , se - > rate , se - > bits_per_sample , size ) ;
2006-09-27 18:17:01 +00:00
return ;
default :
se - > file_size = 0 ;
return ;
}
}
}
2006-11-16 22:05:33 +00:00
/* Action 0x12 */
2008-05-08 13:20:54 +00:00
static void LoadFontGlyph ( byte * buf , size_t len )
2006-11-16 22:05:33 +00:00
{
/* <12> <num_def> <font_size> <num_char> <base_char>
*
* B num_def Number of definitions
* B font_size Size of font ( 0 = normal , 1 = small , 2 = large )
* B num_char Number of consecutive glyphs
* W base_char First character index */
buf + + ; len - - ;
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 1 , " LoadFontGlyph " ) ) return ;
2006-11-16 22:05:33 +00:00
2007-03-10 09:55:11 +00:00
uint8 num_def = grf_load_byte ( & buf ) ;
2006-11-16 22:05:33 +00:00
2007-01-10 19:20:25 +00:00
if ( ! check_length ( len , 1 + num_def * 4 , " LoadFontGlyph " ) ) return ;
2006-11-16 22:05:33 +00:00
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < num_def ; i + + ) {
2007-01-10 18:56:51 +00:00
FontSize size = ( FontSize ) grf_load_byte ( & buf ) ;
2006-11-16 22:05:33 +00:00
uint8 num_char = grf_load_byte ( & buf ) ;
uint16 base_char = grf_load_word ( & buf ) ;
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u " , num_char , base_char , size ) ;
2006-11-16 22:05:33 +00:00
2007-03-10 09:55:11 +00:00
for ( uint c = 0 ; c < num_char ; c + + ) {
2006-11-16 22:05:33 +00:00
SetUnicodeGlyph ( size , base_char + c , _cur_spriteid ) ;
_nfo_line + + ;
2007-11-24 10:19:56 +00:00
LoadNextSprite ( _cur_spriteid + + , _file_index , _nfo_line ) ;
2006-11-16 22:05:33 +00:00
}
}
}
2008-01-28 15:55:59 +00:00
/* Action 0x12 (SKIP) */
2008-05-08 13:20:54 +00:00
static void SkipAct12 ( byte * buf , size_t len )
2008-01-28 15:55:59 +00:00
{
/* <12> <num_def> <font_size> <num_char> <base_char>
*
* B num_def Number of definitions
* B font_size Size of font ( 0 = normal , 1 = small , 2 = large )
* B num_char Number of consecutive glyphs
* W base_char First character index */
buf + + ; len - - ;
if ( ! check_length ( len , 1 , " SkipAct12 " ) ) return ;
uint8 num_def = grf_load_byte ( & buf ) ;
if ( ! check_length ( len , 1 + num_def * 4 , " SkipAct12 " ) ) return ;
for ( uint i = 0 ; i < num_def ; i + + ) {
/* Ignore 'size' byte */
grf_load_byte ( & buf ) ;
/* Sum up number of characters */
_skip_sprites + = grf_load_byte ( & buf ) ;
/* Ignore 'base_char' word */
grf_load_word ( & buf ) ;
}
grfmsg ( 3 , " SkipAct12: Skipping %d sprites " , _skip_sprites ) ;
}
2007-03-06 22:00:13 +00:00
/* Action 0x13 */
2008-05-08 13:20:54 +00:00
static void TranslateGRFStrings ( byte * buf , size_t len )
2007-03-06 22:00:13 +00:00
{
/* <13> <grfid> <num-ent> <offset> <text...>
*
* 4 * B grfid The GRFID of the file whose texts are to be translated
* B num - ent Number of strings
* W offset First text ID
* S text . . . Zero - terminated strings */
buf + + ; len - - ;
if ( ! check_length ( len , 7 , " TranslateGRFString " ) ) return ;
uint32 grfid = grf_load_dword ( & buf ) ;
const GRFConfig * c = GetGRFConfig ( grfid ) ;
if ( c = = NULL | | ( c - > status ! = GCS_INITIALISED & & c - > status ! = GCS_ACTIVATED ) ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13 " , BSWAP32 ( grfid ) ) ;
2007-03-06 22:00:13 +00:00
return ;
}
if ( c - > status = = GCS_INITIALISED ) {
/* If the file is not active but will be activated later, give an error
* and disable this file . */
GRFError * error = CallocT < GRFError > ( 1 ) ;
2007-06-12 13:22:14 +00:00
char tmp [ 256 ] ;
GetString ( tmp , STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE , lastof ( tmp ) ) ;
error - > data = strdup ( tmp ) ;
2007-03-06 22:00:13 +00:00
error - > message = STR_NEWGRF_ERROR_LOAD_AFTER ;
error - > severity = STR_NEWGRF_ERROR_MSG_FATAL ;
if ( _cur_grfconfig - > error ! = NULL ) free ( _cur_grfconfig - > error ) ;
_cur_grfconfig - > error = error ;
_cur_grfconfig - > status = GCS_DISABLED ;
2008-07-04 18:42:04 +00:00
ClearTemporaryNewGRFData ( ) ;
2007-03-06 22:00:13 +00:00
_skip_sprites = - 1 ;
return ;
}
byte num_strings = grf_load_byte ( & buf ) ;
uint16 first_id = grf_load_word ( & buf ) ;
if ( ! ( ( first_id > = 0xD000 & & first_id + num_strings < = 0xD3FF ) | | ( first_id > = 0xDC00 & & first_id + num_strings < = 0xDCFF ) ) ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X) " , first_id , num_strings ) ;
2007-03-06 22:00:13 +00:00
return ;
}
len - = 7 ;
for ( uint i = 0 ; i < num_strings & & len > 0 ; i + + ) {
const char * string = grf_load_string ( & buf , len ) ;
size_t string_length = strlen ( string ) + 1 ;
len - = ( int ) string_length ;
if ( string_length = = 1 ) {
grfmsg ( 7 , " TranslateGRFString: Ignoring empty string. " ) ;
continue ;
}
/* Since no language id is supplied this string has to be added as a
* generic string , thus the language id of 0x7F . For this to work
* new_scheme has to be true as well . A language id of 0x7F will be
* overridden by a non - generic id , so this will not change anything if
* a string has been provided specifically for this language . */
AddGRFString ( grfid , first_id + i , 0x7F , true , string , STR_UNDEFINED ) ;
}
}
2006-09-27 18:17:01 +00:00
/* 'Action 0xFF' */
static void GRFDataBlock ( byte * buf , int len )
{
if ( _grf_data_blocks = = 0 ) {
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " GRFDataBlock: unexpected data block, skipping " ) ;
2006-09-27 18:17:01 +00:00
return ;
}
buf + + ;
2007-03-10 09:55:11 +00:00
uint8 name_len = grf_load_byte ( & buf ) ;
const char * name = ( const char * ) buf ;
2006-09-27 18:17:01 +00:00
buf + = name_len + 1 ;
2006-12-26 17:36:18 +00:00
grfmsg ( 2 , " GRFDataBlock: block name '%s'... " , name ) ;
2006-09-27 18:17:01 +00:00
_grf_data_blocks - - ;
switch ( _grf_data_type ) {
case GDT_SOUND : LoadGRFSound ( buf , len - name_len - 2 ) ; break ;
default : NOT_REACHED ( ) ; break ;
}
}
2006-12-12 19:38:41 +00:00
/* Used during safety scan on unsafe actions */
2008-05-08 13:20:54 +00:00
static void GRFUnsafe ( byte * buf , size_t len )
2006-12-12 19:38:41 +00:00
{
2007-11-20 13:35:54 +00:00
SetBit ( _cur_grfconfig - > flags , GCF_UNSAFE ) ;
2006-12-12 19:38:41 +00:00
2007-01-03 11:33:54 +00:00
/* Skip remainder of GRF */
_skip_sprites = - 1 ;
2006-12-12 19:38:41 +00:00
}
2007-03-07 11:47:46 +00:00
static void InitializeGRFSpecial ( )
2004-11-12 19:03:37 +00:00
{
2008-05-29 15:13:28 +00:00
_ttdpatch_flags [ 0 ] = ( ( _settings_game . station . always_small_airport ? 1 : 0 ) < < 0x0C ) // keepsmallairport
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x0D ) // newairports
| ( 1 < < 0x0E ) // largestations
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . construction . longbridges ? 1 : 0 ) < < 0x0F ) // longbridges
2008-05-25 19:17:03 +00:00
| ( 0 < < 0x10 ) // loadtime
| ( 1 < < 0x12 ) // presignals
| ( 1 < < 0x13 ) // extpresignals
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . vehicle . never_expire_vehicles ? 1 : 0 ) < < 0x16 ) // enginespersist
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x1B ) // multihead
| ( 1 < < 0x1D ) // lowmemory
| ( 1 < < 0x1E ) ; // generalfixes
2008-05-29 15:13:28 +00:00
_ttdpatch_flags [ 1 ] = ( ( _settings_game . economy . station_noise_level ? 1 : 0 ) < < 0x07 ) // moreairports - based on units of noise
| ( ( _settings_game . vehicle . mammoth_trains ? 1 : 0 ) < < 0x08 ) // mammothtrains
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x09 ) // trainrefit
| ( 0 < < 0x0B ) // subsidiaries
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . order . gradual_loading ? 1 : 0 ) < < 0x0C ) // gradualloading
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x12 ) // unifiedmaglevmode - set bit 0 mode. Not revelant to OTTD
| ( 1 < < 0x13 ) // unifiedmaglevmode - set bit 1 mode
| ( 1 < < 0x14 ) // bridgespeedlimits
| ( 1 < < 0x16 ) // eternalgame
| ( 1 < < 0x17 ) // newtrains
| ( 1 < < 0x18 ) // newrvs
| ( 1 < < 0x19 ) // newships
| ( 1 < < 0x1A ) // newplanes
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . construction . signal_side ? 1 : 0 ) < < 0x1B ) // signalsontrafficside
| ( ( _settings_game . vehicle . disable_elrails ? 0 : 1 ) < < 0x1C ) ; // electrifiedrailway
2008-05-25 19:17:03 +00:00
_ttdpatch_flags [ 2 ] = ( 1 < < 0x01 ) // loadallgraphics - obsolote
| ( 1 < < 0x03 ) // semaphores
| ( 0 < < 0x0B ) // enhancedgui
| ( 0 < < 0x0C ) // newagerating
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . construction . build_on_slopes ? 1 : 0 ) < < 0x0D ) // buildonslopes
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x0E ) // fullloadany
| ( 1 < < 0x0F ) // planespeed
| ( 0 < < 0x10 ) // moreindustriesperclimate - obsolete
| ( 0 < < 0x11 ) // moretoylandfeatures
| ( 1 < < 0x12 ) // newstations
| ( 1 < < 0x13 ) // tracktypecostdiff
| ( 1 < < 0x14 ) // manualconvert
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . construction . build_on_slopes ? 1 : 0 ) < < 0x15 ) // buildoncoasts
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x16 ) // canals
| ( 1 < < 0x17 ) // newstartyear
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . vehicle . freight_trains > 1 ? 1 : 0 ) < < 0x18 ) // freighttrains
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x19 ) // newhouses
| ( 1 < < 0x1A ) // newbridges
| ( 1 < < 0x1B ) // newtownnames
| ( 1 < < 0x1C ) // moreanimation
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . vehicle . wagon_speed_limits ? 1 : 0 ) < < 0x1D ) // wagonspeedlimits
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x1E ) // newshistory
| ( 0 < < 0x1F ) ; // custombridgeheads
_ttdpatch_flags [ 3 ] = ( 0 < < 0x00 ) // newcargodistribution
| ( 1 < < 0x01 ) // windowsnap
| ( 0 < < 0x02 ) // townbuildnoroad
| ( 0 < < 0x03 ) // pathbasedsignalling. To enable if ever pbs is back
| ( 0 < < 0x04 ) // aichoosechance
| ( 1 < < 0x05 ) // resolutionwidth
| ( 1 < < 0x06 ) // resolutionheight
| ( 1 < < 0x07 ) // newindustries
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . order . improved_load ? 1 : 0 ) < < 0x08 ) // fifoloading
2008-05-25 19:17:03 +00:00
| ( 0 < < 0x09 ) // townroadbranchprob
| ( 0 < < 0x0A ) // tempsnowline
| ( 1 < < 0x0B ) // newcargo
| ( 1 < < 0x0C ) // enhancemultiplayer
| ( 1 < < 0x0D ) // onewayroads
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . station . nonuniform_stations ? 1 : 0 ) < < 0x0E ) // irregularstations
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x0F ) // statistics
| ( 1 < < 0x10 ) // newsounds
| ( 1 < < 0x11 ) // autoreplace
| ( 1 < < 0x12 ) // autoslope
| ( 0 < < 0x13 ) // followvehicle
| ( 1 < < 0x14 ) // trams
| ( 0 < < 0x15 ) // enhancetunnels
| ( 1 < < 0x16 ) // shortrvs
| ( 1 < < 0x17 ) // articulatedrvs
2008-05-29 15:13:28 +00:00
| ( ( _settings_game . vehicle . dynamic_engines ? 1 : 0 ) < < 0x18 ) // dynamic engines
2008-05-25 19:17:03 +00:00
| ( 1 < < 0x1E ) ; // variablerunningcosts
2004-11-12 19:03:37 +00:00
}
2007-03-07 11:47:46 +00:00
static void ResetCustomStations ( )
2005-11-12 00:19:34 +00:00
{
2007-03-10 09:55:11 +00:00
for ( GRFFile * file = _first_grffile ; file ! = NULL ; file = file - > next ) {
2006-05-06 22:20:16 +00:00
if ( file - > stations = = NULL ) continue ;
2007-03-10 09:55:11 +00:00
for ( uint i = 0 ; i < MAX_STATIONS ; i + + ) {
2006-05-06 22:20:16 +00:00
if ( file - > stations [ i ] = = NULL ) continue ;
2007-03-10 09:55:11 +00:00
StationSpec * statspec = file - > stations [ i ] ;
2006-05-03 21:07:44 +00:00
/* Release renderdata, if it wasn't copied from another custom station spec */
if ( ! statspec - > copied_renderdata ) {
2007-03-10 09:55:11 +00:00
for ( uint t = 0 ; t < statspec - > tiles ; t + + ) {
2006-05-03 21:07:44 +00:00
free ( ( void * ) statspec - > renderdata [ t ] . seq ) ;
}
free ( statspec - > renderdata ) ;
}
2005-11-12 00:19:34 +00:00
2006-11-08 12:28:57 +00:00
/* Release platforms and layouts */
if ( ! statspec - > copied_layouts ) {
2007-03-10 09:55:11 +00:00
for ( uint l = 0 ; l < statspec - > lengths ; l + + ) {
for ( uint p = 0 ; p < statspec - > platforms [ l ] ; p + + ) {
2006-11-08 12:28:57 +00:00
free ( statspec - > layouts [ l ] [ p ] ) ;
}
free ( statspec - > layouts [ l ] ) ;
}
free ( statspec - > layouts ) ;
free ( statspec - > platforms ) ;
}
2006-05-06 22:20:16 +00:00
/* Release this station */
free ( statspec ) ;
2005-11-12 00:19:34 +00:00
}
2006-04-11 10:05:52 +00:00
/* Free and reset the station data */
free ( file - > stations ) ;
file - > stations = NULL ;
2005-11-12 00:19:34 +00:00
}
}
2007-03-19 11:27:30 +00:00
static void ResetCustomHouses ( )
{
GRFFile * file ;
uint i ;
for ( file = _first_grffile ; file ! = NULL ; file = file - > next ) {
if ( file - > housespec = = NULL ) continue ;
2007-06-10 23:40:29 +00:00
for ( i = 0 ; i < HOUSE_MAX ; i + + ) {
free ( file - > housespec [ i ] ) ;
}
2007-03-19 11:27:30 +00:00
free ( file - > housespec ) ;
file - > housespec = NULL ;
}
}
2007-05-31 03:35:11 +00:00
static void ResetCustomIndustries ( )
{
GRFFile * file ;
for ( file = _first_grffile ; file ! = NULL ; file = file - > next ) {
uint i ;
/* We are verifiying both tiles and industries specs loaded from the grf file
* First , let ' s deal with industryspec */
if ( file - > industryspec ! = NULL ) {
for ( i = 0 ; i < NUM_INDUSTRYTYPES ; i + + ) {
IndustrySpec * ind = file - > industryspec [ i ] ;
if ( ind ! = NULL ) {
2007-05-31 15:40:36 +00:00
/* We need to remove the sounds array */
2007-11-19 21:02:30 +00:00
if ( HasBit ( ind - > cleanup_flag , CLEAN_RANDOMSOUNDS ) ) {
2007-05-31 15:40:36 +00:00
free ( ( void * ) ind - > random_sounds ) ;
}
/* We need to remove the tiles layouts */
2007-11-19 21:02:30 +00:00
if ( HasBit ( ind - > cleanup_flag , CLEAN_TILELSAYOUT ) & & ind - > table ! = NULL ) {
2007-05-31 15:40:36 +00:00
for ( int j = 0 ; j < ind - > num_table ; j + + ) {
/* remove the individual layouts */
if ( ind - > table [ j ] ! = NULL ) {
free ( ( IndustryTileTable * ) ind - > table [ j ] ) ;
}
}
/* remove the layouts pointers */
free ( ( IndustryTileTable * * ) ind - > table ) ;
ind - > table = NULL ;
}
2007-05-31 03:35:11 +00:00
free ( ind ) ;
ind = NULL ;
}
}
free ( file - > industryspec ) ;
file - > industryspec = NULL ;
}
if ( file - > indtspec ! = NULL ) {
for ( i = 0 ; i < NUM_INDUSTRYTILES ; i + + ) {
if ( file - > indtspec [ i ] ! = NULL ) {
free ( file - > indtspec [ i ] ) ;
file - > indtspec [ i ] = NULL ;
}
}
free ( file - > indtspec ) ;
file - > indtspec = NULL ;
}
}
}
2007-03-07 11:47:46 +00:00
static void ResetNewGRF ( )
2006-10-26 19:16:10 +00:00
{
2007-03-10 09:55:11 +00:00
GRFFile * next ;
2006-10-26 19:16:10 +00:00
2007-03-10 09:55:11 +00:00
for ( GRFFile * f = _first_grffile ; f ! = NULL ; f = next ) {
2006-10-26 19:16:10 +00:00
next = f - > next ;
free ( f - > filename ) ;
2007-05-25 06:39:12 +00:00
free ( f - > cargo_list ) ;
2006-10-26 19:16:10 +00:00
free ( f ) ;
}
_first_grffile = NULL ;
_cur_grffile = NULL ;
}
2007-06-12 09:41:12 +00:00
static void ResetNewGRFErrors ( )
{
for ( GRFConfig * c = _grfconfig ; c ! = NULL ; c = c - > next ) {
2007-11-19 21:02:30 +00:00
if ( ! HasBit ( c - > flags , GCF_COPY ) & & c - > error ! = NULL ) {
2007-06-12 13:22:14 +00:00
free ( c - > error - > custom_message ) ;
free ( c - > error - > data ) ;
2007-06-12 09:41:12 +00:00
free ( c - > error ) ;
c - > error = NULL ;
}
}
}
2005-09-26 18:43:58 +00:00
/**
* Reset all NewGRF loaded data
* TODO
*/
2007-03-07 11:47:46 +00:00
static void ResetNewGRFData ( )
2005-09-26 18:43:58 +00:00
{
2006-04-21 03:00:20 +00:00
CleanUpStrings ( ) ;
2007-06-18 23:00:55 +00:00
CleanUpGRFTownNames ( ) ;
2006-04-21 03:00:20 +00:00
2007-03-21 03:06:21 +00:00
/* Copy/reset original engine info data */
2008-01-08 18:25:51 +00:00
SetupEngines ( ) ;
2005-10-01 17:38:48 +00:00
2008-02-05 04:48:56 +00:00
/* Copy/reset original bridge info data */
ResetBridges ( ) ;
2005-10-04 21:42:00 +00:00
2008-08-24 23:00:11 +00:00
/* Reset rail type information */
ResetRailTypes ( ) ;
2008-04-22 18:20:41 +00:00
/* Allocate temporary refit/cargo class data */
2008-04-29 21:31:29 +00:00
_gted = CallocT < GRFTempEngineData > ( GetEnginePoolSize ( ) ) ;
2005-11-06 13:42:26 +00:00
2007-03-21 03:06:21 +00:00
/* Reset GRM reservations */
2006-10-27 13:15:21 +00:00
memset ( & _grm_engines , 0 , sizeof ( _grm_engines ) ) ;
2007-06-02 08:56:21 +00:00
memset ( & _grm_cargos , 0 , sizeof ( _grm_cargos ) ) ;
2006-10-27 13:15:21 +00:00
2008-02-12 13:23:57 +00:00
/* Reset generic feature callback lists */
ResetGenericCallbacks ( ) ;
2007-03-21 03:06:21 +00:00
/* Reset price base data */
2005-10-12 07:27:56 +00:00
ResetPriceBaseMultipliers ( ) ;
2005-11-12 00:19:34 +00:00
2006-08-25 00:41:10 +00:00
/* Reset the curencies array */
ResetCurrencies ( ) ;
2007-03-19 11:27:30 +00:00
/* Reset the house array */
ResetCustomHouses ( ) ;
ResetHouses ( ) ;
2007-05-29 17:41:59 +00:00
/* Reset the industries structures*/
2007-05-31 03:35:11 +00:00
ResetCustomIndustries ( ) ;
2007-05-29 17:41:59 +00:00
ResetIndustries ( ) ;
2007-03-21 03:06:21 +00:00
/* Reset station classes */
2005-11-12 00:19:34 +00:00
ResetStationClasses ( ) ;
ResetCustomStations ( ) ;
2006-01-02 22:40:39 +00:00
2008-01-21 20:41:04 +00:00
/* Reset canal sprite groups and flags */
memset ( _water_feature , 0 , sizeof ( _water_feature ) ) ;
2007-05-06 18:14:33 +00:00
2007-03-20 13:47:00 +00:00
/* Reset the snowline table. */
ClearSnowLine ( ) ;
2006-10-26 19:16:10 +00:00
/* Reset NewGRF files */
ResetNewGRF ( ) ;
2007-06-12 09:41:12 +00:00
/* Reset NewGRF errors. */
ResetNewGRFErrors ( ) ;
2007-02-20 22:09:21 +00:00
/* Set up the default cargo types */
2008-05-29 15:13:28 +00:00
SetupCargoForClimate ( _settings_game . game_creation . landscape ) ;
2007-02-20 22:09:21 +00:00
2006-05-14 20:58:12 +00:00
/* Reset misc GRF features and train list display variables */
_misc_grf_features = 0 ;
_traininfo_vehicle_pitch = 0 ;
_traininfo_vehicle_width = 29 ;
2007-05-31 19:13:41 +00:00
2007-06-15 23:55:52 +00:00
_loaded_newgrf_features . has_2CC = false ;
_loaded_newgrf_features . has_newhouses = false ;
2007-10-02 01:12:06 +00:00
_loaded_newgrf_features . has_newindustries = false ;
2008-01-24 14:49:40 +00:00
_loaded_newgrf_features . shore = SHORE_REPLACE_NONE ;
2006-05-14 20:58:12 +00:00
2008-04-29 21:31:29 +00:00
/* Clear all GRF overrides */
_grf_id_overrides . clear ( ) ;
2006-09-27 18:17:01 +00:00
InitializeSoundPool ( ) ;
2006-04-20 20:51:57 +00:00
InitializeSpriteGroupPool ( ) ;
2005-09-26 18:43:58 +00:00
}
2007-02-24 23:20:21 +00:00
static void BuildCargoTranslationMap ( )
{
memset ( _cur_grffile - > cargo_map , 0xFF , sizeof ( _cur_grffile - > cargo_map ) ) ;
for ( CargoID c = 0 ; c < NUM_CARGO ; c + + ) {
const CargoSpec * cs = GetCargo ( c ) ;
if ( ! cs - > IsValid ( ) ) continue ;
if ( _cur_grffile - > cargo_max = = 0 ) {
/* Default translation table, so just a straight mapping to bitnum */
_cur_grffile - > cargo_map [ c ] = cs - > bitnum ;
} else {
/* Check the translation table for this cargo's label */
for ( uint i = 0 ; i < _cur_grffile - > cargo_max ; i + + ) {
if ( cs - > label = = _cur_grffile - > cargo_list [ i ] ) {
_cur_grffile - > cargo_map [ c ] = i ;
break ;
}
}
}
}
}
2006-04-22 13:17:13 +00:00
static void InitNewGRFFile ( const GRFConfig * config , int sprite_offset )
2004-11-12 23:26:02 +00:00
{
2007-03-10 09:55:11 +00:00
GRFFile * newfile = GetFileByFilename ( config - > filename ) ;
2004-11-22 22:52:01 +00:00
if ( newfile ! = NULL ) {
2004-11-22 22:51:19 +00:00
/* We already loaded it once. */
newfile - > sprite_offset = sprite_offset ;
_cur_grffile = newfile ;
return ;
}
2007-01-11 17:29:39 +00:00
newfile = CallocT < GRFFile > ( 1 ) ;
2004-11-12 22:28:19 +00:00
2006-02-18 14:41:24 +00:00
if ( newfile = = NULL ) error ( " Out of memory " ) ;
2004-11-12 22:28:19 +00:00
2007-06-23 21:12:09 +00:00
newfile - > filename = strdup ( config - > filename ) ;
2004-11-12 22:28:19 +00:00
newfile - > sprite_offset = sprite_offset ;
2006-04-22 13:17:13 +00:00
/* Copy the initial parameter list */
assert ( lengthof ( newfile - > param ) = = lengthof ( config - > param ) & & lengthof ( config - > param ) = = 0x80 ) ;
newfile - > param_end = config - > num_params ;
2006-12-30 01:14:00 +00:00
memcpy ( newfile - > param , config - > param , sizeof ( newfile - > param ) ) ;
2006-04-22 13:17:13 +00:00
2004-11-12 22:28:19 +00:00
if ( _first_grffile = = NULL ) {
_cur_grffile = newfile ;
_first_grffile = newfile ;
} else {
_cur_grffile - > next = newfile ;
_cur_grffile = newfile ;
}
}
2006-11-06 10:11:03 +00:00
2007-02-24 22:01:18 +00:00
/** List of what cargo labels are refittable for the given the vehicle-type.
* Only currently active labels are applied . */
static const CargoLabel _default_refitmasks_rail [ ] = {
' PASS ' , ' COAL ' , ' MAIL ' , ' LVST ' , ' GOOD ' , ' GRAI ' , ' WHEA ' , ' MAIZ ' , ' WOOD ' ,
' IORE ' , ' STEL ' , ' VALU ' , ' GOLD ' , ' DIAM ' , ' PAPR ' , ' FOOD ' , ' FRUT ' , ' CORE ' ,
' WATR ' , ' SUGR ' , ' TOYS ' , ' BATT ' , ' SWET ' , ' TOFF ' , ' COLA ' , ' CTCD ' , ' BUBL ' ,
' PLST ' , ' FZDR ' ,
0 } ;
static const CargoLabel _default_refitmasks_road [ ] = {
0 } ;
static const CargoLabel _default_refitmasks_ships [ ] = {
' COAL ' , ' MAIL ' , ' LVST ' , ' GOOD ' , ' GRAI ' , ' WHEA ' , ' MAIZ ' , ' WOOD ' , ' IORE ' ,
' STEL ' , ' VALU ' , ' GOLD ' , ' DIAM ' , ' PAPR ' , ' FOOD ' , ' FRUT ' , ' CORE ' , ' WATR ' ,
' RUBR ' , ' SUGR ' , ' TOYS ' , ' BATT ' , ' SWET ' , ' TOFF ' , ' COLA ' , ' CTCD ' , ' BUBL ' ,
' PLST ' , ' FZDR ' ,
0 } ;
static const CargoLabel _default_refitmasks_aircraft [ ] = {
' PASS ' , ' MAIL ' , ' GOOD ' , ' VALU ' , ' GOLD ' , ' DIAM ' , ' FOOD ' , ' FRUT ' , ' SUGR ' ,
' TOYS ' , ' BATT ' , ' SWET ' , ' TOFF ' , ' COLA ' , ' CTCD ' , ' BUBL ' , ' PLST ' , ' FZDR ' ,
0 } ;
static const CargoLabel * _default_refitmasks [ ] = {
_default_refitmasks_rail ,
_default_refitmasks_road ,
_default_refitmasks_ships ,
_default_refitmasks_aircraft ,
2006-11-06 10:11:03 +00:00
} ;
2005-11-06 13:42:26 +00:00
/**
* Precalculate refit masks from cargo classes for all vehicles .
*/
2007-03-07 11:47:46 +00:00
static void CalculateRefitMasks ( )
2005-11-06 13:42:26 +00:00
{
2008-04-29 21:31:29 +00:00
Engine * e ;
FOR_ALL_ENGINES ( e ) {
EngineID engine = e - > index ;
EngineInfo * ei = & e - > info ;
2005-11-06 13:42:26 +00:00
uint32 mask = 0 ;
uint32 not_mask = 0 ;
2007-03-10 16:21:29 +00:00
uint32 xor_mask = 0 ;
2008-03-27 17:51:20 +00:00
if ( ei - > refit_mask ! = 0 ) {
2008-04-29 21:31:29 +00:00
const GRFFile * file = e - > grffile ;
2007-03-10 16:21:29 +00:00
if ( file ! = NULL & & file - > cargo_max ! = 0 ) {
/* Apply cargo translation table to the refit mask */
uint num_cargo = min ( 32 , file - > cargo_max ) ;
for ( uint i = 0 ; i < num_cargo ; i + + ) {
2008-03-27 17:51:20 +00:00
if ( ! HasBit ( ei - > refit_mask , i ) ) continue ;
2007-03-10 16:21:29 +00:00
CargoID c = GetCargoIDByLabel ( file - > cargo_list [ i ] ) ;
if ( c = = CT_INVALID ) continue ;
2007-11-20 13:35:54 +00:00
SetBit ( xor_mask , c ) ;
2007-03-10 16:21:29 +00:00
}
} else {
/* No cargo table, so use the cargo bitnum values */
for ( CargoID c = 0 ; c < NUM_CARGO ; c + + ) {
const CargoSpec * cs = GetCargo ( c ) ;
if ( ! cs - > IsValid ( ) ) continue ;
2008-03-27 17:51:20 +00:00
if ( HasBit ( ei - > refit_mask , cs - > bitnum ) ) SetBit ( xor_mask , c ) ;
2007-03-10 16:21:29 +00:00
}
}
}
2005-11-06 13:42:26 +00:00
2008-04-22 18:20:41 +00:00
if ( _gted [ engine ] . cargo_allowed ! = 0 ) {
2007-03-21 03:06:21 +00:00
/* Build up the list of cargo types from the set cargo classes. */
2007-03-10 09:55:11 +00:00
for ( CargoID i = 0 ; i < NUM_CARGO ; i + + ) {
2007-02-22 22:09:51 +00:00
const CargoSpec * cs = GetCargo ( i ) ;
2008-04-22 18:20:41 +00:00
if ( _gted [ engine ] . cargo_allowed & cs - > classes ) SetBit ( mask , i ) ;
if ( _gted [ engine ] . cargo_disallowed & cs - > classes ) SetBit ( not_mask , i ) ;
2005-11-06 13:42:26 +00:00
}
2008-04-29 21:31:29 +00:00
} else if ( xor_mask = = 0 ) {
2007-03-21 03:06:21 +00:00
/* Don't apply default refit mask to wagons or engines with no capacity */
2008-04-29 21:31:29 +00:00
if ( e - > type ! = VEH_TRAIN | | ( e - > u . rail . capacity ! = 0 & & e - > u . rail . railveh_type ! = RAILVEH_WAGON ) ) {
const CargoLabel * cl = _default_refitmasks [ e - > type ] ;
2007-02-24 22:01:18 +00:00
for ( uint i = 0 ; ; i + + ) {
if ( cl [ i ] = = 0 ) break ;
CargoID cargo = GetCargoIDByLabel ( cl [ i ] ) ;
if ( cargo = = CT_INVALID ) continue ;
2007-11-20 13:35:54 +00:00
SetBit ( xor_mask , cargo ) ;
2007-02-24 22:01:18 +00:00
}
2006-02-18 14:41:24 +00:00
}
2005-11-06 13:42:26 +00:00
}
2008-03-27 17:51:20 +00:00
ei - > refit_mask = ( ( mask & ~ not_mask ) ^ xor_mask ) & _cargo_mask ;
2007-02-24 19:26:45 +00:00
/* Check if this engine's cargo type is valid. If not, set to the first refittable
* cargo type . Apparently cargo_type isn ' t a common property . . . */
2008-04-29 21:31:29 +00:00
switch ( e - > type ) {
2007-05-18 17:31:41 +00:00
default : NOT_REACHED ( ) ;
case VEH_AIRCRAFT : break ;
2007-03-08 16:27:54 +00:00
case VEH_TRAIN : {
2008-04-29 21:31:29 +00:00
RailVehicleInfo * rvi = & e - > u . rail ;
2007-02-24 19:26:45 +00:00
if ( rvi - > cargo_type = = CT_INVALID ) rvi - > cargo_type = FindFirstRefittableCargo ( engine ) ;
2008-04-29 21:31:29 +00:00
if ( rvi - > cargo_type = = CT_INVALID ) ei - > climates = 0x80 ;
2007-02-24 19:26:45 +00:00
break ;
}
2007-03-08 16:27:54 +00:00
case VEH_ROAD : {
2008-04-29 21:31:29 +00:00
RoadVehicleInfo * rvi = & e - > u . road ;
2007-02-24 19:26:45 +00:00
if ( rvi - > cargo_type = = CT_INVALID ) rvi - > cargo_type = FindFirstRefittableCargo ( engine ) ;
2008-04-29 21:31:29 +00:00
if ( rvi - > cargo_type = = CT_INVALID ) ei - > climates = 0x80 ;
2007-02-24 19:26:45 +00:00
break ;
}
2007-03-08 16:27:54 +00:00
case VEH_SHIP : {
2008-04-29 21:31:29 +00:00
ShipVehicleInfo * svi = & e - > u . ship ;
2007-02-24 19:26:45 +00:00
if ( svi - > cargo_type = = CT_INVALID ) svi - > cargo_type = FindFirstRefittableCargo ( engine ) ;
2008-04-29 21:31:29 +00:00
if ( svi - > cargo_type = = CT_INVALID ) ei - > climates = 0x80 ;
2007-02-24 19:26:45 +00:00
break ;
}
}
2005-11-06 13:42:26 +00:00
}
}
2004-11-12 19:03:37 +00:00
2007-03-19 11:27:30 +00:00
/** Add all new houses to the house array. House properties can be set at any
* time in the GRF file , so we can only add a house spec to the house array
* after the file has finished loading . We also need to check the dates , due to
* the TTDPatch behaviour described below that we need to emulate . */
static void FinaliseHouseArray ( )
{
/* If there are no houses with start dates before 1930, then all houses
* with start dates of 1930 have them reset to 0. This is in order to be
* compatible with TTDPatch , where if no houses have start dates before
* 1930 and the date is before 1930 , the game pretends that this is 1930.
* If there have been any houses defined with start dates before 1930 then
2007-12-31 07:14:25 +00:00
* the dates are left alone .
* On the other hand , why 1930 ? Just ' fix ' the houses with the lowest
* minimum introduction date to 0.
*/
2008-06-03 03:06:16 +00:00
Year min_year = MAX_YEAR ;
2007-03-19 11:27:30 +00:00
for ( GRFFile * file = _first_grffile ; file ! = NULL ; file = file - > next ) {
if ( file - > housespec = = NULL ) continue ;
for ( int i = 0 ; i < HOUSE_MAX ; i + + ) {
HouseSpec * hs = file - > housespec [ i ] ;
if ( hs ! = NULL ) {
2007-05-15 21:36:58 +00:00
_house_mngr . SetEntitySpec ( hs ) ;
2008-06-03 03:06:16 +00:00
if ( hs - > min_year < min_year ) min_year = hs - > min_year ;
2007-03-19 11:27:30 +00:00
}
}
}
2008-06-03 03:06:16 +00:00
if ( min_year ! = 0 ) {
2007-12-31 07:14:25 +00:00
for ( int i = 0 ; i < HOUSE_MAX ; i + + ) {
2007-03-19 11:27:30 +00:00
HouseSpec * hs = GetHouseSpecs ( i ) ;
2008-06-03 03:06:16 +00:00
if ( hs - > enabled & & hs - > min_year = = min_year ) hs - > min_year = 0 ;
2007-03-19 11:27:30 +00:00
}
}
}
2007-07-06 20:40:58 +00:00
/** Add all new industries to the industry array. Industry properties can be set at any
* time in the GRF file , so we can only add a industry spec to the industry array
* after the file has finished loading . */
static void FinaliseIndustriesArray ( )
{
for ( GRFFile * file = _first_grffile ; file ! = NULL ; file = file - > next ) {
if ( file - > industryspec ! = NULL ) {
for ( int i = 0 ; i < NUM_INDUSTRYTYPES ; i + + ) {
IndustrySpec * indsp = file - > industryspec [ i ] ;
2007-07-10 00:10:19 +00:00
if ( indsp ! = NULL & & indsp - > enabled ) {
StringID strid ;
/* process the conversion of text at the end, so to be sure everything will be fine
* and available . Check if it does not return undefind marker , which is a very good sign of a
* substitute industry who has not changed the string been examined , thus using it as such */
strid = GetGRFStringID ( indsp - > grf_prop . grffile - > grfid , indsp - > name ) ;
if ( strid ! = STR_UNDEFINED ) indsp - > name = strid ;
strid = GetGRFStringID ( indsp - > grf_prop . grffile - > grfid , indsp - > closure_text ) ;
if ( strid ! = STR_UNDEFINED ) indsp - > closure_text = strid ;
strid = GetGRFStringID ( indsp - > grf_prop . grffile - > grfid , indsp - > production_up_text ) ;
if ( strid ! = STR_UNDEFINED ) indsp - > production_up_text = strid ;
strid = GetGRFStringID ( indsp - > grf_prop . grffile - > grfid , indsp - > production_down_text ) ;
if ( strid ! = STR_UNDEFINED ) indsp - > production_down_text = strid ;
strid = GetGRFStringID ( indsp - > grf_prop . grffile - > grfid , indsp - > new_industry_text ) ;
if ( strid ! = STR_UNDEFINED ) indsp - > new_industry_text = strid ;
2008-02-02 03:23:26 +00:00
if ( indsp - > station_name ! = STR_NULL ) {
/* STR_NULL (0) can be set by grf. It has a meaning regarding assignation of the
2008-08-25 20:10:45 +00:00
* station ' s name . Don ' t want to lose the value , therefore , do not process . */
2008-02-02 03:23:26 +00:00
strid = GetGRFStringID ( indsp - > grf_prop . grffile - > grfid , indsp - > station_name ) ;
if ( strid ! = STR_UNDEFINED ) indsp - > station_name = strid ;
}
2007-07-06 20:40:58 +00:00
_industry_mngr . SetEntitySpec ( indsp ) ;
_loaded_newgrf_features . has_newindustries = true ;
}
}
}
if ( file - > indtspec ! = NULL ) {
for ( int i = 0 ; i < NUM_INDUSTRYTILES ; i + + ) {
IndustryTileSpec * indtsp = file - > indtspec [ i ] ;
if ( indtsp ! = NULL ) {
_industile_mngr . SetEntitySpec ( indtsp ) ;
}
}
}
}
2007-07-11 22:57:47 +00:00
for ( uint j = 0 ; j < NUM_INDUSTRYTYPES ; j + + ) {
IndustrySpec * indsp = & _industry_specs [ j ] ;
if ( indsp - > enabled & & indsp - > grf_prop . grffile ! = NULL ) {
for ( uint i = 0 ; i < 3 ; i + + ) {
indsp - > conflicting [ i ] = MapNewGRFIndustryType ( indsp - > conflicting [ i ] , indsp - > grf_prop . grffile - > grfid ) ;
}
}
}
2007-07-06 20:40:58 +00:00
}
2007-03-22 23:19:40 +00:00
2004-08-09 17:04:08 +00:00
/* Here we perform initial decoding of some special sprites (as are they
* described at http : //www.ttdpatch.net/src/newgrf.txt, but this is only a very
2004-11-12 23:26:02 +00:00
* partial implementation yet ) . */
2004-08-09 17:04:08 +00:00
/* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by
* a crafted invalid GRF file . We should tell that to the user somehow , or
* better make this more robust in the future . */
2006-10-31 22:54:57 +00:00
static void DecodeSpecialSprite ( uint num , GrfLoadingStage stage )
2004-08-09 17:04:08 +00:00
{
2005-08-15 11:39:13 +00:00
/* XXX: There is a difference between staged loading in TTDPatch and
* here . In TTDPatch , for some reason actions 1 and 2 are carried out
2006-04-15 21:27:59 +00:00
* during stage 1 , whilst action 3 is carried out during stage 2 ( to
2005-08-15 11:39:13 +00:00
* " resolve " cargo IDs . . . wtf ) . This is a little problem , because cargo
* IDs are valid only within a given set ( action 1 ) block , and may be
* overwritten after action 3 associates them . But overwriting happens
* in an earlier stage than associating , so . . . We just process actions
2006-04-15 21:27:59 +00:00
* 1 and 2 in stage 2 now , let ' s hope that won ' t get us into problems .
2005-08-15 11:39:13 +00:00
* - - pasky */
2006-04-15 21:27:59 +00:00
/* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf
* is not in memory and scanning the file every time would be too expensive .
* In other stages we skip action 0x10 since it ' s already dealt with . */
2006-10-31 22:54:57 +00:00
static const SpecialSpriteHandler handlers [ ] [ GLS_END ] = {
2007-11-17 15:03:19 +00:00
/* 0x00 */ { NULL , SafeChangeInfo , NULL , NULL , ReserveChangeInfo , FeatureChangeInfo , } ,
2007-05-05 10:47:35 +00:00
/* 0x01 */ { SkipAct1 , SkipAct1 , SkipAct1 , SkipAct1 , SkipAct1 , NewSpriteSet , } ,
/* 0x02 */ { NULL , NULL , NULL , NULL , NULL , NewSpriteGroup , } ,
2007-03-22 23:19:40 +00:00
/* 0x03 */ { NULL , GRFUnsafe , NULL , NULL , NULL , FeatureMapSpriteGroup , } ,
/* 0x04 */ { NULL , NULL , NULL , NULL , NULL , FeatureNewName , } ,
2007-04-26 06:49:32 +00:00
/* 0x05 */ { SkipAct5 , SkipAct5 , SkipAct5 , SkipAct5 , SkipAct5 , GraphicsNew , } ,
2007-03-24 23:43:33 +00:00
/* 0x06 */ { NULL , NULL , NULL , CfgApply , CfgApply , CfgApply , } ,
2007-03-22 23:19:40 +00:00
/* 0x07 */ { NULL , NULL , NULL , NULL , SkipIf , SkipIf , } ,
2007-06-05 21:41:31 +00:00
/* 0x08 */ { ScanInfo , NULL , NULL , GRFInfo , GRFInfo , GRFInfo , } ,
2007-03-22 23:19:40 +00:00
/* 0x09 */ { NULL , NULL , NULL , SkipIf , SkipIf , SkipIf , } ,
2007-04-26 06:49:32 +00:00
/* 0x0A */ { SkipActA , SkipActA , SkipActA , SkipActA , SkipActA , SpriteReplace , } ,
2007-03-22 23:19:40 +00:00
/* 0x0B */ { NULL , NULL , NULL , GRFLoadError , GRFLoadError , GRFLoadError , } ,
/* 0x0C */ { NULL , NULL , NULL , GRFComment , NULL , GRFComment , } ,
/* 0x0D */ { NULL , SafeParamSet , NULL , ParamSet , ParamSet , ParamSet , } ,
/* 0x0E */ { NULL , SafeGRFInhibit , NULL , GRFInhibit , GRFInhibit , GRFInhibit , } ,
2007-06-18 23:00:55 +00:00
/* 0x0F */ { NULL , GRFUnsafe , NULL , FeatureTownName , NULL , NULL , } ,
2007-03-22 23:19:40 +00:00
/* 0x10 */ { NULL , NULL , DefineGotoLabel , NULL , NULL , NULL , } ,
2008-01-28 15:55:59 +00:00
/* 0x11 */ { SkipAct11 , GRFUnsafe , SkipAct11 , SkipAct11 , SkipAct11 , GRFSound , } ,
/* 0x12 */ { SkipAct12 , SkipAct12 , SkipAct12 , SkipAct12 , SkipAct12 , LoadFontGlyph , } ,
2007-03-22 23:19:40 +00:00
/* 0x13 */ { NULL , NULL , NULL , NULL , NULL , TranslateGRFStrings , } ,
2004-08-09 17:04:08 +00:00
} ;
2005-08-15 11:39:13 +00:00
2008-08-19 09:08:45 +00:00
bool preloaded_sprite = true ;
GRFLocation location ( _cur_grfconfig - > grfid , _nfo_line ) ;
byte * buf ;
2004-08-09 17:04:08 +00:00
2008-08-19 09:08:45 +00:00
GRFLineToSpriteOverride : : iterator it = _grf_line_to_action6_sprite_override . find ( location ) ;
if ( it = = _grf_line_to_action6_sprite_override . end ( ) ) {
2006-05-23 20:59:01 +00:00
/* No preloaded sprite to work with; allocate and read the
* pseudo sprite content . */
2007-01-11 17:29:39 +00:00
buf = MallocT < byte > ( num ) ;
2006-05-23 20:59:01 +00:00
FioReadBlock ( buf , num ) ;
2008-08-19 09:08:45 +00:00
preloaded_sprite = false ;
2006-05-23 20:59:01 +00:00
} else {
/* Use the preloaded sprite data. */
2008-08-19 09:08:45 +00:00
buf = _grf_line_to_action6_sprite_override [ location ] ;
2006-12-26 17:36:18 +00:00
grfmsg ( 7 , " DecodeSpecialSprite: Using preloaded pseudo sprite data " ) ;
2006-05-23 20:59:01 +00:00
/* Skip the real (original) content of this action. */
FioSeekTo ( num , SEEK_CUR ) ;
}
2004-11-12 15:15:56 +00:00
2007-03-10 09:55:11 +00:00
byte action = buf [ 0 ] ;
2005-08-15 11:39:13 +00:00
2006-09-27 18:17:01 +00:00
if ( action = = 0xFF ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " DecodeSpecialSprite: Handling data block in stage %d " , stage ) ;
2006-09-27 18:17:01 +00:00
GRFDataBlock ( buf , num ) ;
2006-10-12 07:42:37 +00:00
} else if ( action = = 0xFE ) {
2007-11-17 15:03:19 +00:00
grfmsg ( 7 , " DecodeSpecialSprite: Handling import block in stage %d " , stage ) ;
2006-10-12 07:42:37 +00:00
GRFImportBlock ( buf , num ) ;
2006-09-27 18:17:01 +00:00
} else if ( action > = lengthof ( handlers ) ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " DecodeSpecialSprite: Skipping unknown action 0x%02X " , action ) ;
2006-10-31 22:54:57 +00:00
} else if ( handlers [ action ] [ stage ] = = NULL ) {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " DecodeSpecialSprite: Skipping action 0x%02X in stage %d " , action , stage ) ;
2005-11-15 09:47:25 +00:00
} else {
2007-04-16 20:56:19 +00:00
grfmsg ( 7 , " DecodeSpecialSprite: Handling action 0x%02X in stage %d " , action , stage ) ;
2006-10-31 22:54:57 +00:00
handlers [ action ] [ stage ] ( buf , num ) ;
2005-08-15 11:39:13 +00:00
}
2008-08-19 09:08:45 +00:00
if ( ! preloaded_sprite ) free ( buf ) ;
2005-08-15 11:39:13 +00:00
}
2004-11-12 23:26:02 +00:00
2008-01-04 15:39:08 +00:00
void LoadNewGRFFile ( GRFConfig * config , uint file_index , GrfLoadingStage stage )
2005-08-15 11:39:13 +00:00
{
2007-06-23 21:12:09 +00:00
const char * filename = config - > filename ;
2005-08-15 11:39:13 +00:00
uint16 num ;
/* A .grf file is activated only if it was active when the game was
* started . If a game is loaded , only its active . grfs will be
* reactivated , unless " loadallgraphics on " is used . A . grf file is
* considered active if its action 8 has been processed , i . e . its
* action 8 hasn ' t been skipped using an action 7.
*
* During activation , only actions 0 , 1 , 2 , 3 , 4 , 5 , 7 , 8 , 9 , 0 A and 0 B are
* carried out . All others are ignored , because they only need to be
* processed once at initialization . */
2006-12-12 19:38:41 +00:00
if ( stage ! = GLS_FILESCAN & & stage ! = GLS_SAFETYSCAN & & stage ! = GLS_LABELSCAN ) {
2005-08-15 11:39:13 +00:00
_cur_grffile = GetFileByFilename ( filename ) ;
2008-06-05 20:54:52 +00:00
if ( _cur_grffile = = NULL ) usererror ( " File '%s' lost in cache. \n " , filename ) ;
2007-06-05 21:41:31 +00:00
if ( stage = = GLS_RESERVE & & config - > status ! = GCS_INITIALISED ) return ;
2007-11-19 21:02:30 +00:00
if ( stage = = GLS_ACTIVATION & & ! HasBit ( config - > flags , GCF_RESERVED ) ) return ;
2008-01-04 15:39:08 +00:00
_cur_grffile - > is_ottdfile = config - > IsOpenTTDBaseGRF ( ) ;
2005-08-15 11:39:13 +00:00
}
2007-10-29 23:02:31 +00:00
if ( file_index > LAST_GRF_SLOT ) {
DEBUG ( grf , 0 , " '%s' is not loaded as the maximum number of GRFs has been reached " , filename ) ;
config - > status = GCS_DISABLED ;
config - > error = CallocT < GRFError > ( 1 ) ;
config - > error - > severity = STR_NEWGRF_ERROR_MSG_FATAL ;
config - > error - > message = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED ;
return ;
}
2005-08-15 11:39:13 +00:00
FioOpenFile ( file_index , filename ) ;
_file_index = file_index ; // XXX
2006-12-04 08:30:04 +00:00
_cur_grfconfig = config ;
2007-04-16 20:56:19 +00:00
DEBUG ( grf , 2 , " LoadNewGRFFile: Reading NewGRF-file '%s' " , filename ) ;
2005-08-15 11:39:13 +00:00
/* Skip the first sprite; we don't care about how many sprites this
* does contain ; newest TTDPatches and George ' s longvehicles don ' t
* neither , apparently . */
if ( FioReadWord ( ) = = 4 & & FioReadByte ( ) = = 0xFF ) {
FioReadDword ( ) ;
} else {
2007-04-16 20:56:19 +00:00
DEBUG ( grf , 7 , " LoadNewGRFFile: Custom .grf has invalid format " ) ;
2006-12-04 08:30:04 +00:00
return ;
2005-08-15 11:39:13 +00:00
}
_skip_sprites = 0 ; // XXX
2006-04-15 16:40:54 +00:00
_nfo_line = 0 ;
2005-08-15 11:39:13 +00:00
while ( ( num = FioReadWord ( ) ) ! = 0 ) {
byte type = FioReadByte ( ) ;
2006-04-15 16:40:54 +00:00
_nfo_line + + ;
2005-08-15 11:39:13 +00:00
if ( type = = 0xFF ) {
if ( _skip_sprites = = 0 ) {
2006-02-02 07:15:46 +00:00
DecodeSpecialSprite ( num , stage ) ;
2006-11-01 17:42:34 +00:00
/* Stop all processing if we are to skip the remaining sprites */
if ( _skip_sprites = = - 1 ) break ;
2005-08-15 11:39:13 +00:00
continue ;
} else {
FioSkipBytes ( num ) ;
}
} else {
2008-08-29 20:03:51 +00:00
if ( _skip_sprites = = 0 ) {
grfmsg ( 0 , " LoadNewGRFFile: Unexpected sprite, disabling " ) ;
config - > status = GCS_DISABLED ;
config - > error = CallocT < GRFError > ( 1 ) ;
config - > error - > severity = STR_NEWGRF_ERROR_MSG_FATAL ;
config - > error - > message = STR_NEWGRF_ERROR_UNEXPECTED_SPRITE ;
break ;
}
2005-08-15 11:39:13 +00:00
FioSkipBytes ( 7 ) ;
num - = 8 ;
2004-11-12 23:26:02 +00:00
2005-08-15 11:39:13 +00:00
if ( type & 2 ) {
FioSkipBytes ( num ) ;
} else {
while ( num > 0 ) {
int8 i = FioReadByte ( ) ;
if ( i > = 0 ) {
num - = i ;
FioSkipBytes ( i ) ;
2005-04-01 10:43:20 +00:00
} else {
2005-08-15 11:39:13 +00:00
i = - ( i > > 3 ) ;
num - = i ;
FioReadByte ( ) ;
2005-04-01 10:43:20 +00:00
}
2005-08-15 11:39:13 +00:00
}
2005-04-01 10:43:20 +00:00
}
2004-11-12 23:26:02 +00:00
}
2005-08-15 11:39:13 +00:00
if ( _skip_sprites > 0 ) _skip_sprites - - ;
2004-08-09 17:04:08 +00:00
}
2005-08-15 11:39:13 +00:00
}
2004-08-09 17:04:08 +00:00
2008-01-24 14:49:40 +00:00
/**
* Relocates the old shore sprites at new positions .
*
* 1. If shore sprites are neither loaded by Action5 nor ActionA , the extra sprites from openttd ( w / d ) . grf are used . ( SHORE_REPLACE_ONLY_NEW )
* 2. If a newgrf replaces some shore sprites by ActionA . The ( maybe also replaced ) grass tiles are used for corner shores . ( SHORE_REPLACE_ACTION_A )
* 3. If a newgrf replaces shore sprites by Action5 any shore replacement by ActionA has no effect . ( SHORE_REPLACE_ACTION_5 )
*/
static void ActivateOldShore ( )
{
/* Use default graphics, if no shore sprites were loaded.
* Should not happen , as openttd ( w / d ) . grf includes some . */
if ( _loaded_newgrf_features . shore = = SHORE_REPLACE_NONE ) _loaded_newgrf_features . shore = SHORE_REPLACE_ACTION_A ;
if ( _loaded_newgrf_features . shore ! = SHORE_REPLACE_ACTION_5 ) {
DupSprite ( SPR_ORIGINALSHORE_START + 1 , SPR_SHORE_BASE + 1 ) ; // SLOPE_W
DupSprite ( SPR_ORIGINALSHORE_START + 2 , SPR_SHORE_BASE + 2 ) ; // SLOPE_S
DupSprite ( SPR_ORIGINALSHORE_START + 6 , SPR_SHORE_BASE + 3 ) ; // SLOPE_SW
DupSprite ( SPR_ORIGINALSHORE_START , SPR_SHORE_BASE + 4 ) ; // SLOPE_E
DupSprite ( SPR_ORIGINALSHORE_START + 4 , SPR_SHORE_BASE + 6 ) ; // SLOPE_SE
DupSprite ( SPR_ORIGINALSHORE_START + 3 , SPR_SHORE_BASE + 8 ) ; // SLOPE_N
DupSprite ( SPR_ORIGINALSHORE_START + 7 , SPR_SHORE_BASE + 9 ) ; // SLOPE_NW
DupSprite ( SPR_ORIGINALSHORE_START + 5 , SPR_SHORE_BASE + 12 ) ; // SLOPE_NE
}
if ( _loaded_newgrf_features . shore = = SHORE_REPLACE_ACTION_A ) {
DupSprite ( SPR_FLAT_GRASS_TILE + 16 , SPR_SHORE_BASE + 0 ) ; // SLOPE_STEEP_S
DupSprite ( SPR_FLAT_GRASS_TILE + 17 , SPR_SHORE_BASE + 5 ) ; // SLOPE_STEEP_W
DupSprite ( SPR_FLAT_GRASS_TILE + 7 , SPR_SHORE_BASE + 7 ) ; // SLOPE_WSE
DupSprite ( SPR_FLAT_GRASS_TILE + 15 , SPR_SHORE_BASE + 10 ) ; // SLOPE_STEEP_N
DupSprite ( SPR_FLAT_GRASS_TILE + 11 , SPR_SHORE_BASE + 11 ) ; // SLOPE_NWS
DupSprite ( SPR_FLAT_GRASS_TILE + 13 , SPR_SHORE_BASE + 13 ) ; // SLOPE_ENW
DupSprite ( SPR_FLAT_GRASS_TILE + 14 , SPR_SHORE_BASE + 14 ) ; // SLOPE_SEN
DupSprite ( SPR_FLAT_GRASS_TILE + 18 , SPR_SHORE_BASE + 15 ) ; // SLOPE_STEEP_E
/* XXX - SLOPE_EW, SLOPE_NS are currently not used.
* If they would be used somewhen , then these grass tiles will most like not look as needed */
DupSprite ( SPR_FLAT_GRASS_TILE + 5 , SPR_SHORE_BASE + 16 ) ; // SLOPE_EW
DupSprite ( SPR_FLAT_GRASS_TILE + 10 , SPR_SHORE_BASE + 17 ) ; // SLOPE_NS
}
}
2007-03-07 11:47:46 +00:00
void InitDepotWindowBlockSizes ( ) ;
2005-08-15 11:39:13 +00:00
2008-01-17 02:10:26 +00:00
extern void InitGRFTownGeneratorNames ( ) ;
2007-06-18 23:00:55 +00:00
2007-03-19 11:27:30 +00:00
static void AfterLoadGRFs ( )
{
2008-04-17 11:47:22 +00:00
for ( StringIDToGRFIDMapping : : iterator it = _string_to_grf_mapping . begin ( ) ; it ! = _string_to_grf_mapping . end ( ) ; it + + ) {
* ( ( * it ) . first ) = MapGRFStringID ( ( * it ) . second , * ( ( * it ) . first ) ) ;
}
_string_to_grf_mapping . clear ( ) ;
2008-08-19 09:08:45 +00:00
/* Free the action 6 override sprites. */
for ( GRFLineToSpriteOverride : : iterator it = _grf_line_to_action6_sprite_override . begin ( ) ; it ! = _grf_line_to_action6_sprite_override . end ( ) ; it + + ) {
free ( ( * it ) . second ) ;
}
_grf_line_to_action6_sprite_override . clear ( ) ;
2007-03-19 11:27:30 +00:00
/* Pre-calculate all refit masks after loading GRF files. */
CalculateRefitMasks ( ) ;
/* Set the block size in the depot windows based on vehicle sprite sizes */
InitDepotWindowBlockSizes ( ) ;
/* Add all new houses to the house array. */
FinaliseHouseArray ( ) ;
2007-03-22 23:19:40 +00:00
2007-07-06 20:40:58 +00:00
/* Add all new industries to the industry array. */
FinaliseIndustriesArray ( ) ;
2007-04-26 20:20:12 +00:00
/* Create dynamic list of industry legends for smallmap_gui.cpp */
BuildIndustriesLegend ( ) ;
2007-06-18 23:00:55 +00:00
/* Update the townname generators list */
2008-01-17 02:10:26 +00:00
InitGRFTownGeneratorNames ( ) ;
2008-01-24 14:49:40 +00:00
2008-04-29 21:31:29 +00:00
/* Run all queued vehicle list order changes */
2008-07-20 21:23:28 +00:00
CommitVehicleListOrderChanges ( ) ;
2008-04-29 21:31:29 +00:00
2008-01-24 14:49:40 +00:00
/* Load old shore sprites in new position, if they were replaced by ActionA */
ActivateOldShore ( ) ;
2008-04-22 18:20:41 +00:00
/* Deallocate temporary loading data */
free ( _gted ) ;
2008-05-05 19:02:10 +00:00
_grm_sprites . clear ( ) ;
2007-03-19 11:27:30 +00:00
}
2005-08-15 11:39:13 +00:00
void LoadNewGRF ( uint load_index , uint file_index )
{
2006-01-30 14:50:55 +00:00
InitializeGRFSpecial ( ) ;
2005-08-15 11:39:13 +00:00
2005-09-26 18:43:58 +00:00
ResetNewGRFData ( ) ;
2007-12-29 23:49:48 +00:00
/*
* Reset the status of all files , so we can ' retry ' to load them .
* This is needed when one for example rearranges the NewGRFs in - game
* and a previously disabled NewGRF becomes useable . If it would not
* be reset , the NewGRF would remain disabled even though it should
* have been enabled .
*/
for ( GRFConfig * c = _grfconfig ; c ! = NULL ; c = c - > next ) {
if ( c - > status ! = GCS_NOT_FOUND ) c - > status = GCS_UNKNOWN ;
}
2008-05-05 19:02:10 +00:00
_cur_spriteid = load_index ;
2005-08-15 11:39:13 +00:00
/* Load newgrf sprites
* in each loading stage , ( try to ) open each file specified in the config
* and load information from it . */
2007-11-04 22:21:46 +00:00
for ( GrfLoadingStage stage = GLS_LABELSCAN ; stage < = GLS_ACTIVATION ; stage + + ) {
2008-03-04 10:41:16 +00:00
/* Set activated grfs back to will-be-activated between reservation- and activation-stage.
* This ensures that action7 / 9 conditions 0x06 - 0x0A work correctly . */
for ( GRFConfig * c = _grfconfig ; c ! = NULL ; c = c - > next ) {
if ( c - > status = = GCS_ACTIVATED ) c - > status = GCS_INITIALISED ;
}
2005-09-09 06:39:47 +00:00
uint slot = file_index ;
2005-08-15 11:39:13 +00:00
_cur_stage = stage ;
2007-03-10 09:55:11 +00:00
for ( GRFConfig * c = _grfconfig ; c ! = NULL ; c = c - > next ) {
2007-03-06 19:33:28 +00:00
if ( c - > status = = GCS_DISABLED | | c - > status = = GCS_NOT_FOUND ) continue ;
2007-11-19 21:02:30 +00:00
if ( stage > GLS_INIT & & HasBit ( c - > flags , GCF_INIT_ONLY ) ) continue ;
2006-12-04 08:30:04 +00:00
2007-03-21 03:06:21 +00:00
/* @todo usererror() */
2008-06-05 20:54:52 +00:00
if ( ! FioCheckFileExists ( c - > filename ) ) usererror ( " NewGRF file is missing '%s' " , c - > filename ) ;
2006-04-22 13:17:13 +00:00
2006-10-31 22:54:57 +00:00
if ( stage = = GLS_LABELSCAN ) InitNewGRFFile ( c , _cur_spriteid ) ;
2008-01-04 15:39:08 +00:00
LoadNewGRFFile ( c , slot + + , stage ) ;
2007-06-07 18:13:31 +00:00
if ( stage = = GLS_RESERVE ) {
2007-11-20 13:35:54 +00:00
SetBit ( c - > flags , GCF_RESERVED ) ;
2007-11-04 22:21:46 +00:00
} else if ( stage = = GLS_ACTIVATION ) {
2007-11-19 21:32:20 +00:00
ClrBit ( c - > flags , GCF_RESERVED ) ;
2007-01-02 20:00:10 +00:00
ClearTemporaryNewGRFData ( ) ;
2007-02-24 23:20:21 +00:00
BuildCargoTranslationMap ( ) ;
2007-04-16 20:56:19 +00:00
DEBUG ( sprite , 2 , " LoadNewGRF: Currently %i sprites are loaded " , _cur_spriteid ) ;
2007-01-02 20:00:10 +00:00
}
2005-08-15 11:39:13 +00:00
}
}
2005-11-06 13:42:26 +00:00
2007-03-19 11:27:30 +00:00
/* Call any functions that should be run after GRFs have been loaded. */
AfterLoadGRFs ( ) ;
2004-08-09 17:04:08 +00:00
}
2007-04-27 21:35:02 +00:00
bool HasGrfMiscBit ( GrfMiscBit bit )
{
2007-11-19 21:02:30 +00:00
return HasBit ( _misc_grf_features , bit ) ;
2007-04-27 21:35:02 +00:00
}