newgrf.c
author celestar
Fri, 29 Dec 2006 10:13:35 +0000
branchcustombridgeheads
changeset 5592 fd60d4ecc921
parent 5588 1bcb6b4c01d8
child 5623 ef2a8a524a95
child 5664 dbbf4f842a00
permissions -rw-r--r--
(svn r7608) [cbh] - Merge with trunk r7593:7607 because I need 7607 here
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     7
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1183
diff changeset
     8
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "fileio.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    11
#include "functions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "engine.h"
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    13
#include "spritecache.h"
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
    14
#include "station.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 404
diff changeset
    15
#include "sprite.h"
452
520e4ed6945d (svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents: 449
diff changeset
    16
#include "newgrf.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2013
diff changeset
    17
#include "variables.h"
3566
7bdf06a03960 (svn r4447) - NewGRF: It seems I committed printing action NOP Action 0x0C which is mainly used for comments. So leave it in, but fix the created warning. Use proper action name for check_length() in Action 0x10
Darkvater
parents: 3561
diff changeset
    18
#include "string.h"
3821
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
    19
#include "table/strings.h"
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
    20
#include "bridge.h"
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
    21
#include "economy.h"
2962
dbd168a4703a (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2958
diff changeset
    22
#include "newgrf_engine.h"
3577
9e345c932ba2 (svn r4463) -Codechange. Include vehicle.h directly instead of implicitly via station.h in a number of source files
celestar
parents: 3571
diff changeset
    23
#include "vehicle.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
    24
#include "newgrf_text.h"
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
    25
#include "table/sprites.h"
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
    26
#include "fontcache.h"
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4230
diff changeset
    27
#include "date.h"
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
    28
#include "currency.h"
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    29
#include "sound.h"
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    30
#include "newgrf_config.h"
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    31
#include "newgrf_sound.h"
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
    32
#include "newgrf_spritegroup.h"
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
    33
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    36
 * Changes by Florian octo Forster are (c) by the OpenTTD development team.
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    37
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
 * Thanks especially to Josef Drexler for the documentation as well as a lot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
 * of help at #tycoon. Also thanks to Michael Blunck for is GRF files which
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
 * served as subject to the initial testing of this codec. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
455
e7ac799e1437 (svn r665) code fixes for newgrf.c/newgrf.h
dominik
parents: 452
diff changeset
    43
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    44
static int _skip_sprites; // XXX
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
    45
static uint _file_index; // XXX
5209
fa3ad39e2fa7 (svn r7324) -Codechange: reset newgrf signal location data
peter1138
parents: 5161
diff changeset
    46
SpriteID _signal_base;
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
    47
SpriteID _coast_base;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
2340
0a9f3eeccb96 (svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents: 2336
diff changeset
    49
static GRFFile *_cur_grffile;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    50
GRFFile *_first_grffile;
3707
2999a89e8abd (svn r4650) - NewGRF: use the correct type for _cur_spriteid
peter1138
parents: 3704
diff changeset
    51
static SpriteID _cur_spriteid;
5225
52ddcedcc6f7 (svn r7345) -Codechange: enumification of NewGRF loading stage, and move enum definition to header for future use.
peter1138
parents: 5211
diff changeset
    52
static GrfLoadingStage _cur_stage;
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
    53
static uint32 _nfo_line;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    55
static GRFConfig *_cur_grfconfig;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    56
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
    57
/* Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E */
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
    58
static byte _misc_grf_features = 0;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
    59
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    60
/* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    61
static uint32 _ttdpatch_flags[8];
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    62
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
    63
/* Used by Action 0x06 to preload a pseudo sprite and modify its content */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
    64
static byte *_preload_sprite = NULL;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
    65
4742
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
    66
/* Set if any vehicle is loaded which uses 2cc (two company colours) */
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
    67
bool _have_2cc = false;
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
    68
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
    69
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    70
typedef enum GrfDataType {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    71
	GDT_SOUND,
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    72
} GrfDataType;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    73
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    74
static byte _grf_data_blocks;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    75
static GrfDataType _grf_data_type;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    76
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    77
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    78
typedef enum grfspec_feature {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    79
	GSF_TRAIN,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    80
	GSF_ROAD,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    81
	GSF_SHIP,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    82
	GSF_AIRCRAFT,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    83
	GSF_STATION,
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
    84
	GSF_CANAL,
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    85
	GSF_BRIDGE,
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
    86
	GSF_TOWNHOUSE,
3620
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
    87
	GSF_GLOBALVAR,
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
    88
	GSF_INDUSTRYTILES,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
    89
	GSF_INDUSTRIES,
3620
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
    90
	GSF_CARGOS,
b459e678a003 (svn r4517) - NewGRF: fix and complete the feature list
peter1138
parents: 3614
diff changeset
    91
	GSF_SOUNDFX,
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    92
} grfspec_feature;
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    93
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    94
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
typedef void (*SpecialSpriteHandler)(byte *buf, int len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
4964
0ef1eb7e7f35 (svn r6963) - Fix (r6960): signed/unsigned complaints from MSVC
peter1138
parents: 4961
diff changeset
    97
static const int _vehcounts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    98
	/* GSF_TRAIN */    NUM_TRAIN_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
    99
	/* GSF_ROAD */     NUM_ROAD_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   100
	/* GSF_SHIP */     NUM_SHIP_ENGINES,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   101
	/* GSF_AIRCRAFT */ NUM_AIRCRAFT_ENGINES
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   102
};
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   103
4964
0ef1eb7e7f35 (svn r6963) - Fix (r6960): signed/unsigned complaints from MSVC
peter1138
parents: 4961
diff changeset
   104
static const int _vehshifts[4] = {
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   105
	/* GSF_TRAIN */    0,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   106
	/* GSF_ROAD */     ROAD_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   107
	/* GSF_SHIP */     SHIP_ENGINES_INDEX,
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
   108
	/* GSF_AIRCRAFT */ AIRCRAFT_ENGINES_INDEX,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   111
enum {
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   112
	MAX_STATIONS = 256,
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   113
};
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   114
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   115
static uint16 cargo_allowed[TOTAL_NUM_ENGINES];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
   116
static uint16 cargo_disallowed[TOTAL_NUM_ENGINES];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   118
/* Contains the GRF ID of the owner of a vehicle if it has been reserved */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   119
static uint32 _grm_engines[TOTAL_NUM_ENGINES];
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   120
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   121
/** DEBUG() function dedicated to newGRF debugging messages
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   122
 * Function is essentialy the same as DEBUG(grf, severity, ...) with the
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   123
 * addition of file:line information when parsing grf files.
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   124
 * NOTE: for the above reason(s) grfmsg() should ONLY be used for
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   125
 * loading/parsing grf files, not for runtime debug messages as there
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   126
 * is no file information available during that time.
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   127
 * @param severity debugging severity level, see debug.h
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   128
 * @param debugging message in printf() format */
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   129
void CDECL grfmsg(int severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
{
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   131
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   135
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   137
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   138
	DEBUG(grf, severity, "[%s:%d] %s", _cur_grfconfig->filename, _nfo_line, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   141
static inline void check_length(int real, int wanted, const char *str)
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   142
{
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   143
	if (real >= wanted) return;
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   144
	grfmsg(0, "%s: Invalid pseudo sprite length %d (expected %d)!", str, real, wanted);
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   145
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   146
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   147
static inline byte grf_load_byte(byte **buf)
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
   148
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
{
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   154
	uint16 val = grf_load_byte(buf);
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   155
	return val | (grf_load_byte(buf) << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   158
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   159
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   160
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   161
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   162
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   163
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   164
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   165
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   166
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
{
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   168
	uint32 val = grf_load_word(buf);
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   169
	return val | (grf_load_word(buf) << 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   172
static uint32 grf_load_var(byte size, byte **buf)
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   173
{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   174
	switch (size) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   175
		case 1: return grf_load_byte(buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   176
		case 2: return grf_load_word(buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   177
		case 4: return grf_load_dword(buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   178
		default:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   179
			NOT_REACHED();
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   180
			return 0;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   181
	}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   182
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   183
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   184
static GRFFile *GetFileByGRFID(uint32 grfid)
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   185
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   186
	GRFFile *file;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   187
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   188
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   189
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   190
	}
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   191
	return file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   192
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   193
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   194
static GRFFile *GetFileByFilename(const char *filename)
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   195
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   196
	GRFFile *file;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   197
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   198
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   199
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   200
	}
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   201
	return file;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   202
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   203
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
   204
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   205
typedef bool (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   207
#define FOR_EACH_OBJECT for (i = 0; i < numinfo; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   214
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		ei->unk2 &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		rvi->flags &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
		ei->unk2 |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		rvi->flags |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   223
static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   229
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   232
		case 0x05: /* Track type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   233
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
3026
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   236
				switch (tracktype) {
5115
06bf0b853f81 (svn r7194) -Fix (FS#237): the electric rail type was not set correctly for NewGRFs where the engine traction type was set before the track type of the trains.
rubidium
parents: 5114
diff changeset
   237
					case 0: ei[i].railtype = rvi[i].engclass == 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
3026
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   238
					case 1: ei[i].railtype = RAILTYPE_MONO; break;
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   239
					case 2: ei[i].railtype = RAILTYPE_MAGLEV; break;
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   240
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   241
						grfmsg(1, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype);
3026
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   242
						break;
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   243
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
			}
3026
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   245
			break;
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   246
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   247
		case 0x08: /* AI passenger service */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   249
			FOR_EACH_OBJECT grf_load_byte(&buf);
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   250
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   251
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   252
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   253
		case 0x09: /* Speed (1 unit is 1 kmh) */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   254
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
				uint16 speed = grf_load_word(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   256
				if (speed == 0xFFFF) speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   260
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   261
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   262
		case 0x0B: /* Power */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   263
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   266
				if (rvi[i].flags & RVI_MULTIHEAD) power /= 2;
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   267
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   271
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   272
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   273
		case 0x0D: /* Running cost factor */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   274
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   277
				if (rvi[i].flags & RVI_MULTIHEAD) runcostfact /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   278
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   281
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   282
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   283
		case 0x0E: /* Running cost base */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   284
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
				switch (base) {
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   288
					case 0x4C30: rvi[i].running_cost_class = 0; break;
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   289
					case 0x4C36: rvi[i].running_cost_class = 1; break;
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   290
					case 0x4C3C: rvi[i].running_cost_class = 2; break;
5324
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   291
					case 0: break; /* Used by wagons */
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   292
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   293
						grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base);
5324
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   294
						break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   297
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   298
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   299
		case 0x12: /* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   300
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
2895
943612f25754 (svn r3449) - NewGRF Fix: When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf)
peter1138
parents: 2876
diff changeset
   303
				/* TTD sprite IDs point to a location in a 16bit array, but we use it
943612f25754 (svn r3449) - NewGRF Fix: When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf)
peter1138
parents: 2876
diff changeset
   304
				 * as an array index, so we need it to be half the original value. */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   305
				if (spriteid < 0xFD) spriteid >>= 1;
2895
943612f25754 (svn r3449) - NewGRF Fix: When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf)
peter1138
parents: 2876
diff changeset
   306
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   309
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   310
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   311
		case 0x13: /* Dual-headed */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   312
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   315
				if (dual != 0) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   316
					if (!(rvi[i].flags & RVI_MULTIHEAD)) {
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   317
						// adjust power and running cost if needed
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   318
						rvi[i].power /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   319
						rvi[i].running_cost_base /= 2;
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   320
					}
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   321
					rvi[i].flags |= RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
				} else {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   323
					if (rvi[i].flags & RVI_MULTIHEAD) {
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   324
						// adjust power and running cost if needed
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   325
						rvi[i].power *= 2;
2840
d68a605b2087 (svn r3388) - NewGRF: Allow train running cost class to differ from engine class. Also fix typo in r3384.
peter1138
parents: 2838
diff changeset
   326
						rvi[i].running_cost_base *= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   327
					}
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   328
					rvi[i].flags &= ~RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   331
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   332
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   333
		case 0x14: /* Cargo capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   334
			FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   335
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   336
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   337
		case 0x15: /* Cargo type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   338
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   341
				if (ctype < NUM_CARGO) {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   342
					rvi[i].cargo_type = ctype;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   343
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   344
					grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, ignoring", ctype);
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   345
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
			}
3023
e56ff3134c77 (svn r3603) - NewGRF: Support loading of AI rank data
peter1138
parents: 3006
diff changeset
   347
			break;
e56ff3134c77 (svn r3603) - NewGRF: Support loading of AI rank data
peter1138
parents: 3006
diff changeset
   348
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   349
		case 0x16: /* Weight */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   350
			FOR_EACH_OBJECT SB(rvi[i].weight, 0, 8, grf_load_byte(&buf));
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   351
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   352
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   353
		case 0x17: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   354
			FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   355
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   356
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   357
		case 0x18: /* AI rank */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   358
			FOR_EACH_OBJECT rvi[i].ai_rank = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   359
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   360
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   361
		case 0x19: /* Engine traction type */
2838
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   362
			/* What do the individual numbers mean?
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   363
			 * 0x00 .. 0x07: Steam
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   364
			 * 0x08 .. 0x27: Diesel
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   365
			 * 0x28 .. 0x31: Electric
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   366
			 * 0x32 .. 0x37: Monorail
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   367
			 * 0x38 .. 0x41: Maglev
7d6a3195f87d (svn r3386) - NewGRF: Small comment update, and fix for possible issue with engine class not getting set.
peter1138
parents: 2836
diff changeset
   368
			 */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   369
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
				uint8 traction = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
				int engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   373
				if (traction <= 0x07) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
					engclass = 0;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   375
				} else if (traction <= 0x27) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
					engclass = 1;
3355
a653b8e47f27 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3095
diff changeset
   377
				} else if (traction <= 0x31) {
a653b8e47f27 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3095
diff changeset
   378
					engclass = 2;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   379
				} else if (traction <= 0x41) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
					engclass = 2;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   381
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
					break;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   383
				}
5115
06bf0b853f81 (svn r7194) -Fix (FS#237): the electric rail type was not set correctly for NewGRFs where the engine traction type was set before the track type of the trains.
rubidium
parents: 5114
diff changeset
   384
				if (ei[i].railtype == RAILTYPE_RAIL     && engclass == 2) ei[i].railtype = RAILTYPE_ELECTRIC;
06bf0b853f81 (svn r7194) -Fix (FS#237): the electric rail type was not set correctly for NewGRFs where the engine traction type was set before the track type of the trains.
rubidium
parents: 5114
diff changeset
   385
				if (ei[i].railtype == RAILTYPE_ELECTRIC && engclass != 2) ei[i].railtype = RAILTYPE_RAIL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   389
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   390
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   391
		case 0x1A: /* Alter purchase list sort order */
2971
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   392
			FOR_EACH_OBJECT {
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   393
				EngineID pos = grf_load_byte(&buf);
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   394
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   395
				if (pos < NUM_TRAIN_ENGINES) {
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   396
					AlterRailVehListOrder(engine + i, pos);
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   397
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   398
					grfmsg(2, "RailVehicleChangeInfo: Invalid train engine ID %d, ignoring", pos);
2971
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   399
				}
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   400
			}
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   401
			break;
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
   402
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   403
		case 0x1B: /* Powered wagons power bonus */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   404
			FOR_EACH_OBJECT rvi[i].pow_wag_power = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   405
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   406
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   407
		case 0x1C: /* Refit cost */
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   408
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   409
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   410
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   411
		case 0x1D: /* Refit cargo */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   412
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   413
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   414
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   415
		case 0x1E: /* Callback */
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   416
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   417
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   418
5588
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   419
		case 0x1F: /* Tractive effort coefficient */
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   420
			FOR_EACH_OBJECT rvi[i].tractive_effort = grf_load_byte(&buf);
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   421
			break;
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
   422
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   423
		case 0x21: /* Shorter vehicle */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   424
			FOR_EACH_OBJECT rvi[i].shorten_factor = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   425
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   426
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   427
		case 0x22: /* Visual effect */
1908
bc48a30aba72 (svn r2414) - Feature: [newgrf] Implement powered wagons, and the callback that goes with it.
hackykid
parents: 1895
diff changeset
   428
			// see note in engine.h about rvi->visual_effect
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   429
			FOR_EACH_OBJECT rvi[i].visual_effect = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   430
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   431
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   432
		case 0x23: /* Powered wagons weight bonus */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   433
			FOR_EACH_OBJECT rvi[i].pow_wag_weight = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   434
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   435
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   436
		case 0x24: /* High byte of vehicle weight */
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   437
			FOR_EACH_OBJECT {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   438
				byte weight = grf_load_byte(&buf);
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   439
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   440
				if (weight > 4) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   441
					grfmsg(2, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8);
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   442
				} else {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   443
					SB(rvi[i].weight, 8, 8, weight);
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   444
				}
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   445
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   446
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   447
3862
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   448
		case 0x25: /* User-defined bit mask to set when checking veh. var. 42 */
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   449
			FOR_EACH_OBJECT rvi[i].user_def_data = grf_load_byte(&buf);
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   450
			break;
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   451
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   452
		case 0x27: /* Miscellaneous flags */
4742
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   453
			FOR_EACH_OBJECT {
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   454
				ei[i].misc_flags = grf_load_byte(&buf);
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   455
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   456
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   457
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   458
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   459
		case 0x28: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   460
			FOR_EACH_OBJECT cargo_allowed[engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   461
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   462
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   463
		case 0x29: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   464
			FOR_EACH_OBJECT cargo_disallowed[engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   465
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   466
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   467
		case 0x2A: /* Long format introduction date (days since year 0) */
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   468
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   469
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   470
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
		/* TODO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
		/* Fall-through for unimplemented one byte long properties. */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   473
		case 0x20: /* Air drag */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   474
		case 0x26: /* Retire vehicle early */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   476
			FOR_EACH_OBJECT grf_load_byte(&buf);
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   477
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   478
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   479
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   481
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   482
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   488
static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   489
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   490
	EngineInfo *ei = &_engine_info[ROAD_ENGINES_INDEX + engine];
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   491
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   492
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   493
	int i;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   494
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   495
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   496
	switch (prop) {
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   497
		case 0x08: /* Speed (1 unit is 0.5 kmh) */
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   498
			FOR_EACH_OBJECT rvi[i].max_speed = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   499
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   500
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   501
		case 0x09: /* Running cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   502
			FOR_EACH_OBJECT rvi[i].running_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   503
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   504
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   505
		case 0x0A: /* Running cost base */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   506
			/* TODO: I have no idea. --pasky */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   507
			FOR_EACH_OBJECT grf_load_dword(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   508
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   509
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   510
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   511
		case 0x0E: /* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   512
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   513
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   514
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   515
				// cars have different custom id in the GRF file
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   516
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   517
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   518
				if (spriteid < 0xFD) spriteid >>= 1;
2895
943612f25754 (svn r3449) - NewGRF Fix: When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf)
peter1138
parents: 2876
diff changeset
   519
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   520
				rvi[i].image_index = spriteid;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   521
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   522
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   523
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   524
		case 0x0F: /* Cargo capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   525
			FOR_EACH_OBJECT rvi[i].capacity = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   526
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   527
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   528
		case 0x10: /* Cargo type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   529
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   530
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   531
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   532
				if (cargo < NUM_CARGO) {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   533
					rvi[i].cargo_type = cargo;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   534
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   535
					grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, ignoring", cargo);
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   536
				}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   537
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   538
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   539
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   540
		case 0x11: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   541
			FOR_EACH_OBJECT rvi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   542
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   543
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   544
		case 0x12: /* SFX */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   545
			FOR_EACH_OBJECT rvi[i].sfx = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   546
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   547
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   548
		case 0x13: /* Power in 10hp */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   549
		case 0x14: /* Weight in 1/4 tons */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   550
		case 0x15: /* Speed in mph*0.8 */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   551
			/* TODO: Support for road vehicles realistic power
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   552
			 * computations (called rvpower in TTDPatch) is just
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   553
			 * missing in OTTD yet. --pasky */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   554
			FOR_EACH_OBJECT grf_load_byte(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   555
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   556
			break;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   557
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   558
		case 0x16: /* Cargos available for refitting */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   559
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   560
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   561
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   562
		case 0x17: /* Callback mask */
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   563
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   564
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   565
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   566
		case 0x1A: /* Refit cost */
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   567
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   568
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   569
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   570
		case 0x1C: /* Miscellaneous flags */
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   571
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   572
				ei[i].misc_flags = grf_load_byte(&buf);
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   573
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   574
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   575
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   576
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   577
		case 0x1D: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   578
			FOR_EACH_OBJECT cargo_allowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   579
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   580
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   581
		case 0x1E: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   582
			FOR_EACH_OBJECT cargo_disallowed[ROAD_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   583
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   584
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   585
		case 0x1F: /* Long format introduction date (days since year 0) */
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   586
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   587
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   588
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   589
		case 0x18: /* Tractive effort */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   590
		case 0x19: /* Air drag */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   591
		case 0x1B: /* Retire vehicle early */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   592
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   593
			FOR_EACH_OBJECT grf_load_byte(&buf);
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   594
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   595
			break;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   596
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   597
		default:
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   598
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   599
			break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   600
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   601
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   602
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   603
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   604
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   605
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   606
static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   608
	EngineInfo *ei = &_engine_info[SHIP_ENGINES_INDEX + engine];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   612
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   616
		case 0x08: /* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   617
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   620
				// ships have different custom id in the GRF file
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   621
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   622
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   623
				if (spriteid < 0xFD) spriteid >>= 1;
2895
943612f25754 (svn r3449) - NewGRF Fix: When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf)
peter1138
parents: 2876
diff changeset
   624
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   627
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   628
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   629
		case 0x09: /* Refittable */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   630
			FOR_EACH_OBJECT svi[i].refittable = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   631
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   632
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   633
		case 0x0A: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   634
			FOR_EACH_OBJECT svi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   635
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   636
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   637
		case 0x0B: /* Speed (1 unit is 0.5 kmh) */
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   638
			FOR_EACH_OBJECT svi[i].max_speed = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   639
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   640
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   641
		case 0x0C: /* Cargo type */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   642
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
				// XXX: Need to consult this with patchman yet.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
#if 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
				// Documentation claims this is already the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
				// per-landscape cargo type id, but newships.grf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
				// assume otherwise.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
				cargo = local_cargo_id_ctype[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
#endif
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   652
				if (cargo < NUM_CARGO) {
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   653
					svi[i].cargo_type = cargo;
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   654
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   655
					grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, ignoring", cargo);
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   656
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
			}
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   658
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   659
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   660
		case 0x0D: /* Cargo capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   661
			FOR_EACH_OBJECT svi[i].capacity = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   662
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   663
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   664
		case 0x0F: /* Running cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   665
			FOR_EACH_OBJECT svi[i].running_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   666
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   667
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   668
		case 0x10: /* SFX */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   669
			FOR_EACH_OBJECT svi[i].sfx = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   670
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   671
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   672
		case 0x11: /* Cargos available for refitting */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   673
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   674
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   675
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   676
		case 0x12: /* Callback mask */
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   677
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   678
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   679
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   680
		case 0x13: /* Refit cost */
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   681
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   682
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   683
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   684
		case 0x17: /* Miscellaneous flags */
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   685
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   686
				ei[i].misc_flags = grf_load_byte(&buf);
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   687
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   688
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   689
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   690
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   691
		case 0x18: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   692
			FOR_EACH_OBJECT cargo_allowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   693
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   694
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   695
		case 0x19: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   696
			FOR_EACH_OBJECT cargo_disallowed[SHIP_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   697
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   698
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   699
		case 0x1A: /* Long format introduction date (days since year 0) */
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   700
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   701
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   702
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   703
		case 0x14: /* Ocean speed fraction */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   704
		case 0x15: /* Canal speed fraction */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   705
		case 0x16: /* Retire vehicle early */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   706
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   707
			FOR_EACH_OBJECT grf_load_byte(&buf);
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   708
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   709
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   710
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   712
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   713
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   720
static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte **bufp, int len)
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   721
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   722
	EngineInfo *ei = &_engine_info[AIRCRAFT_ENGINES_INDEX + engine];
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   723
	AircraftVehicleInfo *avi = &_aircraft_vehicle_info[engine];
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   724
	byte *buf = *bufp;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   725
	int i;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   726
	bool ret = false;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   727
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   728
	//printf("e %x prop %x?\n", engine, prop);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   729
	switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   730
		case 0x08: /* Sprite ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   731
			FOR_EACH_OBJECT {
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   732
				uint8 spriteid = grf_load_byte(&buf);
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   733
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   734
				// aircraft have different custom id in the GRF file
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   735
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   736
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   737
				if (spriteid < 0xFD) spriteid >>= 1;
2895
943612f25754 (svn r3449) - NewGRF Fix: When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf)
peter1138
parents: 2876
diff changeset
   738
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   739
				avi[i].image_index = spriteid;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   740
			}
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   741
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   742
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   743
		case 0x09: /* Helicopter */
4926
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   744
			FOR_EACH_OBJECT {
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   745
				if (grf_load_byte(&buf) == 0) {
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   746
					avi[i].subtype = 0;
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   747
				} else {
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   748
					SB(avi[i].subtype, 0, 1, 1);
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   749
				}
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   750
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   751
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   752
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   753
		case 0x0A: /* Large */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   754
			FOR_EACH_OBJECT SB(avi[i].subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0));
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   755
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   756
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   757
		case 0x0B: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   758
			FOR_EACH_OBJECT avi[i].base_cost = grf_load_byte(&buf); // ?? is it base_cost?
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   759
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   760
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   761
		case 0x0C: /* Speed (1 unit is 8 mph) */
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   762
			FOR_EACH_OBJECT avi[i].max_speed = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   763
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   764
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   765
		case 0x0D: /* Acceleration */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   766
			FOR_EACH_OBJECT avi[i].acceleration = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   767
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   768
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   769
		case 0x0E: /* Running cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   770
			FOR_EACH_OBJECT avi[i].running_cost = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   771
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   772
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   773
		case 0x0F: /* Passenger capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   774
			FOR_EACH_OBJECT avi[i].passenger_capacity = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   775
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   776
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   777
		case 0x11: /* Mail capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   778
			FOR_EACH_OBJECT avi[i].mail_capacity = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   779
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   780
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   781
		case 0x12: /* SFX */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   782
			FOR_EACH_OBJECT avi[i].sfx = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   783
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   784
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   785
		case 0x13: /* Cargos available for refitting */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   786
			FOR_EACH_OBJECT ei[i].refit_mask = grf_load_dword(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   787
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   788
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   789
		case 0x14: /* Callback mask */
3956
0f43adbc293a (svn r5105) - NewGRF: Move callbackmask from *VehicleInfo to EngineInfo. This simplifies code that works with more than one vehicle type.
peter1138
parents: 3924
diff changeset
   790
			FOR_EACH_OBJECT ei[i].callbackmask = grf_load_byte(&buf);
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   791
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   792
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   793
		case 0x15: /* Refit cost */
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   794
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   795
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   796
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   797
		case 0x17: /* Miscellaneous flags */
4952
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   798
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   799
				ei[i].misc_flags = grf_load_byte(&buf);
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   800
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   801
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   802
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   803
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   804
		case 0x18: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   805
			FOR_EACH_OBJECT cargo_allowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   806
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   807
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   808
		case 0x19: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   809
			FOR_EACH_OBJECT cargo_disallowed[AIRCRAFT_ENGINES_INDEX + engine + i] = grf_load_word(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   810
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   811
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   812
		case 0x1A: /* Long format introduction date (days since year 0) */
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   813
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   814
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
   815
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   816
		case 0x16: /* Retire vehicle early */
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   817
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   818
			FOR_EACH_OBJECT grf_load_byte(&buf);
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   819
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   820
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   821
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   822
		default:
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   823
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   824
			break;
381
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   825
	}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   826
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   827
	*bufp = buf;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   828
	return ret;
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   829
}
94c4794d6bd4 (svn r570) -newgrf: Support for custom aircrafts via GRF files. Planeset seems to work :). Also use aircraft_vehinfo() instead of the old tables (pasky).
darkvater
parents: 379
diff changeset
   830
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   831
static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len)
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   832
{
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   833
	StationSpec **statspec;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   834
	byte *buf = *bufp;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   835
	int i;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   836
	bool ret = false;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   837
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   838
	if (stid + numinfo > MAX_STATIONS) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   839
		grfmsg(1, "StationChangeInfo: Station %u is invalid, max %u, ignoring", stid + numinfo, MAX_STATIONS);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   840
		return false;
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   841
	}
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   842
3501
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
   843
	/* Allocate station specs if necessary */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   844
	if (_cur_grffile->stations == NULL) _cur_grffile->stations = calloc(MAX_STATIONS, sizeof(*_cur_grffile->stations));
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   845
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   846
	statspec = &_cur_grffile->stations[stid];
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   847
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   848
	if (prop != 0x08) {
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   849
		/* Check that all stations we are modifying are defined. */
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   850
		FOR_EACH_OBJECT {
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   851
			if (statspec[i] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   852
				grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   853
				return false;
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   854
			}
3501
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
   855
		}
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
   856
	}
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
   857
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   858
	switch (prop) {
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   859
		case 0x08: /* Class ID */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   860
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   861
				uint32 classid;
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   862
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   863
				/* Property 0x08 is special; it is where the station is allocated */
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   864
				if (statspec[i] == NULL) statspec[i] = calloc(1, sizeof(*statspec[i]));
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   865
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
   866
				/* Swap classid because we read it in BE meaning WAYP or DFLT */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   867
				classid = grf_load_dword(&buf);
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   868
				statspec[i]->sclass = AllocateStationClass(BSWAP32(classid));
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   869
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   870
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   871
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   872
		case 0x09: /* Define sprite layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   873
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   874
				StationSpec *statspec = _cur_grffile->stations[stid + i];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   875
				uint t;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   876
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   877
				statspec->tiles = grf_load_extended(&buf);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   878
				statspec->renderdata = calloc(statspec->tiles, sizeof(*statspec->renderdata));
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   879
				statspec->copied_renderdata = false;
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   880
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   881
				for (t = 0; t < statspec->tiles; t++) {
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   882
					DrawTileSprites *dts = &statspec->renderdata[t];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   883
					uint seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   884
3737
26341085bbbf (svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents: 3736
diff changeset
   885
					dts->seq = NULL;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   886
					dts->ground_sprite = grf_load_dword(&buf);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   887
					if (dts->ground_sprite == 0) continue;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   888
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   889
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   890
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   891
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   892
						// no relative bounding box support
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   893
						dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   894
						dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   895
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   896
						dtss->delta_x = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   897
						if ((byte) dtss->delta_x == 0x80) break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   898
						dtss->delta_y = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   899
						dtss->delta_z = grf_load_byte(&buf);
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4201
diff changeset
   900
						dtss->size_x = grf_load_byte(&buf);
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4201
diff changeset
   901
						dtss->size_y = grf_load_byte(&buf);
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4201
diff changeset
   902
						dtss->size_z = grf_load_byte(&buf);
3771
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
   903
						dtss->image = grf_load_dword(&buf);
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
   904
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   905
						/* Remap flags as ours collide */
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   906
						if (HASBIT(dtss->image, 31)) {
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   907
							CLRBIT(dtss->image, 31);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   908
							SETBIT(dtss->image, 30);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   909
						}
3771
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
   910
						if (HASBIT(dtss->image, 14)) {
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
   911
							CLRBIT(dtss->image, 14);
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
   912
							SETBIT(dtss->image, 31);
b34d07131ad1 (svn r4763) - Newstations: revert r4762, instead map bit the palette modifier from bit 14 to bit 31 on GRF load.
peter1138
parents: 3768
diff changeset
   913
						}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   914
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   915
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   916
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   917
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   918
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   919
		case 0x0A: /* Copy sprite layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   920
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   921
				StationSpec *statspec = _cur_grffile->stations[stid + i];
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   922
				byte srcid = grf_load_byte(&buf);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   923
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
   924
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   925
				statspec->tiles = srcstatspec->tiles;
3738
d41775f0f3fb (svn r4720) - Newstations: instead of literally copying sprite layout data, just copy the pointer to the existing data.
peter1138
parents: 3737
diff changeset
   926
				statspec->renderdata = srcstatspec->renderdata;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   927
				statspec->copied_renderdata = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   928
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   929
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   930
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   931
		case 0x0B: /* Callback mask */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   932
			FOR_EACH_OBJECT statspec[i]->callbackmask = grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   933
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   934
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   935
		case 0x0C: /* Disallowed number of platforms */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   936
			FOR_EACH_OBJECT statspec[i]->disallowed_platforms = grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   937
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   938
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   939
		case 0x0D: /* Disallowed platform lengths */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   940
			FOR_EACH_OBJECT statspec[i]->disallowed_lengths = grf_load_byte(&buf);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   941
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   942
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   943
		case 0x0E: /* Define custom layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   944
			FOR_EACH_OBJECT {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
   945
				StationSpec *statspec = _cur_grffile->stations[stid + i];
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   946
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
   947
				statspec->copied_layouts = false;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
   948
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   949
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   950
					byte length = grf_load_byte(&buf);
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   951
					byte number = grf_load_byte(&buf);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   952
					StationLayout layout;
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   953
					uint l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   954
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   955
					if (length == 0 || number == 0) break;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   956
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   957
					//debug("l %d > %d ?", length, stat->lengths);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   958
					if (length > statspec->lengths) {
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   959
						statspec->platforms = realloc(statspec->platforms, length);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   960
						memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   961
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   962
						statspec->layouts = realloc(statspec->layouts, length * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   963
						memset(statspec->layouts + statspec->lengths, 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   964
						       (length - statspec->lengths) * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   965
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   966
						statspec->lengths = length;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   967
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   968
					l = length - 1; // index is zero-based
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   969
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   970
					//debug("p %d > %d ?", number, stat->platforms[l]);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   971
					if (number > statspec->platforms[l]) {
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   972
						statspec->layouts[l] = realloc(statspec->layouts[l],
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   973
						                               number * sizeof(**statspec->layouts));
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   974
						// We expect NULL being 0 here, but C99 guarantees that.
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   975
						memset(statspec->layouts[l] + statspec->platforms[l], 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   976
						       (number - statspec->platforms[l]) * sizeof(**statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   977
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   978
						statspec->platforms[l] = number;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   979
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   980
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
   981
					p = 0;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   982
					layout = malloc(length * number);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   983
					for (l = 0; l < length; l++) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   984
						for (p = 0; p < number; p++) {
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   985
							layout[l * number + p] = grf_load_byte(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   986
						}
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   987
					}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   988
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   989
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   990
					p--;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   991
					free(statspec->layouts[l][p]);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   992
					statspec->layouts[l][p] = layout;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   993
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   994
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   995
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   996
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   997
		case 0x0F: /* Copy custom layout */
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
   998
			FOR_EACH_OBJECT {
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
   999
				StationSpec *statspec = _cur_grffile->stations[stid + i];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1000
				byte srcid = grf_load_byte(&buf);
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1001
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1002
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1003
				statspec->lengths   = srcstatspec->lengths;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1004
				statspec->platforms = srcstatspec->platforms;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1005
				statspec->layouts   = srcstatspec->layouts;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1006
				statspec->copied_layouts = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1007
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1008
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1009
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1010
		case 0x10: /* Little/lots cargo threshold */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1011
			FOR_EACH_OBJECT statspec[i]->cargo_threshold = grf_load_word(&buf);
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1012
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1013
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1014
		case 0x11: /* Pylon placement */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1015
			FOR_EACH_OBJECT statspec[i]->pylons = grf_load_byte(&buf);
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1016
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1017
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1018
		case 0x12: /* Cargo types for random triggers */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1019
			FOR_EACH_OBJECT statspec[i]->cargo_triggers = grf_load_dword(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1020
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1021
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1022
		case 0x13: /* General flags */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1023
			FOR_EACH_OBJECT statspec[i]->flags = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1024
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1025
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1026
		case 0x14: /* Overhead wire placement */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1027
			FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1028
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1029
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1030
		case 0x15: /* Blocked tiles */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1031
			FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1032
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1033
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1034
		default:
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1035
			ret = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1036
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1037
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1038
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1039
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1040
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1041
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1042
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1043
static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int len)
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1044
{
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1045
	byte *buf = *bufp;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1046
	int i;
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1047
	bool ret = false;
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1048
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1049
	switch (prop) {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1050
		case 0x08: /* Year of availability */
4322
0bee6d9bc452 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4321
diff changeset
  1051
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1052
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1053
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1054
		case 0x09: /* Minimum length */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1055
			FOR_EACH_OBJECT _bridge[brid + i].min_length = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1056
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1057
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1058
		case 0x0A: /* Maximum length */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1059
			FOR_EACH_OBJECT _bridge[brid + i].max_length = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1060
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1061
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1062
		case 0x0B: /* Cost factor */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1063
			FOR_EACH_OBJECT _bridge[brid + i].price = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1064
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1065
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1066
		case 0x0C: /* Maximum speed */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1067
			FOR_EACH_OBJECT _bridge[brid + i].speed = grf_load_word(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1068
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1069
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1070
		case 0x0D: /* Bridge sprite tables */
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1071
			FOR_EACH_OBJECT {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1072
				Bridge *bridge = &_bridge[brid + i];
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1073
				byte tableid = grf_load_byte(&buf);
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1074
				byte numtables = grf_load_byte(&buf);
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1075
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1076
				if (bridge->sprite_table == NULL) {
3555
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1077
					/* Allocate memory for sprite table pointers and zero out */
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1078
					bridge->sprite_table = calloc(7, sizeof(*bridge->sprite_table));
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1079
				}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1080
3555
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1081
				for (; numtables-- != 0; tableid++) {
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1082
					byte sprite;
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1083
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1084
					if (tableid >= 7) { // skip invalid data
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1085
						grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid);
3555
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1086
						for (sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf);
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1087
						continue;
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1088
					}
3555
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1089
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1090
					if (bridge->sprite_table[tableid] == NULL) {
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1091
						bridge->sprite_table[tableid] = malloc(32 * sizeof(**bridge->sprite_table));
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1092
					}
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1093
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1094
					for (sprite = 0; sprite < 32; sprite++)
7a4f6e2aee0f (svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
Darkvater
parents: 3548
diff changeset
  1095
						bridge->sprite_table[tableid][sprite] = grf_load_dword(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1096
				}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1097
			}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1098
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1099
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1100
		case 0x0E: /* Flags; bit 0 - disable far pillars */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1101
			FOR_EACH_OBJECT _bridge[brid + i].flags = grf_load_byte(&buf);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1102
			break;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1103
5114
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1104
		case 0x0F: /* Long format year of availability (year since year 0) */
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1105
			FOR_EACH_OBJECT _bridge[brid + i].avail_year = clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1106
			break;
2a29f37a7c1e (svn r7191) -Feature: Add NewGRF support for 32 bit dates, allowing vehicles and bridges to be available before 1920.
peter1138
parents: 5108
diff changeset
  1107
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1108
		default:
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1109
			ret = true;
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1110
	}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1111
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1112
	*bufp = buf;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1113
	return ret;
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  1114
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1115
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1116
static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, int len)
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1117
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1118
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1119
	int i;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1120
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1121
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1122
	switch (prop) {
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1123
		case 0x08: /* Cost base factor */
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1124
			FOR_EACH_OBJECT {
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1125
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1126
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1127
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1128
				if (price < NUM_PRICES) {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1129
					SetPriceBaseMultiplier(price, factor);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1130
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1131
					grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1132
				}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1133
			}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1134
			break;
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1135
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1136
		case 0x0A: // Currency display names
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1137
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1138
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1139
				StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1140
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1141
				if ((newone != STR_UNDEFINED) && (curidx < NUM_CURRENCY)) {
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1142
					_currency_specs[curidx].name = newone;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1143
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1144
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1145
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1146
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1147
		case 0x0B: // Currency multipliers
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1148
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1149
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1150
				uint32 rate = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1151
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1152
				if (curidx < NUM_CURRENCY) {
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1153
					/* TTDPatch uses a multiple of 1000 for its conversion calculations,
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1154
					 * which OTTD does not. For this reason, divide grf value by 1000,
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1155
					 * to be compatible */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1156
					_currency_specs[curidx].rate = rate / 1000;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1157
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1158
					grfmsg(1, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1159
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1160
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1161
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1162
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1163
		case 0x0C: // Currency options
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1164
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1165
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1166
				uint16 options = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1167
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1168
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1169
					_currency_specs[curidx].separator = GB(options, 0, 8);
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1170
					/* By specifying only one bit, we prevent errors,
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1171
					 * since newgrf specs said that only 0 and 1 can be set for symbol_pos */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1172
					_currency_specs[curidx].symbol_pos = GB(options, 8, 1);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1173
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1174
					grfmsg(1, "GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1175
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1176
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1177
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1178
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1179
		case 0x0D: // Currency prefix symbol
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1180
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1181
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1182
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1183
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1184
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1185
					memcpy(_currency_specs[curidx].prefix,&tempfix,4);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1186
					_currency_specs[curidx].prefix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1187
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1188
					grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1189
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1190
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1191
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1192
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1193
		case 0x0E: // Currency suffix symbol
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1194
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1195
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1196
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1197
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1198
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1199
					memcpy(&_currency_specs[curidx].suffix,&tempfix,4);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1200
					_currency_specs[curidx].suffix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1201
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1202
					grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1203
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1204
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1205
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1206
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1207
		case 0x0F: //  Euro introduction dates
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1208
			FOR_EACH_OBJECT {
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1209
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1210
				Year year_euro = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1211
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1212
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1213
					_currency_specs[curidx].to_euro = year_euro;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1214
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1215
					grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1216
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1217
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1218
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1219
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1220
		case 0x09: // Cargo translation table
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1221
		case 0x10: // 12 * 32 * B Snow line height table
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1222
		default:
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1223
			ret = true;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1224
	}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1225
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1226
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1227
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1228
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1229
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1230
static bool SoundEffectChangeInfo(uint sid, int numinfo, int prop, byte **bufp, int len)
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1231
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1232
	byte *buf = *bufp;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1233
	int i;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1234
	bool ret = false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1235
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1236
	if (_cur_grffile->sound_offset == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1237
		grfmsg(1, "SoundEffectChangeInfo: No effects defined, skipping");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1238
		return false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1239
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1240
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1241
	switch (prop) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1242
		case 0x08: /* Relative volume */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1243
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1244
				uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1245
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1246
				if (sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1247
					grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1248
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1249
					GetSound(sound)->volume = grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1250
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1251
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1252
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1253
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1254
		case 0x09: /* Priority */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1255
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1256
				uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1257
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1258
				if (sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1259
					grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1260
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1261
					GetSound(sound)->priority = grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1262
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1263
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1264
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1265
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1266
		case 0x0A: /* Override old sound */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1267
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1268
				uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1269
				uint orig_sound = grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1270
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1271
				if (sound >= GetNumSounds() || orig_sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1272
					grfmsg(1, "SoundEffectChangeInfo: Sound %d or %d not defined (max %d)", sound, orig_sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1273
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1274
					FileEntry *newfe = GetSound(sound);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1275
					FileEntry *oldfe = GetSound(orig_sound);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1276
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1277
					/* Literally copy the data of the new sound over the original */
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  1278
					*oldfe = *newfe;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1279
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1280
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1281
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1282
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1283
		default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1284
			ret = true;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1285
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1286
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1287
	*bufp = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1288
	return ret;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1289
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1290
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1291
/* Action 0x00 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1292
static void FeatureChangeInfo(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	/* <00> <feature> <num-props> <num-info> <id> (<property <new-info>)...
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
	 * B feature       0, 1, 2 or 3 for trains, road vehicles, ships or planes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
	 * B num-props     how many properties to change per vehicle/station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	 * B id            ID of first vehicle/station to change, if num-info is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
	 * B property      what property to change, depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
	 * V new-info      new bytes of info (variable size; depends on properties) */
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1308
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  1310
	static const VCI_Handler handler[] = {
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1311
		/* GSF_TRAIN */        RailVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1312
		/* GSF_ROAD */         RoadVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1313
		/* GSF_SHIP */         ShipVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1314
		/* GSF_AIRCRAFT */     AircraftVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1315
		/* GSF_STATION */      StationChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1316
		/* GSF_CANAL */        NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1317
		/* GSF_BRIDGE */       BridgeChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1318
		/* GSF_TOWNHOUSE */    NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1319
		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1320
		/* GSF_INDUSTRYTILES */NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1321
		/* GSF_INDUSTRIES */   NULL,
4138
15f4aa024ad4 (svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents: 4077
diff changeset
  1322
		/* GSF_CARGOS */       NULL,
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1323
		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1325
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1326
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1327
	uint8 numprops;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1328
	uint8 numinfo;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1329
	byte engine;
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1330
	EngineInfo *ei = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
396
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1332
	if (len == 1) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1333
		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
396
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1334
		return;
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1335
	}
f7dc2d2144b6 (svn r588) -newgrf: Silent ignore those stupid one-byte zero special sprites (dbsetw.grf is crawling with them) (pasky).
darkvater
parents: 391
diff changeset
  1336
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1337
	check_length(len, 6, "FeatureChangeInfo");
3714
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1338
	buf++;
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1339
	feature  = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1340
	numprops = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1341
	numinfo  = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1342
	engine   = grf_load_byte(&buf);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1343
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1344
	grfmsg(6, "FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d",
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1345
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1346
2440
443e2f3cce75 (svn r2966) Fix: newgrf: Replace special case with a check for the existence of a handler in VehicleChangeInfo.
peter1138
parents: 2439
diff changeset
  1347
	if (feature >= lengthof(handler) || handler[feature] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1348
		grfmsg(1, "FeatureChangeInfo: Unsupported feature %d, skipping", feature);
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1349
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1350
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1351
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1352
	if (feature <= GSF_AIRCRAFT) {
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1353
		if (engine + numinfo > _vehcounts[feature]) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1354
			grfmsg(0, "FeatureChangeInfo: Last engine ID %d out of bounds (max %d), skipping", engine + numinfo, _vehcounts[feature]);
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1355
			return;
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1356
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1357
		ei = &_engine_info[engine + _vehshifts[feature]];
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1358
	}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1359
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1360
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1361
		uint8 prop = grf_load_byte(&buf);
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1362
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1363
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1364
		switch (feature) {
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1365
			case GSF_TRAIN:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1366
			case GSF_ROAD:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1367
			case GSF_SHIP:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1368
			case GSF_AIRCRAFT:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1369
				/* Common properties for vehicles */
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1370
				switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1371
					case 0x00: /* Introduction date */
4322
0bee6d9bc452 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4321
diff changeset
  1372
						FOR_EACH_OBJECT ei[i].base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1373
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1374
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1375
					case 0x02: /* Decay speed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1376
						FOR_EACH_OBJECT SB(ei[i].unk2, 0, 7, grf_load_byte(&buf) & 0x7F);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1377
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1378
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1379
					case 0x03: /* Vehicle life */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1380
						FOR_EACH_OBJECT ei[i].lifelength = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1381
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1382
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1383
					case 0x04: /* Model life */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1384
						FOR_EACH_OBJECT ei[i].base_life = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1385
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1386
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1387
					case 0x06: /* Climates available */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1388
						FOR_EACH_OBJECT ei[i].climates = grf_load_byte(&buf);
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1389
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1390
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1391
					case 0x07: /* Loading speed */
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1392
						/* Hyronymus explained me what does
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1393
						 * this mean and insists on having a
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1394
						 * credit ;-). --pasky */
5211
651c9272ad22 (svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents: 5210
diff changeset
  1395
						FOR_EACH_OBJECT ei[i].load_amount = grf_load_byte(&buf);
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1396
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1397
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1398
					default:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1399
						if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1400
							ignoring = true;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1401
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1402
				}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1403
				break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1404
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1405
			default:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1406
				if (handler[feature](engine, numinfo, prop, &buf, bufend - buf))
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1407
					ignoring = true;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1408
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1409
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1410
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1411
		if (ignoring) grfmsg(2, "FeatureChangeInfo: Ignoring property 0x%02X (not implemented)", prop);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
439
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1415
#undef FOR_EACH_OBJECT
4e71a04a7fce (svn r648) Dummy skip-support for two new station properties. Rename FOR_EACH_ENGINE() to more appropriate FOR_EACH_OBJECT(). (pasky)
miham
parents: 438
diff changeset
  1416
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1417
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1418
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1419
 * @param value The value that was used to represent this callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1420
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1421
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1422
static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1423
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  1424
	SpriteGroup *group = AllocateSpriteGroup();
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1425
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1426
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1427
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1428
	// Old style callback results have the highest byte 0xFF so signify it is a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1429
	// New style ones only have the highest bit set (allows 15-bit results, instead of just 8)
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1430
	if ((value >> 8) == 0xFF) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1431
		value &= ~0xFF00;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1432
	} else {
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1433
		value &= ~0x8000;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1434
	}
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1435
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1436
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1437
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1438
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1439
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
2489
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1441
/**
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1442
 * Creates a spritegroup representing a sprite number result.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1443
 * @param value The sprite number.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1444
 * @param sprites The number of sprites per set.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1445
 * @return A spritegroup representing the sprite number result.
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1446
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1447
static const SpriteGroup* NewResultSpriteGroup(SpriteID sprite, byte num_sprites)
2489
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1448
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  1449
	SpriteGroup *group = AllocateSpriteGroup();
2489
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1450
	group->type = SGT_RESULT;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1451
	group->g.result.sprite = sprite;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1452
	group->g.result.num_sprites = num_sprites;
2489
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1453
	return group;
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1454
}
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1455
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1456
/* Action 0x01 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1457
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1464
	 * E num-ent       how many entries per sprite set
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
	 *                         In that case, use num-dirs=4.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	 *                 For stations, must be 12 (hex) for the eighteen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
	 *                         different sprites that make up a station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
	/* TODO: No stations support. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1472
	uint8 feature;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1473
	uint num_sets;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1474
	uint num_ents;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1475
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1477
	check_length(len, 4, "NewSpriteSet");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1478
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1479
	feature  = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1480
	num_sets = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1481
	num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1483
	_cur_grffile->spriteset_start = _cur_spriteid;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1484
	_cur_grffile->spriteset_feature = feature;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1485
	_cur_grffile->spriteset_numsets = num_sets;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1486
	_cur_grffile->spriteset_numents = num_ents;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1487
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1488
	grfmsg(7, "New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d)",
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1489
		_cur_spriteid, feature, num_sets, num_ents, num_sets * num_ents
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1490
	);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1491
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1492
	for (i = 0; i < num_sets * num_ents; i++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1493
		LoadNextSprite(_cur_spriteid++, _file_index);
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  1494
		_nfo_line++;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  1495
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1498
/* Helper function to either create a callback or link to a previously
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1499
 * defined spritegroup. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1500
static const SpriteGroup* GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1501
{
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1502
	if (HASBIT(groupid, 15)) return NewCallBackResultSpriteGroup(groupid);
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1503
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1504
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1505
		grfmsg(1, "NewSpriteGroup(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid);
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1506
		return NULL;
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1507
	}
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1508
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1509
	return _cur_grffile->spritegroups[groupid];
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1510
}
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1511
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1512
/* Helper function to either create a callback or a result sprite group. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1513
static const SpriteGroup* CreateGroupFromGroupID(byte feature, byte setid, byte type, uint16 spriteid, uint16 num_sprites)
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1514
{
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1515
	if (HASBIT(spriteid, 15)) return NewCallBackResultSpriteGroup(spriteid);
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1516
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1517
	if (spriteid >= _cur_grffile->spriteset_numsets) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1518
		grfmsg(1, "NewSpriteGroup(0x%02X:0x%02X): Sprite set %u invalid, max %u", setid, type, spriteid, _cur_grffile->spriteset_numsets);
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1519
		return NULL;
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1520
	}
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1521
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1522
	/* Check if the sprite is within range. This can fail if the Action 0x01
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1523
	 * is skipped, as TTDPatch mandates that Action 0x02s must be processed.
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1524
	 * We don't have that rule, but must live by the Patch... */
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1525
	if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1526
		grfmsg(1, "NewSpriteGroup(0x%02X:0x%02X): Real Sprite IDs 0x%04X - 0x%04X do not (all) exist (max 0x%04X), leaving empty",
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1527
				setid, type,
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1528
				_cur_grffile->spriteset_start + spriteid * num_sprites,
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1529
				_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites - 1, _cur_spriteid - 1);
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1530
		return NULL;
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1531
	}
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1532
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1533
	if (feature != _cur_grffile->spriteset_feature) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1534
		grfmsg(1, "NewSpriteGroup(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping",
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1535
				_cur_grffile->spriteset_feature, feature);
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1536
		return NULL;
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1537
	}
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1538
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1539
	return NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteid * num_sprites, num_sprites);
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1540
}
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  1541
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1542
/* Action 0x02 */
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1543
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
	/* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
	 *                 if 80 or greater, this is a randomized or variational
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	 * V feature-specific-data (huge mess, don't even look it up --pasky) */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1555
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1556
	uint8 setid;
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1557
	uint8 type;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1558
	SpriteGroup *group = NULL;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1559
	byte *bufend = buf + len;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1560
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1561
	check_length(len, 5, "NewSpriteGroup");
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1562
	buf++;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1563
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1564
	feature = grf_load_byte(&buf);
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1565
	setid   = grf_load_byte(&buf);
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1566
	type    = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
2444
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1568
	if (setid >= _cur_grffile->spritegroups_count) {
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1569
		// Allocate memory for new sprite group references.
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1570
		_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, (setid + 1) * sizeof(*_cur_grffile->spritegroups));
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1571
		// Initialise new space to NULL
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1572
		for (; _cur_grffile->spritegroups_count < (setid + 1); _cur_grffile->spritegroups_count++)
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1573
			_cur_grffile->spritegroups[_cur_grffile->spritegroups_count] = NULL;
2444
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1574
	}
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1575
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1576
	switch (type) {
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1577
		/* Deterministic Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1578
		case 0x81: // Self scope, byte
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1579
		case 0x82: // Parent scope, byte
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1580
		case 0x85: // Self scope, word
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1581
		case 0x86: // Parent scope, word
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1582
		case 0x89: // Self scope, dword
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1583
		case 0x8A: // Parent scope, dword
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1584
		{
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1585
			byte varadjust;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1586
			byte varsize;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1587
			uint i;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1588
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1589
			/* Check we can load the var size parameter */
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1590
			check_length(bufend - buf, 1, "NewSpriteGroup (Deterministic) (1)");
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1591
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1592
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1593
			group->type = SGT_DETERMINISTIC;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1594
			group->g.determ.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1595
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1596
			switch (GB(type, 2, 2)) {
3672
73caf2e829f8 (svn r4588) - NewGRF: silence a false compiler warning
peter1138
parents: 3668
diff changeset
  1597
				default: NOT_REACHED();
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1598
				case 0: group->g.determ.size = DSG_SIZE_BYTE;  varsize = 1; break;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1599
				case 1: group->g.determ.size = DSG_SIZE_WORD;  varsize = 2; break;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1600
				case 2: group->g.determ.size = DSG_SIZE_DWORD; varsize = 4; break;
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1601
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1602
5288
7758df538a10 (svn r7437) -Fix (r4583): incorrect minimum size check in some cases for VarAction2
peter1138
parents: 5287
diff changeset
  1603
			check_length(bufend - buf, 5 + varsize, "NewSpriteGroup (Deterministic) (2)");
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1604
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1605
			/* Loop through the var adjusts. Unfortunately we don't know how many we have
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1606
			 * from the outset, so we shall have to keep reallocing. */
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1607
			do {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1608
				DeterministicSpriteGroupAdjust *adjust;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1609
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1610
				if (group->g.determ.num_adjusts > 0) {
3694
ba2b26464b85 (svn r4631) - NewGRF: fix incorrect length check
peter1138
parents: 3676
diff changeset
  1611
					check_length(bufend - buf, 2 + varsize + 3, "NewSpriteGroup (Deterministic) (3)");
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1612
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1613
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1614
				group->g.determ.num_adjusts++;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1615
				group->g.determ.adjusts = realloc(group->g.determ.adjusts, group->g.determ.num_adjusts * sizeof(*group->g.determ.adjusts));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1616
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1617
				adjust = &group->g.determ.adjusts[group->g.determ.num_adjusts - 1];
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1618
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1619
				/* The first var adjust doesn't have an operation specified, so we set it to add. */
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1620
				adjust->operation = group->g.determ.num_adjusts == 1 ? DSGA_OP_ADD : grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1621
				adjust->variable  = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1622
				adjust->parameter = IS_BYTE_INSIDE(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1623
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1624
				varadjust = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1625
				adjust->shift_num = GB(varadjust, 0, 5);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1626
				adjust->type      = GB(varadjust, 6, 2);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1627
				adjust->and_mask  = grf_load_var(varsize, &buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1628
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1629
				if (adjust->type != DSGA_TYPE_NONE) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1630
					adjust->add_val    = grf_load_var(varsize, &buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1631
					adjust->divmod_val = grf_load_var(varsize, &buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1632
				} else {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1633
					adjust->add_val    = 0;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1634
					adjust->divmod_val = 0;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1635
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1636
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1637
				/* Continue reading var adjusts while bit 5 is set. */
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1638
			} while (HASBIT(varadjust, 5));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1639
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1640
			group->g.determ.num_ranges = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1641
			group->g.determ.ranges = calloc(group->g.determ.num_ranges, sizeof(*group->g.determ.ranges));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1642
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1643
			check_length(bufend - buf, 2 + (2 + 2 * varsize) * group->g.determ.num_ranges, "NewSpriteGroup (Deterministic)");
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1644
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1645
			for (i = 0; i < group->g.determ.num_ranges; i++) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1646
				group->g.determ.ranges[i].group = GetGroupFromGroupID(setid, type, grf_load_word(&buf));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1647
				group->g.determ.ranges[i].low   = grf_load_var(varsize, &buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1648
				group->g.determ.ranges[i].high  = grf_load_var(varsize, &buf);
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1649
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1650
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1651
			group->g.determ.default_group = GetGroupFromGroupID(setid, type, grf_load_word(&buf));
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1652
			break;
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 441
diff changeset
  1653
		}
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 441
diff changeset
  1654
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1655
		/* Randomized Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1656
		case 0x80: // Self scope
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1657
		case 0x83: // Parent scope
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1658
		{
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1659
			byte triggers;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1660
			uint i;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1661
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1662
			check_length(bufend - buf, 7, "NewSpriteGroup (Randomized) (1)");
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1663
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1664
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1665
			group->type = SGT_RANDOMIZED;
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1666
			group->g.random.var_scope = HASBIT(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1667
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1668
			triggers = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1669
			group->g.random.triggers       = GB(triggers, 0, 7);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1670
			group->g.random.cmp_mode       = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1671
			group->g.random.lowest_randbit = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1672
			group->g.random.num_groups     = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1673
			group->g.random.groups = calloc(group->g.random.num_groups, sizeof(*group->g.random.groups));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1674
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1675
			check_length(bufend - buf, 2 * group->g.random.num_groups, "NewSpriteGroup (Randomized) (2)");
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1676
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1677
			for (i = 0; i < group->g.random.num_groups; i++) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1678
				group->g.random.groups[i] = GetGroupFromGroupID(setid, type, grf_load_word(&buf));
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1679
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1680
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1681
			break;
2489
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1682
		}
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1683
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1684
		/* Neither a variable or randomized sprite group... must be a real group */
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1685
		default:
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1686
		{
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1687
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1688
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1689
			switch (feature) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1690
				case GSF_TRAIN:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1691
				case GSF_ROAD:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1692
				case GSF_SHIP:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1693
				case GSF_AIRCRAFT:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1694
				case GSF_STATION:
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1695
				{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1696
					byte sprites     = _cur_grffile->spriteset_numents;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1697
					byte num_loaded  = type;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1698
					byte num_loading = grf_load_byte(&buf);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1699
					uint i;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1700
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1701
					if (_cur_grffile->spriteset_start == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1702
						grfmsg(0, "NewSpriteGroup: No sprite set to work on! Skipping");
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1703
						return;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1704
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1705
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1706
					check_length(bufend - buf, 2 * num_loaded + 2 * num_loading, "NewSpriteGroup (Real) (1)");
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1707
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1708
					group = AllocateSpriteGroup();
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1709
					group->type = SGT_REAL;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1710
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1711
					group->g.real.num_loaded  = num_loaded;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1712
					group->g.real.num_loading = num_loading;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1713
					if (num_loaded  > 0) group->g.real.loaded  = calloc(num_loaded,  sizeof(*group->g.real.loaded));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1714
					if (num_loading > 0) group->g.real.loading = calloc(num_loading, sizeof(*group->g.real.loading));
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1715
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1716
					grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading",
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1717
							setid, sprites, num_loaded, num_loading);
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1718
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1719
					for (i = 0; i < num_loaded; i++) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1720
						uint16 spriteid = grf_load_word(&buf);
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1721
						group->g.real.loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1722
						grfmsg(8, "NewSpriteGroup: + rg->loaded[%i]  = subset %u", i, spriteid);
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1723
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1724
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1725
					for (i = 0; i < num_loading; i++) {
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1726
						uint16 spriteid = grf_load_word(&buf);
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1727
						group->g.real.loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1728
						grfmsg(8, "NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1729
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1730
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1731
					break;
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1732
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1733
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  1734
				/* Loading of Tile Layout and Production Callback groups would happen here */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1735
				default: grfmsg(1, "NewSpriteGroup: Unsupported feature %d, skipping", feature);
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1736
			}
2489
88827d8ae517 (svn r3015) -NewGRF: Add a new sprite group result type, and support loading of callbacks results within random and "real" groups. (Not fully supported yet.)
peter1138
parents: 2488
diff changeset
  1737
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
	}
2444
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1739
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1740
	_cur_grffile->spritegroups[setid] = group;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1743
/* Action 0x03 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1744
static void FeatureMapSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4381
diff changeset
  1747
	 * id-list    := [<id>] [id-list]
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4381
diff changeset
  1748
	 * cargo-list := <cargo-type> <cid> [cargo-list]
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
	 * B feature       see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	 * B n-id          bits 0-6: how many IDs this definition applies to
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	 *                 bit 7: if set, this is a wagon override definition (see below)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	 * B ids           the IDs for which this definition applies
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1754
	 * B num-cid       number of cargo IDs (sprite group IDs) in this definition
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	 *                 can be zero, in that case the def-cid is used always
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1757
	 * W cid           cargo ID (sprite group ID) for this type of cargo
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1758
	 * W def-cid       default cargo ID (sprite group ID) */
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1759
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
	/* TODO: Multiple cargo support could be useful even for trains/cars -
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
	 * cargo id 0xff is used for showing images in the build train list. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
	static int last_engines_count;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1765
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1766
	uint8 idcount;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1767
	bool wagover;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1768
	uint8 cidcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1769
	int c, i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1771
	check_length(len, 6, "FeatureMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1772
	feature = buf[1];
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1773
	idcount = buf[2] & 0x7F;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1774
	wagover = (buf[2] & 0x80) == 0x80;
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1775
	check_length(len, 3 + idcount, "FeatureMapSpriteGroup");
3783
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1776
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1777
	/* If ``n-id'' (or ``idcount'') is zero, this is a ``feature
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1778
	 * callback''. */
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1779
	if (idcount == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1780
		grfmsg(2, "FeatureMapSpriteGroup: Feature callbacks not implemented yet");
3783
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1781
		return;
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1782
	}
17a76f40e236 (svn r4777) - NewGRF: moving warning message about feature callbacks above station code and change minimum length for action 3 from 7 to 6 bytes.
peter1138
parents: 3777
diff changeset
  1783
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1784
	cidcount = buf[3 + idcount];
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1785
	check_length(len, 4 + idcount + cidcount * 3, "FeatureMapSpriteGroup");
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1786
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1787
	grfmsg(6, "FeatureMapSpriteGroup: Feature %d, %d ids, %d cids, wagon override %d",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1788
			feature, idcount, cidcount, wagover);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1789
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1790
	if (feature > GSF_STATION) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1791
		grfmsg(1, "FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1792
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1793
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1794
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1795
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1796
	if (feature == GSF_STATION) {
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1797
		// We do things differently for stations.
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1798
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1799
		for (i = 0; i < idcount; i++) {
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1800
			uint8 stid = buf[3 + i];
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1801
			StationSpec *statspec = _cur_grffile->stations[stid];
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1802
			byte *bp = &buf[4 + idcount];
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1803
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1804
			for (c = 0; c < cidcount; c++) {
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1805
				uint8 ctype = grf_load_byte(&bp);
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1806
				uint16 groupid = grf_load_word(&bp);
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1807
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1808
				if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1809
					grfmsg(1, "FeatureMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1810
					       groupid, _cur_grffile->spritegroups_count);
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1811
					return;
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1812
				}
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1813
3750
a8600490f8fc (svn r4738) - Newstations: attach all sprite group cargo types, not just the default and purchase pseudo types, to a station spec.
peter1138
parents: 3740
diff changeset
  1814
				if (ctype == 0xFE) ctype = GC_DEFAULT_NA;
a8600490f8fc (svn r4738) - Newstations: attach all sprite group cargo types, not just the default and purchase pseudo types, to a station spec.
peter1138
parents: 3740
diff changeset
  1815
				if (ctype == 0xFF) ctype = GC_PURCHASE;
a8600490f8fc (svn r4738) - Newstations: attach all sprite group cargo types, not just the default and purchase pseudo types, to a station spec.
peter1138
parents: 3740
diff changeset
  1816
5338
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1817
				if (ctype >= NUM_GLOBAL_CID) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1818
					grfmsg(1, "FeatureMapSpriteGroup: Cargo type %d out of range, skipping.", ctype);
5338
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1819
					continue;
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1820
				}
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1821
3750
a8600490f8fc (svn r4738) - Newstations: attach all sprite group cargo types, not just the default and purchase pseudo types, to a station spec.
peter1138
parents: 3740
diff changeset
  1822
				statspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid];
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1823
			}
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1824
		}
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1825
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1826
		{
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1827
			byte *bp = buf + 4 + idcount + cidcount * 3;
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1828
			uint16 groupid = grf_load_word(&bp);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1829
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1830
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1831
				grfmsg(1, "FeatureMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping",
397
fc532e982139 (svn r589) -newgrf: Rename spritesset to spritegroups (pasky).
darkvater
parents: 396
diff changeset
  1832
				       groupid, _cur_grffile->spritegroups_count);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1833
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1834
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1835
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1836
			for (i = 0; i < idcount; i++) {
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 401
diff changeset
  1837
				uint8 stid = buf[3 + i];
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1838
				StationSpec *statspec = _cur_grffile->stations[stid];
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1839
3750
a8600490f8fc (svn r4738) - Newstations: attach all sprite group cargo types, not just the default and purchase pseudo types, to a station spec.
peter1138
parents: 3740
diff changeset
  1840
				statspec->spritegroup[GC_DEFAULT] = _cur_grffile->spritegroups[groupid];
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1841
				statspec->grfid = _cur_grffile->grfid;
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1842
				statspec->localidx = stid;
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1843
				SetCustomStationSpec(statspec);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1844
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1845
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1846
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1847
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1848
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1849
	// FIXME: Tropicset contains things like:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1850
	// 03 00 01 19 01 00 00 00 00 - this is missing one 00 at the end,
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1851
	// what should we exactly do with that? --pasky
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1852
3635
59265706435c (svn r4540) - NewGRF: don't treat integer values as boolean.
peter1138
parents: 3634
diff changeset
  1853
	if (_cur_grffile->spriteset_start == 0 || _cur_grffile->spritegroups == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1854
		grfmsg(1, "FeatureMapSpriteGroup: No sprite set to work on! Skipping");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1855
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1856
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1857
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1858
	if (!wagover && last_engines_count != idcount) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1859
		last_engines = realloc(last_engines, idcount);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1860
		last_engines_count = idcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1861
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1862
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1863
	if (wagover) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1864
		if (last_engines_count == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1865
			grfmsg(0, "FeatureMapSpriteGroup: WagonOverride: No engine to do override with");
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1866
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1867
		}
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1868
		grfmsg(6, "FeatureMapSpriteGroup: WagonOverride: %u engines, %u wagons",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1869
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1870
	}
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  1871
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1872
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1873
	for (i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1874
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1875
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1876
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1877
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1878
		if (engine_id > _vehcounts[feature]) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1879
			grfmsg(0, "Id %u for feature 0x%02X is out of bounds", engine_id, feature);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1880
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1881
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1882
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1883
		grfmsg(7, "FeatureMapSpriteGroup: [%d] Engine %d...", i, engine);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1884
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1885
		for (c = 0; c < cidcount; c++) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1886
			uint8 ctype = grf_load_byte(&bp);
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1887
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1888
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1889
			grfmsg(8, "FeatureMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1890
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1891
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1892
				grfmsg(1, "FeatureMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1893
				return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1894
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1895
1802
448f187042d3 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1611
diff changeset
  1896
			if (ctype == GC_INVALID) ctype = GC_PURCHASE;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1897
5338
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1898
			if (ctype >= NUM_GLOBAL_CID) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1899
				grfmsg(1, "FeatureMapSpriteGroup: Cargo type %d out of range, skipping.", ctype);
5338
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1900
				continue;
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1901
			}
5b48218d8bd2 (svn r7503) -Codechange: [NewGRF] Add bounds checking for spriteset cargo types. (NewCargo support will change this rule a bit...)
peter1138
parents: 5334
diff changeset
  1902
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1903
			if (wagover) {
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  1904
				SetWagonOverrideSprites(engine, ctype, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1905
			} else {
2444
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1906
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1907
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1908
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1910
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1912
	{
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1913
		byte *bp = buf + 4 + idcount + cidcount * 3;
369
ab2266938fa8 (svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents: 368
diff changeset
  1914
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1916
		grfmsg(8, "-- Default group id 0x%04X", groupid);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1917
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
		for (i = 0; i < idcount; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1921
			// Don't tell me you don't love duplicated code!
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1922
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1923
				grfmsg(1, "FeatureMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping", groupid, _cur_grffile->spritegroups_count);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1924
				return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1927
			if (wagover) {
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1928
				/* If the ID for this action 3 is the same as the vehicle ID,
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1929
				 * this indicates we have a helicopter rotor override. */
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1930
				if (feature == GSF_AIRCRAFT && engine == last_engines[i]) {
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1931
					SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]);
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1932
				} else {
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1933
					// TODO: No multiple cargo types per vehicle yet. --pasky
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  1934
					SetWagonOverrideSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  1935
				}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1936
			} else {
2444
e618726432a4 (svn r2970) - Newgrf: Allocate spritegroups dynamically; this allows a cargo ID to reference the previous definition of the same cargo ID, instead of causing loops.
peter1138
parents: 2442
diff changeset
  1937
				SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]);
3924
de86db4fbd1e (svn r5059) - NewGRF: store a GRFFile pointer reference for each pointer, instead of just the GRF ID.
peter1138
parents: 3895
diff changeset
  1938
				SetEngineGRF(engine, _cur_grffile);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1939
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1945
/* Action 0x04 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1946
static void FeatureNewName(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
	 *
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1950
	 * B veh-type      see action 0 (as 00..07, + 0A
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1951
	 *                 But IF veh-type = 48, then generic text
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1952
	 * B language-id   If bit 6 is set, This is the extended language scheme,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1953
	                   with up to 64 language.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1954
	                   Otherwise, it is a mapping where set bits have meaning
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1955
	                   0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1956
	                   Bit 7 set means this is a generic text, not a vehicle one (or else)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
	 * B num-veh       number of vehicles which are getting a new name
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1958
	 * B/W offset      number of the first vehicle that gets a new name
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1959
	 *                 Byte : ID of vehicle to change
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1960
	 *                 Word : ID of string to change/add
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
	 * S data          new texts, each of them zero-terminated, after
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
	 *                 which the next name begins. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1963
	/* TODO: No support for changing non-vehicle text. Perhaps we shouldn't
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
	 * implement it at all, but it could be useful for some "modpacks"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
	 * (completely new scenarios changing all graphics and logically also
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
	 * factory names etc). We should then also support all languages (by
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1967
	 * name), not only the original four ones. --pasky
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1968
	 * All of the above are coming.  In Time.  Some sooner than others :)*/
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1970
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1971
	uint8 lang;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1972
	uint8 num;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1973
	uint16 id;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1974
	uint16 endid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  1975
	const char* name;
3643
5d1f3fe61036 (svn r4552) - NewGRF: fix braino... in r4550, new_scheme should true when the version is 7 or higher, not less than 7...
peter1138
parents: 3642
diff changeset
  1976
	bool new_scheme = _cur_grffile->grf_version >= 7;
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1977
	bool generic;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1979
	check_length(len, 6, "FeatureNewName");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1980
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1981
	feature  = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1982
	lang     = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1983
	num      = grf_load_byte(&buf);
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1984
	generic  = HASBIT(lang, 7);
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1985
	id       = generic ? grf_load_word(&buf) : grf_load_byte(&buf);
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1986
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1987
	CLRBIT(lang, 7);
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1988
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  1989
	if (feature <= GSF_AIRCRAFT && id < _vehcounts[feature]) {
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1990
		id += _vehshifts[feature];
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1991
	}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1992
	endid    = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1994
	grfmsg(6, "FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1995
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1996
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  1997
	name = (const char*)buf; /*transfer read value*/
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1998
	len -= generic ? 6 : 5;
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4964
diff changeset
  1999
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2000
	for (; id < endid && len > 0; id++) {
2458
c95808cd2ac9 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2456
diff changeset
  2001
		size_t ofs = strlen(name) + 1;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2002
4711
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4657
diff changeset
  2003
		if (ofs < 128) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2004
			grfmsg(8, "FeatureNewName: %d <- %s", id, name);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2005
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2006
			switch (feature) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2007
				case GSF_TRAIN:
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2008
				case GSF_ROAD:
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2009
				case GSF_SHIP:
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  2010
				case GSF_AIRCRAFT: {
3821
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2011
					if (id < TOTAL_NUM_ENGINES) {
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2012
						StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2013
						SetCustomEngineName(id, string);
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2014
					} else {
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2015
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2016
					}
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2017
					break;
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  2018
				}
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2019
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2020
				default:
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2021
					switch (GB(id, 8, 8)) {
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2022
						case 0xC4: /* Station class name */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  2023
							if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2024
								grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2025
							} else {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  2026
								StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
3821
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2027
								SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2028
							}
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2029
							break;
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2030
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2031
						case 0xC5: /* Station name */
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  2032
							if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2033
								grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2034
							} else {
3821
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3814
diff changeset
  2035
								_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
3760
10a6f762e754 (svn r4751) - NewGRF: when assigning new texts, ignore the feature byte as some sets use generic feature always. Also, don't add vehicle id shifts if the vehicle id is out of range.
peter1138
parents: 3750
diff changeset
  2036
							}
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2037
							break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2038
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  2039
						case 0xC9:
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  2040
						case 0xD0:
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  2041
						case 0xDC:
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  2042
							AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  2043
							break;
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  2044
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2045
						default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2046
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2047
							break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2048
					}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2049
					break;
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  2050
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  2051
#if 0
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2052
				case GSF_CANAL :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2053
				case GSF_BRIDGE :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2054
				case GSF_TOWNHOUSE :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2055
					AddGRFString(_cur_spriteid, id, lang, name);
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2056
					switch (GB(id, 8,8)) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2057
						case 0xC9: /* House name */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2058
						default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2059
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2060
					}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2061
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2062
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2063
				case GSF_INDUSTRIES :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2064
				case 0x48 :   /* for generic strings */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2065
					AddGRFString(_cur_spriteid, id, lang, name);
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2066
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2067
				default :
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2068
					grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2069
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2070
#endif
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2071
			}
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2072
		} else {
3863
62f1303f4bb4 (svn r4897) - NewGRF: don't allow addition of empty strings in action 4
peter1138
parents: 3862
diff changeset
  2073
			/* ofs is the string length + 1, so if the string is empty, ofs
62f1303f4bb4 (svn r4897) - NewGRF: don't allow addition of empty strings in action 4
peter1138
parents: 3862
diff changeset
  2074
			 * is 1 */
62f1303f4bb4 (svn r4897) - NewGRF: don't allow addition of empty strings in action 4
peter1138
parents: 3862
diff changeset
  2075
			if (ofs == 1) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2076
				grfmsg(7, "FeatureNewName: Can't add empty name");
3863
62f1303f4bb4 (svn r4897) - NewGRF: don't allow addition of empty strings in action 4
peter1138
parents: 3862
diff changeset
  2077
			} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2078
				grfmsg(7, "FeatureNewName: Too long a name (%d)", ofs);
3863
62f1303f4bb4 (svn r4897) - NewGRF: don't allow addition of empty strings in action 4
peter1138
parents: 3862
diff changeset
  2079
			}
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2080
		}
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2081
		name += ofs;
4321
b763b7007162 (svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents: 4297
diff changeset
  2082
		len -= (int)ofs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2083
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2086
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
	 * B graphics-type What set of graphics the sprites define.
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2092
	 * E num-sprites   How many sprites are in this set?
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2095
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2096
	uint8 type;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2097
	uint16 num;
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2098
	SpriteID replace = 0;
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2099
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2100
	check_length(len, 2, "GraphicsNew");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2101
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2102
	type = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2103
	num  = grf_load_extended(&buf);
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2104
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2105
	switch (type) {
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2106
		case 0x04: /* Signal graphics */
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2107
			if (num != 112 && num != 240) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2108
				grfmsg(1, "GraphicsNews: Signal graphics sprite count must be 112 or 240, skipping");
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2109
				return;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2110
			}
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2111
			_signal_base = _cur_spriteid;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2112
			break;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2113
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2114
		case 0x05: /* Catenary graphics */
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2115
			if (num != 48) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2116
				grfmsg(1, "GraphicsNews: Catenary graphics sprite count must be 48, skipping");
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2117
				return;
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2118
			}
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2119
			replace = SPR_ELRAIL_BASE + 3;
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2120
			break;
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2121
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2122
		case 0x06: /* Foundations */
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2123
			if (num != 74) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2124
				grfmsg(1, "GraphicsNews: Foundation graphics sprite count must be 74, skipping");
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2125
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2126
			}
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2127
			replace = SPR_SLOPES_BASE;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2128
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2129
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2130
		case 0x08: /* Canal graphics */
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2131
			if (num != 65) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2132
				grfmsg(1, "GraphicsNews: Canal graphics sprite count must be 65, skipping");
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2133
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2134
			}
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2135
			replace = SPR_CANALS_BASE + 5;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2136
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2137
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2138
		case 0x0D: /* Coast graphics */
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2139
			if (num != 16) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2140
				grfmsg(1, "GraphicsNews: Coast graphics sprite count must be 16, skipping");
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2141
				return;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2142
			}
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2143
			_coast_base = _cur_spriteid;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2144
			break;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2145
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2146
		default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2147
			grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)",
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2148
					type, num);
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2149
			return;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2150
	}
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2151
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2152
	if (replace == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2153
		grfmsg(2, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2154
	} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2155
		grfmsg(2, "GraphicsNew: Replacing %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, replace);
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2156
	}
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2157
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2158
	for (; num > 0; num--) {
3708
1c548218151c (svn r4651) - NewGRF: support loading of catenary sprites from NewGRF files. This actually works by replacing our hardcoded sprites.
peter1138
parents: 3707
diff changeset
  2159
		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index);
3638
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2160
		_nfo_line++;
6e0b43d905d4 (svn r4546) - NewGRF: add support for Action 0x05, type 0x04: replacement signal graphics. Thanks to Purno for supplying data to test
peter1138
parents: 3635
diff changeset
  2161
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2164
static uint32 GetParamVal(byte param, uint32 *cond_val)
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2165
{
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2166
	switch (param) {
5340
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2167
		case 0x81: /* current year */
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2168
			return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2169
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2170
		case 0x83: /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2171
			return _opt.landscape;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2172
5161
a064564a4a70 (svn r7266) -Codechange: Make the NewGRF loading stage look like ttdpatch to NewGRFs
peter1138
parents: 5115
diff changeset
  2173
		case 0x84: /* GRF loading stage */
a064564a4a70 (svn r7266) -Codechange: Make the NewGRF loading stage look like ttdpatch to NewGRFs
peter1138
parents: 5115
diff changeset
  2174
			return (_cur_stage > GLS_INIT) | ((_cur_stage == GLS_ACTIVATION) << 9);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2175
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2176
		case 0x85: /* TTDPatch flags, only for bit tests */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2177
			if (cond_val == NULL) {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2178
				/* Supported in Action 0x07 and 0x09, not 0x0D */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2179
				return 0;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2180
			} else {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2181
				uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2182
				*cond_val %= 0x20;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2183
				return param_val;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2184
			}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2185
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2186
		case 0x86: /* road traffic side, bit 4 clear=left, set=right */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2187
			return _opt.road_side << 4;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2188
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2189
		case 0x88: /* GRF ID check */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2190
			return 0;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2191
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2192
		case 0x8B: { /* TTDPatch version */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2193
			uint major    = 2;
4993
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  2194
			uint minor    = 6;
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  2195
			uint revision = 0; // special case: 2.0.1 is 2.0.10
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  2196
			uint build    = 1168;
7d84a318e3a4 (svn r6996) - Codechange: Pretend to be the current version of TTDPatch. This value doesn't anything to us as we don't follow TTDPatch's development timeline...
peter1138
parents: 4992
diff changeset
  2197
			return (major << 24) | (minor << 20) | (revision << 16) | build;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2198
		}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2199
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2200
		case 0x8D: /* TTD Version, 00=DOS, 01=Windows */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2201
			return !_use_dos_palette;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2202
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2203
		case 0x8E: /* Y-offset for train sprites */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2204
			return _traininfo_vehicle_pitch;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2205
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2206
		case 0x92: /* Game mode */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2207
			return _game_mode;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2208
5287
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  2209
		case 0x9A: /* Always -1 */
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  2210
			return -1;
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  2211
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2212
		case 0x9D: /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2213
			return 1;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2214
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2215
		case 0x9E: /* Miscellaneous GRF features */
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2216
			return _misc_grf_features;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2217
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2218
		default:
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2219
			/* GRF Parameter */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2220
			if (param < 0x80) return _cur_grffile->param[param];
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2221
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2222
			/* In-game variable. */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2223
			grfmsg(1, "Unsupported in-game variable 0x%02X", param);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2224
			return -1;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2225
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2226
}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2227
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2228
/* Action 0x06 */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2229
static void CfgApply(byte *buf, int len)
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2230
{
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2231
	/* <06> <param-num> <param-size> <offset> ... <FF>
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2232
	 *
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2233
	 * B param-num     Number of parameter to substitute (First = "zero")
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2234
	 *                 Ignored if that parameter was not specified in newgrf.cfg
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2235
	 * B param-size    How many bytes to replace.  If larger than 4, the
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2236
	 *                 bytes of the following parameter are used.  In that
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2237
	 *                 case, nothing is applied unless *all* parameters
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2238
	 *                 were specified.
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2239
	 * B offset        Offset into data from beginning of next sprite
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2240
	 *                 to place where parameter is to be stored. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2241
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2242
	/* Preload the next sprite */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2243
	uint32 pos = FioGetPos();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2244
	uint16 num = FioReadWord();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2245
	uint8 type = FioReadByte();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2246
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2247
	/* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2248
	if (type == 0xFF) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2249
		_preload_sprite = malloc(num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2250
		FioReadBlock(_preload_sprite, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2251
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2252
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2253
	/* Reset the file position to the start of the next sprite */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2254
	FioSeekTo(pos, SEEK_SET);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2255
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2256
	if (type != 0xFF) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2257
		grfmsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)");
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2258
		return;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2259
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2260
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2261
	/* Now perform the Action 0x06 on our data. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2262
	buf++;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2263
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2264
	for (;;) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2265
		uint i;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2266
		uint param_num;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2267
		uint param_size;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2268
		uint offset;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2269
		bool add_value;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2270
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2271
		/* Read the parameter to apply. 0xFF indicates no more data to change. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2272
		param_num = grf_load_byte(&buf);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2273
		if (param_num == 0xFF) break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2274
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2275
		/* Get the size of the parameter to use. If the size covers multiple
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2276
		 * double words, sequential parameter values are used. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2277
		param_size = grf_load_byte(&buf);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2278
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2279
		/* Bit 7 of param_size indicates we should add to the original value
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2280
		 * instead of replacing it. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2281
		add_value  = HASBIT(param_size, 7);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2282
		param_size = GB(param_size, 0, 7);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2283
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2284
		/* Where to apply the data to within the pseudo sprite data. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2285
		offset     = grf_load_extended(&buf);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2286
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2287
		/* If the parameter is a GRF parameter (not an internal variable) check
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2288
		 * if it (and all further sequential parameters) has been defined. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2289
		if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur_grffile->param_end) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2290
			grfmsg(2, "CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2291
			break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2292
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2293
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2294
		grfmsg(8, "CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2295
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2296
		for (i = 0; i < param_size; i++) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2297
			uint32 value = GetParamVal(param_num + i / 4, NULL);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2298
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2299
			if (add_value) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2300
				_preload_sprite[offset + i] += GB(value, (i % 4) * 8, 8);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2301
			} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2302
				_preload_sprite[offset + i] = GB(value, (i % 4) * 8, 8);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2303
			}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2304
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2305
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2306
}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2307
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2308
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2309
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2310
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2311
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2312
	/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2313
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2314
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2315
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2316
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2317
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2318
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2319
	/* TODO: More params. More condition types. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2320
	uint8 param;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2321
	uint8 paramsize;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2322
	uint8 condtype;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2323
	uint8 numsprites;
2336
48ace1344af0 (svn r2862) Return a proper version number, when testing the TTDPatch version in the SkipIf action. Pretend to be version 2.0.1 alpha 49 for now.
tron
parents: 2324
diff changeset
  2324
	uint32 param_val = 0;
48ace1344af0 (svn r2862) Return a proper version number, when testing the TTDPatch version in the SkipIf action. Pretend to be version 2.0.1 alpha 49 for now.
tron
parents: 2324
diff changeset
  2325
	uint32 cond_val = 0;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2326
	uint32 mask = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2327
	bool result;
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2328
	GRFLabel *label;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2329
	GRFLabel *choice = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2330
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2331
	check_length(len, 6, "SkipIf");
3714
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2332
	buf++;
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2333
	param     = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2334
	paramsize = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2335
	condtype  = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2336
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2337
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2338
		/* Always 1 for bit tests, the given value should be ignored. */
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2339
		paramsize = 1;
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2340
	}
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2341
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2342
	switch (paramsize) {
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2343
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2344
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2345
		case 1: cond_val = grf_load_byte(&buf);  mask = 0x000000FF; break;
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2346
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2347
	}
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2348
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2349
	if (param < 0x80 && _cur_grffile->param_end <= param) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2350
		grfmsg(7, "Param %d undefined, skipping test", param);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2351
		return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2352
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2353
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2354
	if (param == 0x88 && GetFileByGRFID(cond_val) == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2355
		grfmsg(7, "GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val));
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2356
		return;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2357
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2358
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2359
	param_val = GetParamVal(param, &cond_val);
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2360
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2361
	grfmsg(7, "Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2362
	switch (condtype) {
1606
4ec79f87951a (svn r2110) - Fix: Fixed test for various flags (e.g. newtrains in usset). result is bool so !! any non-zero values before assigning them to it - they apparently didn't fit. ;-)
pasky
parents: 1542
diff changeset
  2363
		case 0: result = !!(param_val & (1 << cond_val));
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2364
			break;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2365
		case 1: result = !(param_val & (1 << cond_val));
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2366
			break;
5306
8081baa646cd (svn r7462) -Fix: when doing comparison in action 7/9, mask the param value so it has the 'same' size as the value it is compared to
glx
parents: 5288
diff changeset
  2367
		case 2: result = (param_val & mask) == cond_val;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2368
			break;
5306
8081baa646cd (svn r7462) -Fix: when doing comparison in action 7/9, mask the param value so it has the 'same' size as the value it is compared to
glx
parents: 5288
diff changeset
  2369
		case 3: result = (param_val & mask) != cond_val;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2370
			break;
5306
8081baa646cd (svn r7462) -Fix: when doing comparison in action 7/9, mask the param value so it has the 'same' size as the value it is compared to
glx
parents: 5288
diff changeset
  2371
		case 4: result = (param_val & mask) < cond_val;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2372
			break;
5306
8081baa646cd (svn r7462) -Fix: when doing comparison in action 7/9, mask the param value so it has the 'same' size as the value it is compared to
glx
parents: 5288
diff changeset
  2373
		case 5: result = (param_val & mask) > cond_val;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2374
			break;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2375
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2376
		/* Tests 6 to 10 are only for param 0x88, GRFID checks */
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2377
		case 6: { /* Is GRFID active? */
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2378
			const GRFConfig *c = GetGRFConfig(cond_val);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2379
			if (c == NULL) return;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2380
			result = HASBIT(c->flags, GCF_ACTIVATED);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2381
			break;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2382
		}
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2383
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2384
		case 7: { /* Is GRFID non-active? */
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2385
			const GRFConfig *c = GetGRFConfig(cond_val);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2386
			if (c == NULL) return;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2387
			result = !HASBIT(c->flags, GCF_ACTIVATED);
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2388
			break;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2389
		}
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2390
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2391
		case 8: { /* GRFID is not but will be active? */
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2392
			const GRFConfig *c = GetGRFConfig(cond_val);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2393
			if (c == NULL) return;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2394
			result = !HASBIT(c->flags, GCF_ACTIVATED) && !HASBIT(c->flags, GCF_DISABLED);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2395
			break;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2396
		}
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2397
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2398
		case 9: { /* GRFID is or will be active? */
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2399
			const GRFConfig *c = GetGRFConfig(cond_val);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2400
			if (c == NULL) return;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2401
			result = !HASBIT(c->flags, GCF_NOT_FOUND) && !HASBIT(c->flags, GCF_DISABLED);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2402
			break;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2403
		}
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2404
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2405
		case 10: { /* GRFID is not nor will be active */
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2406
			const GRFConfig *c = GetGRFConfig(cond_val);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2407
			/* This is the only condtype that doesn't get ignored if the GRFID is not found */
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2408
			result = c == NULL || HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2409
			break;
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2410
		}
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2411
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2412
		default: grfmsg(1, "Unsupported test %d. Ignoring", condtype); return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2413
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2414
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  2415
	if (!result) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2416
		grfmsg(2, "Not skipping sprites, test was false");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2417
		return;
359
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2418
	}
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2419
f0ee94d705ed (svn r547) -newgrf: Enhanced support for action 0x7 and 0x9 (skips). Killer mixture mixed from octo's patch and pasky's old patch (pasky & octo).
darkvater
parents: 357
diff changeset
  2420
	numsprites = grf_load_byte(&buf);
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2421
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2422
	/* numsprites can be a GOTO label if it has been defined in the GRF
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2423
	 * file. The jump will always be the first matching label that follows
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2424
	 * the current nfo_line. If no matching label is found, the first matching
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2425
	 * label in the file is used. */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2426
	for (label = _cur_grffile->label; label != NULL; label = label->next) {
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2427
		if (label->label != numsprites) continue;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2428
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2429
		/* Remember a goto before the current line */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2430
		if (choice == NULL) choice = label;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2431
		/* If we find a label here, this is definitely good */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2432
		if (label->nfo_line > _nfo_line) {
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2433
			choice = label;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2434
			break;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2435
		}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2436
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2437
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2438
	if (choice != NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2439
		grfmsg(2, "Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line);
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2440
		FioSeekTo(choice->pos, SEEK_SET);
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2441
		_nfo_line = choice->nfo_line;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2442
		return;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2443
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2444
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2445
	grfmsg(2, "Skipping %d sprites, test was true", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2446
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2447
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2448
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2449
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2450
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2451
		_skip_sprites = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2452
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2453
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2454
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2455
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2456
/* Action 0x08 (GLS_SAFETYSCAN) */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2457
static void SafeInfo(byte *buf, int len)
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2458
{
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2459
	uint8 version;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2460
	uint32 grfid;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2461
	const char *name;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2462
	const char *info;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2463
	int name_len;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2464
	int info_len;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2465
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2466
	check_length(len, 8, "Info"); buf++;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2467
	version = grf_load_byte(&buf);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2468
	grfid = grf_load_dword(&buf);
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2469
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2470
	_cur_grfconfig->grfid = grfid;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2471
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2472
	/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2473
	if (GB(grfid, 24, 8) == 0xFF) SETBIT(_cur_grfconfig->flags, GCF_SYSTEM);
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2474
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2475
	len -= 6;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2476
	name = (const char*)buf;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2477
	name_len = ttd_strnlen(name, len);
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2478
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2479
	if (name_len < len) {
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2480
		_cur_grfconfig->name = TranslateTTDPatchCodes(name);
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2481
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2482
		len -= name_len + 1;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2483
		info = name + name_len + 1;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2484
		info_len = ttd_strnlen(info, len);
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2485
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2486
		if (info_len < len) {
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2487
			_cur_grfconfig->info  = TranslateTTDPatchCodes(info);
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2488
		}
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2489
	}
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2490
}
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2491
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2492
/* Action 0x08 (GLS_INFOSCAN) */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2493
static void ScanInfo(byte *buf, int len)
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2494
{
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2495
	SafeInfo(buf, len);
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2496
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  2497
	/* GLS_INFOSCAN only looks for the action 8, so we can skip the rest of the file */
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2498
	_skip_sprites = -1;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2499
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2500
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  2501
/* Action 0x08 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2502
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2503
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2504
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2505
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2506
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2507
	 * 4*B grf-id      globally unique ID of this .grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2508
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2509
	 * S info          string describing the set, and e.g. author and copyright */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2510
	/* TODO: Check version. (We should have own versioning done somehow.) */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2511
	uint8 version;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2512
	uint32 grfid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2513
	const char *name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2514
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
  2515
	check_length(len, 8, "GRFInfo"); buf++;
3712
b0e03bf96808 (svn r4655) - Fix [NewGRF r4654]: /me bangs head against the wall....gaah
Darkvater
parents: 3711
diff changeset
  2516
	version = grf_load_byte(&buf);
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
  2517
	grfid = grf_load_dword(&buf);
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
  2518
	name = (const char*)buf;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2519
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2520
	_cur_grffile->grfid = grfid;
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  2521
	_cur_grffile->grf_version = version;
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2522
	SETBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  2523
3711
4a0d1c635b56 (svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
Darkvater
parents: 3709
diff changeset
  2524
	/* Do swap the GRFID for displaying purposes since people expect that */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2525
	DEBUG(grf, 1, "Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2526
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2527
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  2528
/* Action 0x0A */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2529
static void SpriteReplace(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2530
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2531
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2532
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2533
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2534
	 * B num-sets      How many sets of sprites to replace.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2535
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2536
	 * B num-sprites   How many sprites are in this set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2537
	 * W first-sprite  First sprite number to replace */
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2538
	uint8 num_sets;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2539
	uint i;
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2540
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2541
	buf++; /* skip action byte */
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2542
	num_sets = grf_load_byte(&buf);
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2543
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2544
	for (i = 0; i < num_sets; i++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2545
		uint8 num_sprites = grf_load_byte(&buf);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2546
		uint16 first_sprite = grf_load_word(&buf);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2547
		uint j;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  2548
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2549
		grfmsg(2, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2550
			i, num_sprites, first_sprite
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2551
		);
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2552
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2553
		for (j = 0; j < num_sprites; j++) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2554
			LoadNextSprite(first_sprite + j, _file_index); // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  2555
			_nfo_line++;
361
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2556
		}
ad7a042ee0eb (svn r549) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 360
diff changeset
  2557
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2558
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2559
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  2560
/* Action 0x0B */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2561
static void GRFError(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2562
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2563
	/* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2564
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2565
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2566
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2567
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2568
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2569
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2570
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2571
	 * B language-id   see action 4, use 1F for built-in error messages
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2572
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2573
	 * S message       for custom messages (message-id FF), text of the message
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2574
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2575
	 * V data          additional data for built-in (or custom) messages
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2576
	 * B parnum        see action 6, only used with built-in message 03 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2577
	/* TODO: For now we just show the message, sometimes incomplete and never translated. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2578
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2579
	static const char *const msgstr[] = {
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2580
		"%sRequires at least pseudo-TTDPatch version %s",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2581
		"%sThis file is for %s version of TTD",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2582
		"%sDesigned to be used with %s",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2583
		"%sInvalid parameter %s",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2584
		"%sMust be loaded before %s",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2585
		"%sMust be loaded after %s",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2586
		"%s%s"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2587
	};
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2588
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2589
	static const char *const sevstr[] = {
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2590
		"",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2591
		"Warning: ",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2592
		"Error: ",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2593
		"Fatal: ",
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2594
	};
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2595
	uint8 sevid;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2596
	uint8 msgid;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2597
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2598
	check_length(len, 6, "GRFError");
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2599
	sevid = buf[1];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2600
	msgid = buf[3];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2601
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2602
	// Undocumented TTDPatch feature.
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2603
	if (!HASBIT(sevid, 7) && _cur_stage < GLS_ACTIVATION) {
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2604
		grfmsg(7, "Skipping non-fatal GRFError in stage 1");
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2605
		return;
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  2606
	}
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2607
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  2608
	sevid = GB(sevid, 0, 2);
5570
9ce93d899b1c (svn r7568) -Fix [r7564]: buf+4 is the same as &buf[4], not buf[4] for a char*.
Darkvater
parents: 5568
diff changeset
  2609
	grfmsg(0,  msgstr[(msgid == 0xFF) ? lengthof(msgstr) - 1 : msgid], sevstr[sevid], &buf[4]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2610
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2611
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  2612
/* Action 0x0C */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2613
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2614
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2615
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2616
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2617
	 * V ignored       Anything following the 0C is ignored */
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2618
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2619
	static char comment[256];
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2620
	if (len == 1) return;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2621
3571
441ad6b656f1 (svn r4453) - NewGRF: fix two compile warnings.
peter1138
parents: 3570
diff changeset
  2622
	ttd_strlcpy(comment, (char*)(buf + 1), minu(sizeof(comment), len));
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2623
	grfmsg(2, "GRFComment: %s", comment);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2624
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2625
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2626
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2627
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2628
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2629
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2630
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2631
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2632
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2633
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2634
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2635
	 * D data          data to use in the calculation, not necessary
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2636
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2637
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2638
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2639
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2640
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2641
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2642
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2644
	 * 05      Unsigned bit shift, source1 by source2 (source2 taken to be a
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2645
	 *         signed quantity; left shift if positive and right shift if
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2646
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2648
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2649
	 */
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2650
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2651
	byte target;
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2652
	byte oper;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2653
	uint32 src1;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2654
	uint32 src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2655
	uint32 data = 0;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2656
	uint32 res;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2657
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2658
	check_length(len, 5, "ParamSet");
418
67457dd7e5bc (svn r615) Fix the same bug in ParamSet action loading, pointer out by Bjarni too. (pasky)
bjarni
parents: 416
diff changeset
  2659
	buf++;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2660
	target = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2661
	oper = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2662
	src1 = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2663
	src2 = grf_load_byte(&buf);
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2664
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2665
	if (len >= 8) data = grf_load_dword(&buf);
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  2666
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2667
	/* You can add 80 to the operation to make it apply only if the target
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2668
	 * is not defined yet.  In this respect, a parameter is taken to be
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2669
	 * defined if any of the following applies:
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2670
	 * - it has been set to any value in the newgrf(w).cfg parameter list
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2671
	 * - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2672
	 *   an earlier action D */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2673
	if (oper & 0x80) {
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2674
		if (target < 0x80 && target < _cur_grffile->param_end) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2675
			grfmsg(7, "Param %u already defined, skipping", target);
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2676
			return;
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2677
		}
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2678
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2679
		oper &= 0x7F;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2680
	}
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2681
3808
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2682
	if (src2 == 0xFE) {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2683
		if (GB(data, 0, 8) == 0xFF) {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2684
			if (data == 0x0000FFFF) {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2685
				/* Patch variables */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2686
				grfmsg(2, "ParamSet: Reading Patch variables unsupported");
3808
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2687
				return;
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2688
			} else {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2689
				/* GRF Resource Management */
5225
52ddcedcc6f7 (svn r7345) -Codechange: enumification of NewGRF loading stage, and move enum definition to header for future use.
peter1138
parents: 5211
diff changeset
  2690
				if (_cur_stage != GLS_ACTIVATION) {
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2691
					/* Ignore GRM during initialization */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2692
					src1 = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2693
				} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2694
					uint8  op      = src1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2695
					uint8  feature = GB(data, 8, 8);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2696
					uint16 count   = GB(data, 16, 16);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2697
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2698
					switch (feature) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2699
						case 0x00: /* Trains */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2700
						case 0x01: /* Road Vehicles */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2701
						case 0x02: /* Ships */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2702
						case 0x03: /* Aircraft */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2703
						{
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2704
							uint start = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2705
							uint size  = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2706
							uint shift = _vehshifts[feature];
4964
0ef1eb7e7f35 (svn r6963) - Fix (r6960): signed/unsigned complaints from MSVC
peter1138
parents: 4961
diff changeset
  2707
							int i;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2708
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2709
							if (op == 6) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2710
								/* Return GRFID of set that reserved ID */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2711
								src1 = _grm_engines[shift + _cur_grffile->param[target]];
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2712
								break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2713
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2714
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2715
							/* With an operation of 2 or 3, we want to reserve a specific block of IDs */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2716
							if (op == 2 || op == 3) start = _cur_grffile->param[target];
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2717
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2718
							for (i = start; i < _vehcounts[feature]; i++) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2719
								if (_grm_engines[shift + i] == 0) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2720
									size++;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2721
								} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2722
									if (op == 2 || op == 3) break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2723
									start = i + 1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2724
									size = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2725
								}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2726
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2727
								if (size == count) break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2728
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2729
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2730
							if (size == count) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2731
								/* Got the slot... */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2732
								if (op == 0 || op == 3) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2733
									grfmsg(2, "GRM: Reserving %d vehicles at %d", count, start);
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2734
									for (i = 0; i < count; i++) _grm_engines[shift + start + i] = _cur_grffile->grfid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2735
								}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2736
								src1 = start;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2737
							} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2738
								/* Unable to allocate */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2739
								if (op != 4 && op != 5) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2740
									/* Deactivate GRF */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2741
									grfmsg(0, "GRM: Unable to allocate %d vehicles, deactivating", count);
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2742
									SETBIT(_cur_grfconfig->flags, GCF_DISABLED);
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  2743
									CLRBIT(_cur_grfconfig->flags, GCF_ACTIVATED);
5011
23f0b424a1be (svn r7031) -Codechange: Use _skip_sprites to skip the rest of the NewGRF when disabled by GRM, and add a shortcut so that the rest of the file isn't scanned.
peter1138
parents: 5008
diff changeset
  2744
23f0b424a1be (svn r7031) -Codechange: Use _skip_sprites to skip the rest of the NewGRF when disabled by GRM, and add a shortcut so that the rest of the file isn't scanned.
peter1138
parents: 5008
diff changeset
  2745
									_skip_sprites = -1;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2746
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2747
								}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2748
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2749
								grfmsg(1, "GRM: Unable to allocate %d vehicles", count);
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2750
								src1 = -1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2751
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2752
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2753
						}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2754
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2755
						case 0x08: /* General sprites */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2756
							switch (op) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2757
								case 0:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2758
									/* 'Reserve' space at the current sprite ID */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2759
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2760
									_cur_spriteid += count;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2761
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2762
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2763
								case 1:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2764
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2765
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2766
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2767
								default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2768
									grfmsg(1, "GRM: Unsupported operation %d for general sprites", op);
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2769
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2770
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2771
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2772
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2773
						default: grfmsg(1, "GRM: Unsupported feature 0x%X", feature); return;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2774
					}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2775
				}
3808
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2776
			}
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2777
		} else {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2778
			/* Read another GRF File's parameter */
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2779
			const GRFFile *file = GetFileByGRFID(data);
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2780
			if (file == NULL || src1 >= file->param_end) {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2781
				src1 = 0;
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2782
			} else {
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2783
				src1 = file->param[src1];
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2784
			}
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2785
		}
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2786
	} else {
3808
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2787
		/* The source1 and source2 operands refer to the grf parameter number
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2788
		 * like in action 6 and 7.  In addition, they can refer to the special
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2789
		 * variables available in action 7, or they can be FF to use the value
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2790
		 * of <data>.  If referring to parameters that are undefined, a value
332b9b202afb (svn r4818) - NewGRF: add support for reading another GRF file's parameters, and warn if GRF Resource Management is tried.
peter1138
parents: 3807
diff changeset
  2791
		 * of 0 is used instead.  */
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2792
		src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2793
		src2 = (src2 == 0xFF) ? data : GetParamVal(src2, NULL);
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2794
	}
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2795
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2796
	/* TODO: You can access the parameters of another GRF file by using
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2797
	 * source2=FE, source1=the other GRF's parameter number and data=GRF
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2798
	 * ID.  This is only valid with operation 00 (set).  If the GRF ID
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2799
	 * cannot be found, a value of 0 is used for the parameter value
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2800
	 * instead. */
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2801
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2802
	switch (oper) {
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2803
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2804
			res = src1;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2805
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2806
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2807
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2808
			res = src1 + src2;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2809
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2810
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2811
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2812
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2813
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2814
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2815
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2816
			res = src1 * src2;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2817
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2818
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2819
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2820
			res = (int32)src1 * (int32)src2;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2821
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2822
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2823
		case 0x05:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2824
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2825
				res = src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2826
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2827
				res = src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2828
			}
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2829
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2830
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2831
		case 0x06:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2832
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2833
				res = (int32)src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2834
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2835
				res = (int32)src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2836
			}
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2837
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2838
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2839
		case 0x07: /* Bitwise AND */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2840
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2841
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2842
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2843
		case 0x08: /* Bitwise OR */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2844
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2845
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2846
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2847
		case 0x09: /* Unsigned division */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2848
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2849
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2850
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2851
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2852
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2853
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2854
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2855
		case 0x0A: /* Signed divison */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2856
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2857
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2858
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2859
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2860
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2861
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2862
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2863
		case 0x0B: /* Unsigned modulo */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2864
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2865
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2866
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2867
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2868
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2869
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2870
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2871
		case 0x0C: /* Signed modulo */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2872
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2873
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2874
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2875
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2876
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2877
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2878
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2879
		default: grfmsg(0, "ParamSet: Unknown operation %d, skipping", oper); return;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2880
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2881
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2882
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2883
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2884
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2885
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2886
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2887
		// TODO implement
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2888
		case 0x8F: // Rail track type cost factors
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2889
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2890
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2891
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2892
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2893
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2894
		case 0x99: // Global ID offset
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2895
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2896
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2897
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2898
		case 0x9E: /* Miscellaneous GRF features */
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2899
			_misc_grf_features = res;
3845
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  2900
			/* Set train list engine width */
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  2901
			_traininfo_vehicle_width = HASBIT(res, 3) ? 32 : 29;
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2902
			break;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2903
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2904
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2905
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2906
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2907
				if (target + 1U > _cur_grffile->param_end) _cur_grffile->param_end = target + 1;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2908
			} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2909
				grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2910
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2911
			break;
362
bd9bc9c072ba (svn r550) -newgrf: Support for action 0xd (change a parameter (sorta variable for the GRF scripts)). Based on patch by octo, heavy changes by pasky.
darkvater
parents: 361
diff changeset
  2912
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2913
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2914
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  2915
/* Action 0x0E */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2916
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2917
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2918
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2919
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2920
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2921
	 * D grfids        GRFIDs of the files to deactivate */
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2922
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2923
	byte num;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2924
	int i;
398
20f8a2faf809 (svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).
darkvater
parents: 397
diff changeset
  2925
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2926
	check_length(len, 1, "GRFInhibit");
416
810c6de8eeed (svn r613) Fix bug in GRFInhibit action loading, pointed out by Bjarni. (pasky)
bjarni
parents: 413
diff changeset
  2927
	buf++, len--;
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2928
	num = grf_load_byte(&buf); len--;
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2929
	check_length(len, 4 * num, "GRFInhibit");
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2930
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2931
	for (i = 0; i < num; i++) {
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2932
		uint32 grfid = grf_load_dword(&buf);
5333
8e7d68b06399 (svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents: 5329
diff changeset
  2933
		GRFConfig *file = GetGRFConfig(grfid);
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2934
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2935
		/* Unset activation flag */
5557
dc2402eb851b (svn r7554) -Fix (r7496): In Action 0xE, don't deactivate the current GRF (to be ported to 0.5)
peter1138
parents: 5340
diff changeset
  2936
		if (file != NULL && file != _cur_grfconfig) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2937
			grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
5333
8e7d68b06399 (svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents: 5329
diff changeset
  2938
			SETBIT(file->flags, GCF_DISABLED);
8e7d68b06399 (svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents: 5329
diff changeset
  2939
			CLRBIT(file->flags, GCF_ACTIVATED);
367
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2940
		}
d0d895bd4972 (svn r555) -newgrf: Preliminary support for action 0xE. Inhibit another GRF file by ID. It won't really work until we get stages support (pasky & octo).
darkvater
parents: 366
diff changeset
  2941
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2942
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2943
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  2944
/* Action 0x10 */
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2945
static void DefineGotoLabel(byte *buf, int len)
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2946
{
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2947
	/* <10> <label> [<comment>]
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2948
	 *
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2949
	 * B label      The label to define
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2950
	 * V comment    Optional comment - ignored */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2951
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2952
	GRFLabel *label;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2953
3566
7bdf06a03960 (svn r4447) - NewGRF: It seems I committed printing action NOP Action 0x0C which is mainly used for comments. So leave it in, but fix the created warning. Use proper action name for check_length() in Action 0x10
Darkvater
parents: 3561
diff changeset
  2954
	check_length(len, 1, "DefineGotoLabel");
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2955
	buf++; len--;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2956
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2957
	label = malloc(sizeof(*label));
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2958
	label->label    = grf_load_byte(&buf);
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2959
	label->nfo_line = _nfo_line;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2960
	label->pos      = FioGetPos();
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2961
	label->next     = NULL;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2962
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2963
	/* Set up a linked list of goto targets which we will search in an Action 0x7/0x9 */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2964
	if (_cur_grffile->label == NULL) {
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2965
		_cur_grffile->label = label;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2966
	} else {
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2967
		/* Attach the label to the end of the list */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2968
		GRFLabel *l;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2969
		for (l = _cur_grffile->label; l->next != NULL; l = l->next);
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2970
		l->next = label;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2971
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2972
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2973
	grfmsg(2, "DefineGotoLabel: GOTO target with label 0x%02X", label->label);
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  2974
}
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  2975
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2976
/* Action 0x11 */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2977
static void GRFSound(byte *buf, int len)
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2978
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2979
	/* <11> <num>
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2980
	 *
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2981
	 * W num      Number of sound files that follow */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2982
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2983
	uint16 num;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2984
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2985
	check_length(len, 1, "GRFSound");
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2986
	buf++;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2987
	num = grf_load_word(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2988
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2989
	_grf_data_blocks = num;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2990
	_grf_data_type   = GDT_SOUND;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2991
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2992
	if (_cur_grffile->sound_offset == 0) _cur_grffile->sound_offset = GetNumSounds();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2993
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2994
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  2995
static void ImportGRFSound(byte *buf, int len)
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  2996
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  2997
	const GRFFile *file;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  2998
	FileEntry *se = AllocateFileEntry();
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  2999
	uint32 grfid = grf_load_dword(&buf);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3000
	uint16 sound = grf_load_word(&buf);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3001
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3002
	file = GetFileByGRFID(grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3003
	if (file == NULL || file->sound_offset == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3004
		grfmsg(1, "ImportGRFSound: Source file not available");
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3005
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3006
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3007
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3008
	if (file->sound_offset + sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3009
		grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3010
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3011
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3012
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3013
	grfmsg(2, "ImportGRFSound: Copying sound %d (%d) from file %X", sound, file->sound_offset + sound, grfid);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3014
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  3015
	*se = *GetSound(file->sound_offset + sound);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3016
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3017
	/* Reset volume and priority, which TTDPatch doesn't copy */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3018
	se->volume   = 128;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3019
	se->priority = 0;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3020
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3021
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3022
/* 'Action 0xFE' */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3023
static void GRFImportBlock(byte *buf, int len)
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3024
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3025
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3026
		grfmsg(2, "GRFImportBlock: Unexpected import block, skipping");
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3027
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3028
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3029
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3030
	buf++;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3031
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3032
	_grf_data_blocks--;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3033
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3034
	/* XXX 'Action 0xFE' isn't really specified. It is only mentioned for
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3035
	 * importing sounds, so this is probably all wrong... */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3036
	if (grf_load_byte(&buf) != _grf_data_type) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3037
		grfmsg(1, "GRFImportBlock: Import type mismatch");
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3038
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3039
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3040
	switch (_grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3041
		case GDT_SOUND: ImportGRFSound(buf, len - 1); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3042
		default: NOT_REACHED(); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3043
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3044
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3045
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3046
static void LoadGRFSound(byte *buf, int len)
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3047
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3048
	byte *buf_start = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3049
	FileEntry *se;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3050
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3051
	/* Allocate a sound entry. This is done even if the data is not loaded
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3052
	 * so that the indices used elsewhere are still correct. */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3053
	se = AllocateFileEntry();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3054
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  3055
	if (grf_load_dword(&buf) != BSWAP32('RIFF')) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3056
		grfmsg(1, "LoadGRFSound: Missing RIFF header");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3057
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3058
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3059
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3060
	/* Size of file -- we ignore this */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3061
	grf_load_dword(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3062
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  3063
	if (grf_load_dword(&buf) != BSWAP32('WAVE')) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3064
		grfmsg(1, "LoadGRFSound: Invalid RIFF type");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3065
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3066
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3067
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3068
	for (;;) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3069
		uint32 tag  = grf_load_dword(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3070
		uint32 size = grf_load_dword(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3071
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3072
		switch (tag) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3073
			case ' tmf': /* 'fmt ' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3074
				/* Audio format, must be 1 (PCM) */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3075
				if (grf_load_word(&buf) != 1) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3076
					grfmsg(1, "LoadGRFSound: Invalid audio format");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3077
					return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3078
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3079
				se->channels = grf_load_word(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3080
				se->rate = grf_load_dword(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3081
				grf_load_dword(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3082
				grf_load_word(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3083
				se->bits_per_sample = grf_load_word(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3084
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3085
				/* Consume any extra bytes */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3086
				for (; size > 16; size--) grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3087
				break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3088
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3089
			case 'atad': /* 'data' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3090
				se->file_size    = size;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3091
				se->file_offset  = FioGetPos() - (len - (buf - buf_start)) + 1;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3092
				se->file_offset |= _file_index << 24;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3093
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3094
				/* Set default volume and priority */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3095
				se->volume = 0x80;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3096
				se->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3097
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3098
				grfmsg(2, "LoadGRFSound: channels %u, sample rate %u, bits per sample %u, length %u", se->channels, se->rate, se->bits_per_sample, size);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3099
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3100
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3101
			default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3102
				se->file_size = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3103
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3104
		}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3105
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3106
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3107
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3108
/* Action 0x12 */
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3109
static void LoadFontGlyph(byte *buf, int len)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3110
{
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3111
	/* <12> <num_def> <font_size> <num_char> <base_char>
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3112
	 *
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3113
	 * B num_def      Number of definitions
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3114
	 * B font_size    Size of font (0 = normal, 1 = small, 2 = large)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3115
	 * B num_char     Number of consecutive glyphs
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3116
	 * W base_char    First character index */
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3117
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3118
	uint8 num_def;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3119
	uint i;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3120
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3121
	buf++; len--;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3122
	check_length(len, 1, "LoadFontGlyph");
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3123
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3124
	num_def = grf_load_byte(&buf);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3125
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3126
	check_length(len, 1 + num_def * 4, "LoadFontGlyph");
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3127
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3128
	for (i = 0; i < num_def; i++) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3129
		FontSize size    = grf_load_byte(&buf);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3130
		uint8  num_char  = grf_load_byte(&buf);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3131
		uint16 base_char = grf_load_word(&buf);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3132
		uint c;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3133
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3134
		grfmsg(7, "LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3135
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3136
		for (c = 0; c < num_char; c++) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3137
			SetUnicodeGlyph(size, base_char + c, _cur_spriteid);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3138
			LoadNextSprite(_cur_spriteid++, _file_index);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3139
			_nfo_line++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3140
		}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3141
	}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3142
}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  3143
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3144
/* 'Action 0xFF' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3145
static void GRFDataBlock(byte *buf, int len)
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3146
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3147
	byte name_len;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3148
	const char *name;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3149
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3150
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3151
		grfmsg(2, "GRFDataBlock: unexpected data block, skipping");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3152
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3153
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3154
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3155
	buf++;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3156
	name_len = grf_load_byte(&buf);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3157
	name = (const char *)buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3158
	buf += name_len + 1;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3159
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3160
	grfmsg(2, "GRFDataBlock: block name '%s'...", name);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3161
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3162
	_grf_data_blocks--;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3163
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3164
	switch (_grf_data_type) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3165
		case GDT_SOUND: LoadGRFSound(buf, len - name_len - 2); break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3166
		default: NOT_REACHED(); break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3167
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3168
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3169
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3170
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3171
/* Used during safety scan on unsafe actions */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3172
static void GRFUnsafe(byte *buf, int len)
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3173
{
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3174
	SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3175
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3176
	/* Skip remainder of GRF if GRF ID is set */
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3177
	if (_cur_grfconfig->grfid != 0) _skip_sprites = -1;
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3178
}
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3179
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3180
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  3181
static void InitializeGRFSpecial(void)
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  3182
{
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3183
	_ttdpatch_flags[0] =  ((_patches.always_small_airport ? 1 : 0) << 0x0C)  // keepsmallairport
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3184
	                   |                                        (1 << 0x0D)  // newairports
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3185
	                   |                                        (1 << 0x0E)  // largestations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3186
	                   |           ((_patches.longbridges ? 1 : 0) << 0x0F)  // longbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3187
	                   |                                        (0 << 0x10)  // loadtime
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3188
	                   |                                        (1 << 0x12)  // presignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3189
	                   |                                        (1 << 0x13)  // extpresignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3190
	                   | ((_patches.never_expire_vehicles ? 1 : 0) << 0x16)  // enginespersist
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3191
	                   |                                        (1 << 0x1B)  // multihead
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3192
	                   |                                        (1 << 0x1D)  // lowmemory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3193
	                   |                                        (1 << 0x1E); // generalfixes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3194
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3195
	_ttdpatch_flags[1] =                                        (0 << 0x07)  // moreairports - based on units of noise
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3196
	                   |        ((_patches.mammoth_trains ? 1 : 0) << 0x08)  // mammothtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3197
	                   |                                        (1 << 0x09)  // trainrefit
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3198
	                   |                                        (0 << 0x0B)  // subsidiaries
5211
651c9272ad22 (svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents: 5210
diff changeset
  3199
	                   |       ((_patches.gradual_loading ? 1 : 0) << 0x1C)  // gradualloading
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3200
	                   |                                        (1 << 0x12)  // unifiedmaglevmode - set bit 0 mode. Not revelant to OTTD
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3201
	                   |                                        (1 << 0x13)  // unifiedmaglevmode - set bit 1 mode
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3202
	                   |                                        (1 << 0x14)  // bridgespeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3203
	                   |                                        (1 << 0x16)  // eternalgame
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3204
	                   |                                        (1 << 0x17)  // newtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3205
	                   |                                        (1 << 0x18)  // newrvs
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3206
	                   |                                        (1 << 0x19)  // newships
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3207
	                   |                                        (1 << 0x1A)  // newplanes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3208
	                   |           ((_patches.signal_side ? 1 : 0) << 0x1B)  // signalsontrafficside
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3209
	                   |                                        (1 << 0x1C); // electrifiedrailway
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3210
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3211
	_ttdpatch_flags[2] =                                        (1 << 0x01)  // loadallgraphics - obsolote
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3212
	                   |                                        (1 << 0x03)  // semaphores
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3213
	                   |                                        (0 << 0x0B)  // enhancedgui
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3214
	                   |                                        (0 << 0x0C)  // newagerating
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3215
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x0D)  // buildonslopes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3216
	                   |                                        (0 << 0x0F)  // planespeed
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3217
	                   |                                        (0 << 0x10)  // moreindustriesperclimate - obsolete
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3218
	                   |                                        (0 << 0x11)  // moretoylandfeatures
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3219
	                   |                                        (1 << 0x12)  // newstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3220
	                   |                                        (0 << 0x13)  // tracktypecostdiff
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3221
	                   |                                        (0 << 0x14)  // manualconvert
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3222
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x15)  // buildoncoasts
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3223
	                   |                                        (1 << 0x16)  // canals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3224
	                   |                                        (1 << 0x17)  // newstartyear
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3225
	                   |                                        (0 << 0x18)  // freighttrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3226
	                   |                                        (0 << 0x19)  // newhouses
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3227
	                   |                                        (1 << 0x1A)  // newbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3228
	                   |                                        (0 << 0x1B)  // newtownnames
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3229
	                   |                                        (0 << 0x1C)  // moreanimations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3230
	                   |    ((_patches.wagon_speed_limits ? 1 : 0) << 0x1D)  // wagonspeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3231
	                   |                                        (1 << 0x1E)  // newshistory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3232
	                   |                                        (0 << 0x1F); // custombridgeheads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3233
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3234
	_ttdpatch_flags[3] =                                        (0 << 0x00)  // newcargodistribution
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3235
	                   |                                        (1 << 0x01)  // windowsnap
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3236
	                   |                                        (0 << 0x02)  // townbuildnoroad
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3237
	                   |                                        (0 << 0x03)  // pathbasedsignalling. To enable if ever pbs is back
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3238
	                   |                                        (0 << 0x04)  // aichoosechance
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3239
	                   |                                        (1 << 0x05)  // resolutionwidth
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3240
	                   |                                        (1 << 0x06)  // resolutionheight
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3241
	                   |                                        (0 << 0x07)  // newindustries
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3242
	                   |                                        (0 << 0x08)  // fifoloading
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3243
	                   |                                        (0 << 0x09)  // townroadbranchprob
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3244
	                   |                                        (0 << 0x0A)  // tempsnowline
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3245
	                   |                                        (0 << 0x0B)  // newcargo
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3246
	                   |                                        (1 << 0x0C)  // enhancemultiplayer
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3247
	                   |                                        (1 << 0x0D)  // onewayroads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3248
	                   |   ((_patches.nonuniform_stations ? 1 : 0) << 0x0E)  // irregularstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3249
	                   |                                        (1 << 0x0F)  // statistics
4657
188335e8d316 (svn r6533) - Fix (r6532): Somebody forgot to add newsounds to the ttdpatch flags...
peter1138
parents: 4656
diff changeset
  3250
	                   |                                        (1 << 0x10)  // newsounds
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3251
	                   |                                        (1 << 0x11)  // autoreplace
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3252
	                   |                                        (1 << 0x12)  // autoslope
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3253
	                   |                                        (0 << 0x13)  // followvehicle
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3254
	                   |                                        (0 << 0x14)  // trams
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3255
	                   |                                        (0 << 0x15)  // enhancetunnels
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3256
	                   |                                        (0 << 0x16)  // shortrvs
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3257
	                   |                                        (0 << 0x17); // articulatedrvs
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  3258
}
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  3259
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3260
static void ResetCustomStations(void)
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3261
{
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3262
	StationSpec *statspec;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3263
	GRFFile *file;
2627
8c964f74bd7b (svn r3169) Little bit of coding style fixing, and change from value to lengthof()
peter1138
parents: 2625
diff changeset
  3264
	uint i;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3265
	uint t;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3266
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3267
	for (file = _first_grffile; file != NULL; file = file->next) {
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3268
		if (file->stations == NULL) continue;
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3269
		for (i = 0; i < MAX_STATIONS; i++) {
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3270
			if (file->stations[i] == NULL) continue;
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3271
			statspec = file->stations[i];
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3272
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3273
			/* Release renderdata, if it wasn't copied from another custom station spec  */
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3274
			if (!statspec->copied_renderdata) {
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3275
				for (t = 0; t < statspec->tiles; t++) {
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3276
					free((void*)statspec->renderdata[t].seq);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3277
				}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3278
				free(statspec->renderdata);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3279
			}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3280
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3281
			/* Release platforms and layouts */
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3282
			if (!statspec->copied_layouts) {
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3283
				uint l, p;
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3284
				for (l = 0; l < statspec->lengths; l++) {
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3285
					for (p = 0; p < statspec->platforms[l]; p++) {
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3286
						free(statspec->layouts[l][p]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3287
					}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3288
					free(statspec->layouts[l]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3289
				}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3290
				free(statspec->layouts);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3291
				free(statspec->platforms);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3292
			}
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3293
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3294
			/* Release this station */
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  3295
			free(statspec);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3296
		}
3501
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
  3297
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
  3298
		/* Free and reset the station data */
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
  3299
		free(file->stations);
cf7d2c33e7fc (svn r4352) - NewGRF Codechange: dynamically allocate the memory used to store custom station data. This saves us approximately 40KB per GRF file, if there are no stations defined.
peter1138
parents: 3488
diff changeset
  3300
		file->stations = NULL;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3301
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3302
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3303
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3304
static void ResetNewGRF(void)
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3305
{
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3306
	GRFFile *f, *next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3307
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3308
	for (f = _first_grffile; f != NULL; f = next) {
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3309
		next = f->next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3310
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3311
		free(f->filename);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3312
		free(f);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3313
	}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3314
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3315
	_first_grffile = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3316
	_cur_grffile   = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3317
}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3318
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3319
/**
2463
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3320
 * Reset all NewGRF loaded data
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3321
 * TODO
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3322
 */
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3323
static void ResetNewGRFData(void)
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3324
{
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3325
	uint i;
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3326
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3327
	CleanUpStrings();
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3328
2463
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3329
	// Copy/reset original engine info data
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3330
	memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3331
	memcpy(&_rail_vehicle_info, &orig_rail_vehicle_info, sizeof(orig_rail_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3332
	memcpy(&_ship_vehicle_info, &orig_ship_vehicle_info, sizeof(orig_ship_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3333
	memcpy(&_aircraft_vehicle_info, &orig_aircraft_vehicle_info, sizeof(orig_aircraft_vehicle_info));
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3334
	memcpy(&_road_vehicle_info, &orig_road_vehicle_info, sizeof(orig_road_vehicle_info));
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3335
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3336
	// Copy/reset original bridge info data
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3337
	// First, free sprite table data
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3338
	for (i = 0; i < MAX_BRIDGES; i++) {
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3339
		if (_bridge[i].sprite_table != NULL) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3340
			uint j;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3341
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3342
			for (j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]);
2478
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3343
			free(_bridge[i].sprite_table);
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3344
		}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3345
	}
16b05f1de6bb (svn r3004) -Feature, NewGRF: Support loading of bridge attributes and tables from GRF. Currently drawing tall pillars uses old data.
peter1138
parents: 2476
diff changeset
  3346
	memcpy(&_bridge, &orig_bridge, sizeof(_bridge));
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3347
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3348
	// Reset refit/cargo class data
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3349
	memset(&cargo_allowed, 0, sizeof(cargo_allowed));
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3350
	memset(&cargo_disallowed, 0, sizeof(cargo_disallowed));
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3351
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3352
	// Reset GRM reservations
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3353
	memset(&_grm_engines, 0, sizeof(_grm_engines));
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3354
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3355
	// Unload sprite group data
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3356
	UnloadWagonOverrides();
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  3357
	UnloadRotorOverrideSprites();
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3358
	UnloadCustomEngineSprites();
2769
acea0abd2195 (svn r3316) - NewGRF: Unload engine names before loading grf files. This fixes names in climates where the engines don't get loaded. Renamed function to reflect its purpose.
peter1138
parents: 2766
diff changeset
  3359
	UnloadCustomEngineNames();
2971
9b62397dbd56 (svn r3546) - NewGRF feature: Implement rail vehicle 'property' 0x1A: allows shuffling order of rail vehicle purchase list (and replace vehicle list)
peter1138
parents: 2962
diff changeset
  3360
	ResetEngineListOrder();
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  3361
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  3362
	// Reset price base data
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  3363
	ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3364
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  3365
	/* Reset the curencies array */
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  3366
	ResetCurrencies();
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  3367
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3368
	// Reset station classes
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3369
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3370
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  3371
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3372
	/* Reset NewGRF files */
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3373
	ResetNewGRF();
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3374
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  3375
	// Add engine type to engine data. This is needed for the refit precalculation.
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  3376
	AddTypeToEngines();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3377
3845
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  3378
	/* Reset misc GRF features and train list display variables */
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  3379
	_misc_grf_features = 0;
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  3380
	_traininfo_vehicle_pitch = 0;
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  3381
	_traininfo_vehicle_width = 29;
4742
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
  3382
	_have_2cc = false;
5209
fa3ad39e2fa7 (svn r7324) -Codechange: reset newgrf signal location data
peter1138
parents: 5161
diff changeset
  3383
	_signal_base = 0;
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  3384
	_coast_base = 0;
3845
c3cd4b825c2f (svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents: 3825
diff changeset
  3385
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3386
	InitializeSoundPool();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3387
	InitializeSpriteGroupPool();
2463
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3388
}
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3389
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3390
/** Reset all NewGRFData that was used only while processing data */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3391
static void ClearTemporaryNewGRFData(void)
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3392
{
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3393
	/* Clear the GOTO labels used for GRF processing */
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3394
	GRFLabel *l;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3395
	for (l = _cur_grffile->label; l != NULL;) {
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3396
		GRFLabel *l2 = l->next;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3397
		free(l);
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3398
		l = l2;
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3399
	}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3400
	_cur_grffile->label = NULL;
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3401
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3402
	/* Clear the list of spritegroups */
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3403
	free(_cur_grffile->spritegroups);
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3404
	_cur_grffile->spritegroups = NULL;
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3405
	_cur_grffile->spritegroups_count = 0;
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3406
}
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3407
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3408
static void InitNewGRFFile(const GRFConfig *config, int sprite_offset)
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3409
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  3410
	GRFFile *newfile;
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3411
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3412
	newfile = GetFileByFilename(config->filename);
490
83455cd1cc55 (svn r772) Whoops, I know. Do not consider pointer to be a boolean value. Sorry 'bout that, sirs.
pasky
parents: 489
diff changeset
  3413
	if (newfile != NULL) {
489
9c8e1806935e (svn r771) Do not give a file new {struct GRFFile} if it was already loaded once. Eliminates those double entries in the newgrf manager and also some possible memory leaks.
pasky
parents: 478
diff changeset
  3414
		/* We already loaded it once. */
9c8e1806935e (svn r771) Do not give a file new {struct GRFFile} if it was already loaded once. Eliminates those double entries in the newgrf manager and also some possible memory leaks.
pasky
parents: 478
diff changeset
  3415
		newfile->sprite_offset = sprite_offset;
9c8e1806935e (svn r771) Do not give a file new {struct GRFFile} if it was already loaded once. Eliminates those double entries in the newgrf manager and also some possible memory leaks.
pasky
parents: 478
diff changeset
  3416
		_cur_grffile = newfile;
9c8e1806935e (svn r771) Do not give a file new {struct GRFFile} if it was already loaded once. Eliminates those double entries in the newgrf manager and also some possible memory leaks.
pasky
parents: 478
diff changeset
  3417
		return;
9c8e1806935e (svn r771) Do not give a file new {struct GRFFile} if it was already loaded once. Eliminates those double entries in the newgrf manager and also some possible memory leaks.
pasky
parents: 478
diff changeset
  3418
	}
9c8e1806935e (svn r771) Do not give a file new {struct GRFFile} if it was already loaded once. Eliminates those double entries in the newgrf manager and also some possible memory leaks.
pasky
parents: 478
diff changeset
  3419
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  3420
	newfile = calloc(1, sizeof(*newfile));
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3421
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3422
	if (newfile == NULL) error ("Out of memory");
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3423
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3424
	newfile->filename = strdup(config->filename);
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3425
	newfile->sprite_offset = sprite_offset;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3426
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3427
	/* Copy the initial parameter list */
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3428
	assert(lengthof(newfile->param) == lengthof(config->param) && lengthof(config->param) == 0x80);
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3429
	newfile->param_end = config->num_params;
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3430
	memcpy(newfile->param, config->param, 0x80 * sizeof(newfile->param[0]));
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3431
366
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3432
	if (_first_grffile == NULL) {
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3433
		_cur_grffile = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3434
		_first_grffile = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3435
	} else {
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3436
		_cur_grffile->next = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3437
		_cur_grffile = newfile;
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3438
	}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3439
}
9d2630b8b4de (svn r554) -newgrf: Keep track of GRF files. Remember them all in a linked list, this already enables tests for an already loaded GRF file in SkipIf(). Patch by octo, heavily re-hammered by pasky
darkvater
parents: 363
diff changeset
  3440
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3441
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3442
/** Bitmasked values of what type of cargo is refittable for the given vehicle-type.
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3443
 * This coupled with the landscape information (_landscape_global_cargo_mask) gives
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3444
 * us exactly what is refittable and what is not */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3445
#define MC(cargo) (1 << cargo)
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3446
static const uint32 _default_refitmasks[NUM_VEHICLE_TYPES] = {
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3447
	/* Trains */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3448
	MC(GC_PASSENGERS) | MC(GC_COAL)      | MC(GC_MAIL)   | MC(GC_LIVESTOCK) | MC(GC_GOODS)        | MC(GC_GRAIN)      | MC(GC_WOOD)    | MC(GC_IRON_ORE)    |
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3449
	MC(GC_STEEL)      | MC(GC_VALUABLES) | MC(GC_PAPER)  | MC(GC_FOOD)      | MC(GC_FRUIT)        | MC(GC_COPPER_ORE) | MC(GC_WATER)   | MC(GC_SUGAR)       |
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3450
	MC(GC_TOYS)       | MC(GC_CANDY)     | MC(GC_TOFFEE) | MC(GC_COLA)      | MC(GC_COTTON_CANDY) | MC(GC_BUBBLES)    | MC(GC_PLASTIC) | MC(GC_FIZZY_DRINKS),
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3451
	/* Road vehicles (not refittable by default) */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3452
	0,
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3453
	/* Ships */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3454
	MC(GC_COAL)  | MC(GC_MAIL)   | MC(GC_LIVESTOCK) | MC(GC_GOODS)        | MC(GC_GRAIN)   | MC(GC_WOOD)    | MC(GC_IRON_ORE) | MC(GC_STEEL) | MC(GC_VALUABLES) |
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3455
	MC(GC_PAPER) | MC(GC_FOOD)   | MC(GC_FRUIT)     | MC(GC_COPPER_ORE)   | MC(GC_WATER)   | MC(GC_RUBBER)  | MC(GC_SUGAR)    | MC(GC_TOYS)  | MC(GC_BATTERIES) |
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3456
	MC(GC_CANDY) | MC(GC_TOFFEE) | MC(GC_COLA)      | MC(GC_COTTON_CANDY) | MC(GC_BUBBLES) | MC(GC_PLASTIC) | MC(GC_FIZZY_DRINKS),
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3457
	/* Aircraft */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3458
	MC(GC_PASSENGERS) | MC(GC_MAIL)  | MC(GC_GOODS)  | MC(GC_VALUABLES) | MC(GC_FOOD)         | MC(GC_FRUIT)   | MC(GC_SUGAR)   | MC(GC_TOYS) |
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3459
	MC(GC_BATTERIES)  | MC(GC_CANDY) | MC(GC_TOFFEE) | MC(GC_COLA)      | MC(GC_COTTON_CANDY) | MC(GC_BUBBLES) | MC(GC_PLASTIC) | MC(GC_FIZZY_DRINKS),
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3460
	/* Special/Disaster */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3461
	0,0
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3462
};
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3463
#undef MC
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3464
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3465
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3466
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3467
 * Precalculate refit masks from cargo classes for all vehicles.
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3468
 */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3469
static void CalculateRefitMasks(void)
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3470
{
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3471
	EngineID engine;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3472
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3473
	for (engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3474
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3475
		uint32 not_mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3476
		uint32 xor_mask = _engine_info[engine].refit_mask;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3477
		byte i;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3478
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3479
		if (cargo_allowed[engine] != 0) {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3480
			// Build up the list of cargo types from the set cargo classes.
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3481
			for (i = 0; i < lengthof(cargo_classes); i++) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3482
				if (HASBIT(cargo_allowed[engine], i)) mask |= cargo_classes[i];
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3483
				if (HASBIT(cargo_disallowed[engine], i)) not_mask |= cargo_classes[i];
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3484
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3485
		} else {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3486
			// Don't apply default refit mask to wagons or engines with no capacity
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3487
			if (xor_mask == 0 && (
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3488
						GetEngine(engine)->type != VEH_Train || (
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3489
							RailVehInfo(engine)->capacity != 0 &&
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3490
							!(RailVehInfo(engine)->flags & RVI_WAGON)
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3491
						)
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3492
					)) {
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3493
				xor_mask = _default_refitmasks[GetEngine(engine)->type - VEH_Train];
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3494
			}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3495
		}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3496
		_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _landscape_global_cargo_mask[_opt.landscape];
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3497
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3498
}
363
cf3cee5f33b4 (svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
darkvater
parents: 362
diff changeset
  3499
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3500
/* Here we perform initial decoding of some special sprites (as are they
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3501
 * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3502
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3503
/* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3504
 * a crafted invalid GRF file. We should tell that to the user somehow, or
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3505
 * better make this more robust in the future. */
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3506
static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3507
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3508
	/* XXX: There is a difference between staged loading in TTDPatch and
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3509
	 * here.  In TTDPatch, for some reason actions 1 and 2 are carried out
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3510
	 * during stage 1, whilst action 3 is carried out during stage 2 (to
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3511
	 * "resolve" cargo IDs... wtf). This is a little problem, because cargo
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3512
	 * IDs are valid only within a given set (action 1) block, and may be
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3513
	 * overwritten after action 3 associates them. But overwriting happens
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3514
	 * in an earlier stage than associating, so...  We just process actions
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3515
	 * 1 and 2 in stage 2 now, let's hope that won't get us into problems.
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3516
	 * --pasky */
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3517
	/* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3518
	 * is not in memory and scanning the file every time would be too expensive.
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  3519
	 * In other stages we skip action 0x10 since it's already dealt with. */
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3520
	static const SpecialSpriteHandler handlers[][GLS_END] = {
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3521
		/* 0x00 */ { NULL,     GRFUnsafe, NULL,            NULL,       FeatureChangeInfo, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3522
		/* 0x01 */ { NULL,     GRFUnsafe, NULL,            NULL,       NewSpriteSet, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3523
		/* 0x02 */ { NULL,     GRFUnsafe, NULL,            NULL,       NewSpriteGroup, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3524
		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,       FeatureMapSpriteGroup, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3525
		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,       FeatureNewName, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3526
		/* 0x05 */ { NULL,     NULL,      NULL,            NULL,       GraphicsNew, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3527
		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,   CfgApply, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3528
		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,       SkipIf, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3529
		/* 0x08 */ { ScanInfo, SafeInfo,  NULL,            GRFInfo,    GRFInfo, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3530
		/* 0x09 */ { NULL,     NULL,      NULL,            SkipIf,     SkipIf, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3531
		/* 0x0A */ { NULL,     NULL,      NULL,            NULL,       SpriteReplace, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3532
		/* 0x0B */ { NULL,     NULL,      NULL,            GRFError,   GRFError, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3533
		/* 0x0C */ { NULL,     NULL,      NULL,            GRFComment, GRFComment, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3534
		/* 0x0D */ { NULL,     GRFUnsafe, NULL,            ParamSet,   ParamSet, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3535
		/* 0x0E */ { NULL,     GRFUnsafe, NULL,            GRFInhibit, GRFInhibit, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3536
		/* 0x0F */ { NULL,     NULL,      NULL,            NULL,       NULL, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3537
		/* 0x10 */ { NULL,     NULL,      DefineGotoLabel, NULL,       NULL, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3538
		/* 0x11 */ { NULL,     GRFUnsafe, NULL,            NULL,       GRFSound, },
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3539
		/* 0x12 */ { NULL,     NULL,      NULL,            NULL,       LoadFontGlyph, },
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3540
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3541
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3542
	byte* buf;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3543
	byte action;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3544
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3545
	if (_preload_sprite == NULL) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3546
		/* No preloaded sprite to work with; allocate and read the
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3547
		 * pseudo sprite content. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3548
		buf = malloc(num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3549
		if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3550
		FioReadBlock(buf, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3551
	} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3552
		/* Use the preloaded sprite data. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3553
		buf = _preload_sprite;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3554
		_preload_sprite = NULL;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3555
		grfmsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data");
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3556
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3557
		/* Skip the real (original) content of this action. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3558
		FioSeekTo(num, SEEK_CUR);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3559
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3560
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3561
	action = buf[0];
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3562
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3563
	if (action == 0xFF) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3564
		grfmsg(7, "Handling data block in stage %d", stage);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3565
		GRFDataBlock(buf, num);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3566
	} else if (action == 0xFE) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3567
		grfmsg(7, "Handling import block in stage %d", stage);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3568
		GRFImportBlock(buf, num);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3569
	} else if (action >= lengthof(handlers)) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3570
		grfmsg(7, "Skipping unknown action 0x%02X", action);
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3571
	} else if (handlers[action][stage] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3572
		grfmsg(7, "Skipping action 0x%02X in stage %d", action, stage);
2645
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  3573
	} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3574
		grfmsg(7, "Handling action 0x%02X in stage %d", action, stage);
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3575
		handlers[action][stage](buf, num);
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3576
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3577
	free(buf);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3578
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3579
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3580
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3581
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3582
{
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3583
	const char *filename = config->filename;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3584
	uint16 num;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3585
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3586
	/* A .grf file is activated only if it was active when the game was
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3587
	 * started.  If a game is loaded, only its active .grfs will be
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3588
	 * reactivated, unless "loadallgraphics on" is used.  A .grf file is
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3589
	 * considered active if its action 8 has been processed, i.e. its
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3590
	 * action 8 hasn't been skipped using an action 7.
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3591
	 *
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3592
	 * During activation, only actions 0, 1, 2, 3, 4, 5, 7, 8, 9, 0A and 0B are
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3593
	 * carried out.  All others are ignored, because they only need to be
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3594
	 * processed once at initialization.  */
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5324
diff changeset
  3595
	if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3596
		_cur_grffile = GetFileByFilename(filename);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3597
		if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename);
5234
91b7def5e4b2 (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5228
diff changeset
  3598
		if (stage == GLS_ACTIVATION && !HASBIT(config->flags, GCF_ACTIVATED)) return;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3599
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3600
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3601
	FioOpenFile(file_index, filename);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3602
	_file_index = file_index; // XXX
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3603
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3604
	_cur_grfconfig = config;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3605
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3606
	DEBUG(grf, 2, "Reading NewGRF-file '%s'", filename);
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3607
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3608
	/* Skip the first sprite; we don't care about how many sprites this
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3609
	 * does contain; newest TTDPatches and George's longvehicles don't
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3610
	 * neither, apparently. */
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3611
	if (FioReadWord() == 4 && FioReadByte() == 0xFF) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3612
		FioReadDword();
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3613
	} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3614
		DEBUG(grf, 7, "Custom .grf has invalid format");
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3615
		return;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3616
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3617
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3618
	_skip_sprites = 0; // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  3619
	_nfo_line = 0;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3620
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3621
	while ((num = FioReadWord()) != 0) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3622
		byte type = FioReadByte();
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  3623
		_nfo_line++;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3624
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3625
		if (type == 0xFF) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3626
			if (_skip_sprites == 0) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2935
diff changeset
  3627
				DecodeSpecialSprite(num, stage);
5011
23f0b424a1be (svn r7031) -Codechange: Use _skip_sprites to skip the rest of the NewGRF when disabled by GRM, and add a shortcut so that the rest of the file isn't scanned.
peter1138
parents: 5008
diff changeset
  3628
23f0b424a1be (svn r7031) -Codechange: Use _skip_sprites to skip the rest of the NewGRF when disabled by GRM, and add a shortcut so that the rest of the file isn't scanned.
peter1138
parents: 5008
diff changeset
  3629
				/* Stop all processing if we are to skip the remaining sprites */
23f0b424a1be (svn r7031) -Codechange: Use _skip_sprites to skip the rest of the NewGRF when disabled by GRM, and add a shortcut so that the rest of the file isn't scanned.
peter1138
parents: 5008
diff changeset
  3630
				if (_skip_sprites == -1) break;
23f0b424a1be (svn r7031) -Codechange: Use _skip_sprites to skip the rest of the NewGRF when disabled by GRM, and add a shortcut so that the rest of the file isn't scanned.
peter1138
parents: 5008
diff changeset
  3631
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3632
				continue;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3633
			} else {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3634
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3635
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3636
		} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3637
			if (_skip_sprites == 0) grfmsg(7, "Skipping unexpected sprite");
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3638
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3639
			FioSkipBytes(7);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3640
			num -= 8;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3641
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3642
			if (type & 2) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3643
				FioSkipBytes(num);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3644
			} else {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3645
				while (num > 0) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3646
					int8 i = FioReadByte();
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3647
					if (i >= 0) {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3648
						num -= i;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3649
						FioSkipBytes(i);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3650
					} else {
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3651
						i = -(i >> 3);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3652
						num -= i;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3653
						FioReadByte();
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3654
					}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3655
				}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3656
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3657
		}
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3658
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3659
		if (_skip_sprites > 0) _skip_sprites--;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3660
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3661
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3662
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3663
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3664
void LoadNewGRF(uint load_index, uint file_index)
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3665
{
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3666
	GrfLoadingStage stage;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3667
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  3668
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3669
2463
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3670
	ResetNewGRFData();
de2605ed3758 (svn r2989) - Make engine/vehicle information tables constant. Duplicate them so NewGRF data can be loaded without wiping out the default data.
peter1138
parents: 2458
diff changeset
  3671
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3672
	/* Load newgrf sprites
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3673
	 * in each loading stage, (try to) open each file specified in the config
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3674
	 * and load information from it. */
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3675
	for (stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
2400
0b51bc385750 (svn r2926) -Fix: Use the same file slots in both initialisation stages when loading a patch grf
tron
parents: 2346
diff changeset
  3676
		uint slot = file_index;
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3677
		GRFConfig *c;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3678
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3679
		_cur_stage = stage;
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3680
		_cur_spriteid = load_index;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3681
		for (c = _grfconfig; c != NULL; c = c->next) {
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3682
			if (HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND)) continue;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3683
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3684
			// TODO usererror()
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3685
			if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  3686
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3687
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3688
			LoadNewGRFFile(c, slot++, stage);
5008
f95f0bd55c34 (svn r7027) - Codechange: Replace NewGRF loading stage masks with separate function lists. This will allow us to call different handlers depending on the current stage. Also enum-ize the stage.
peter1138
parents: 4993
diff changeset
  3689
			if (stage == GLS_ACTIVATION) ClearTemporaryNewGRFData();
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3690
			DEBUG(sprite, 2, "Currently %i sprites are loaded", load_index);
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3691
		}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  3692
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3693
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3694
	// Pre-calculate all refit masks after loading GRF files
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3695
	CalculateRefitMasks();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3696
}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3697
5588
1bcb6b4c01d8 (svn r7592) -Feature: Add support for tractive effort to 'realistic' acceleration.
peter1138
parents: 5570
diff changeset
  3698