newgrf.c
author glx
Mon, 24 Sep 2007 03:08:47 +0000
branch0.5
changeset 5545 f42dc59a45f5
parent 5511 fee376b81447
permissions -rw-r--r--
(svn r11153) [0.5] -Fix [FS#1251]: incorrect usage of {G} tag in slovak translation
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
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   121
/* Debugging messages policy:
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   122
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   123
 * These should be the severities used for direct DEBUG() calls
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   124
 * (there is room for exceptions, but you have to have a good cause):
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   125
 *
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   126
 * 0..2 - dedicated to grfmsg()
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   127
 * 3
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   128
 * 4
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   129
 * 5
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   130
 * 6 - action handler entry reporting - one per action
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   131
 * 7 - basic action progress reporting - in loops, only single one allowed
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   132
 * 8 - more detailed progress reporting - less important stuff, in deep loops etc
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   133
 * 9 - extremely detailed progress reporting - detailed reports inside of deep loops and so
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   134
 */
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   135
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
   136
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   137
typedef enum grfmsg_severity {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	GMS_NOTICE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	GMS_WARN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	GMS_ERROR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	GMS_FATAL,
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   142
} grfmsg_severity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   144
static void CDECL grfmsg(grfmsg_severity severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   146
	static const char* const severitystr[] = {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   147
		"Notice",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   148
		"Warning",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   149
		"Error",
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   150
		"Fatal"
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   151
	};
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   152
	int export_severity = 0;
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   153
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   157
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   159
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   160
	export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
   161
	DEBUG(grf, export_severity) ("[%s:%d][%s] %s", _cur_grffile->filename, _nfo_line, severitystr[severity], buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   164
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   165
#define check_length(real, wanted, where) \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   166
do { \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   167
	if (real < wanted) { \
2849
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
   168
		grfmsg(GMS_ERROR, "%s: Invalid special sprite length %d (expected %d)!", \
73c752b82488 (svn r3397) - NewGRF fix: Show nfo sprite number instead of current sprite id for warning messages -- this makes this output more useful...
peter1138
parents: 2846
diff changeset
   169
		       where, real, wanted); \
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   170
		return; \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   171
	} \
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   172
} while (0)
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   173
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   174
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   175
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
   176
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
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
   182
	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
   183
	return val | (grf_load_byte(buf) << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   186
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   187
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   188
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   189
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   190
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   191
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   192
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   193
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   194
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
{
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
   196
	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
   197
	return val | (grf_load_word(buf) << 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
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
   200
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
   201
{
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
   202
	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
   203
		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
   204
		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
   205
		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
   206
		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
   207
			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
   208
			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
   209
	}
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
   210
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   211
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   212
static const char *grf_load_string(byte **buf, size_t max_len)
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   213
{
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   214
	const char *string   = *(const char **)buf;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   215
	size_t string_length = ttd_strnlen(string, max_len);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   216
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   217
	if (string_length == max_len) {
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   218
		/* String was not NUL terminated, so make sure it is now. */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   219
		(*buf)[string_length - 1] = '\0';
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   220
		DEBUG(grf, 7) ("String was not terminated with a zero byte.");
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   221
	} else {
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   222
		/* Increase the string length to include the NUL byte. */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   223
		string_length++;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   224
	}
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   225
	*buf += string_length;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   226
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   227
	return string;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   228
}
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
   229
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   230
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
   231
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   232
	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
   233
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   234
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   235
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   236
	}
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
   237
	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
   238
}
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
   239
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   240
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
   241
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   242
	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
   243
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   244
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   245
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   246
	}
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
   247
	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
   248
}
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
   249
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
   250
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   251
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
   252
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
   253
#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
   254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
static void dewagonize(int condition, int engine)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   260
	if (condition != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		ei->unk2 &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
		rvi->flags &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
		ei->unk2 |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
		rvi->flags |= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   269
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
   270
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	EngineInfo *ei = &_engine_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   275
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   278
		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
   279
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
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
   282
				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
   283
					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
   284
					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
   285
					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
   286
					default:
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
   287
						grfmsg(GMS_WARN, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring.", tracktype);
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
   288
						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
   289
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
			}
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
   291
			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
   292
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   293
		case 0x08: /* AI passenger service */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   295
			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
   296
			ret = true;
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
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   299
		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
   300
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
				uint16 speed = grf_load_word(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   302
				if (speed == 0xFFFF) speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
				rvi[i].max_speed = speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   306
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   307
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   308
		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
   309
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
				uint16 power = grf_load_word(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   312
				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
   313
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
				rvi[i].power = power;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
				dewagonize(power, engine + i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   317
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   318
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   319
		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
   320
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
				uint8 runcostfact = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   323
				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
   324
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
				rvi[i].running_cost_base = runcostfact;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   327
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   328
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   329
		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
   330
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
				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
   334
					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
   335
					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
   336
					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
   337
					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
   338
					default:
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   339
						grfmsg(GMS_WARN, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring.", base);
b2429a2def00 (svn r7485) -Codechange: [NewGRF] Add debug warning for unsupported running cost bases for rail vehicles.
peter1138
parents: 5317
diff changeset
   340
						break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   343
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   344
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   345
		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
   346
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
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
   349
				/* 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
   350
				 * 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
   351
				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
   352
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
				rvi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
			}
3089
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 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
   358
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   361
				if (dual != 0) {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   362
					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
   363
						// 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
   364
						rvi[i].power /= 2;
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   365
						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
   366
					}
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   367
					rvi[i].flags |= RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
				} else {
2836
b5e8424f5955 (svn r3384) - NewGRF fix: running cost should be halved for dual head vehicles.
peter1138
parents: 2812
diff changeset
   369
					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
   370
						// 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
   371
						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
   372
						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
   373
					}
1894
0053e4f13db8 (svn r2400) - Fix: [newgrf] Load power for dual-headed engines correctly
hackykid
parents: 1891
diff changeset
   374
					rvi[i].flags &= ~RVI_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   377
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   378
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   379
		case 0x14: /* Cargo capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   380
			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
   381
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   382
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   383
		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
   384
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
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
   387
				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
   388
					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
   389
				} else {
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
   390
					grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Invalid cargo type %d, ignoring.", 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
   391
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			}
3023
e56ff3134c77 (svn r3603) - NewGRF: Support loading of AI rank data
peter1138
parents: 3006
diff changeset
   393
			break;
e56ff3134c77 (svn r3603) - NewGRF: Support loading of AI rank data
peter1138
parents: 3006
diff changeset
   394
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   395
		case 0x16: /* Weight */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   396
			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
   397
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   398
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   399
		case 0x17: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   400
			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
   401
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   402
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   403
		case 0x18: /* AI rank */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   404
			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
   405
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   406
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   407
		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
   408
			/* 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
   409
			 * 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
   410
			 * 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
   411
			 * 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
   412
			 * 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
   413
			 * 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
   414
			 */
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
   415
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
				uint8 traction = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
				int engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   419
				if (traction <= 0x07) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
					engclass = 0;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   421
				} else if (traction <= 0x27) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
					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
   423
				} 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
   424
					engclass = 2;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   425
				} else if (traction <= 0x41) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
					engclass = 2;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   427
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
					break;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   429
				}
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
   430
				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
   431
				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
   432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
				rvi[i].engclass = engclass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   435
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   436
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   437
		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
   438
			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
   439
				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
   440
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
   441
				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
   442
					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
   443
				} else {
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
   444
					grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Invalid train engine ID %d, ignoring.", 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
   445
				}
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
   446
			}
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
   447
			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
   448
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   449
		case 0x1B: /* Powered wagons power bonus */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   450
			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
   451
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   452
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   453
		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
   454
			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
   455
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   456
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   457
		case 0x1D: /* Refit cargo */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   458
			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
   459
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   460
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   461
		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
   462
			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
   463
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   464
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   465
		case 0x21: /* Shorter vehicle */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   466
			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
   467
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   468
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   469
		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
   470
			// 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
   471
			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
   472
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   473
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   474
		case 0x23: /* Powered wagons weight bonus */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   475
			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
   476
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   477
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   478
		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
   479
			FOR_EACH_OBJECT {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   480
				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
   481
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   482
				if (weight > 4) {
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   483
					grfmsg(GMS_NOTICE, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring.", weight << 8);
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   484
				} else {
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   485
					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
   486
				}
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   487
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   488
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   489
3862
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   490
		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
   491
			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
   492
			break;
898c8212afa1 (svn r4896) - NewGRF: add support for vehicle property 0x25 (user defined data) used by variable 0x42.
peter1138
parents: 3845
diff changeset
   493
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   494
		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
   495
			FOR_EACH_OBJECT {
d5a2d3da5002 (svn r6654) - Codechange: If no 2cc vehicles are available, hide the secondary colour choice.
peter1138
parents: 4711
diff changeset
   496
				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
   497
				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
   498
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   499
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   500
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   501
		case 0x28: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   502
			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
   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 0x29: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   506
			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
   507
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   508
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
   509
		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
   510
			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
   511
			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
   512
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
		/* TODO */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
		/* 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
   515
		case 0x1F: /* Tractive effort */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   516
		case 0x20: /* Air drag */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   517
		case 0x26: /* Retire vehicle early */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   519
			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
   520
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   521
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   522
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   524
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   525
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   531
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
   532
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   533
	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
   534
	RoadVehicleInfo *rvi = &_road_vehicle_info[engine];
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   535
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   536
	int i;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   537
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   538
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   539
	switch (prop) {
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   540
		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
   541
			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
   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 0x09: /* Running cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   545
			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
   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 0x0A: /* Running cost base */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   549
			/* TODO: I have no idea. --pasky */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   550
			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
   551
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   552
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   553
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   554
		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
   555
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   556
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   557
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   558
				// 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
   559
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   560
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   561
				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
   562
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   563
				rvi[i].image_index = spriteid;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   564
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   565
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   566
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   567
		case 0x0F: /* Cargo capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   568
			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
   569
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   570
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   571
		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
   572
			FOR_EACH_OBJECT {
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   573
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   574
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
   575
				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
   576
					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
   577
				} else {
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
   578
					grfmsg(GMS_NOTICE, "RoadVehicleChangeInfo: Invalid cargo type %d, ignoring.", 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
   579
				}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   580
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   581
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   582
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   583
		case 0x11: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   584
			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
   585
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   586
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   587
		case 0x12: /* SFX */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   588
			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
   589
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   590
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   591
		case 0x13: /* Power in 10hp */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   592
		case 0x14: /* Weight in 1/4 tons */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   593
		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
   594
			/* 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
   595
			 * 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
   596
			 * missing in OTTD yet. --pasky */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   597
			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
   598
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   599
			break;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   600
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   601
		case 0x16: /* Cargos available for refitting */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   602
			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
   603
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   604
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   605
		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
   606
			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
   607
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   608
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   609
		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
   610
			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
   611
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   612
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   613
		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
   614
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   615
				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
   616
				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
   617
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   618
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   619
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   620
		case 0x1D: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   621
			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
   622
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   623
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   624
		case 0x1E: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   625
			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
   626
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   627
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
   628
		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
   629
			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
   630
			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
   631
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   632
		case 0x18: /* Tractive effort */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   633
		case 0x19: /* Air drag */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   634
		case 0x1B: /* Retire vehicle early */
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   635
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   636
			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
   637
			ret = true;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   638
			break;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   639
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   640
		default:
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   641
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   642
			break;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   643
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   644
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   645
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   646
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   647
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   648
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   649
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
   650
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   651
	EngineInfo *ei = &_engine_info[SHIP_ENGINES_INDEX + engine];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	ShipVehicleInfo *svi = &_ship_vehicle_info[engine];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	byte *buf = *bufp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	int i;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   655
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	//printf("e %x prop %x?\n", engine, prop);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   659
		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
   660
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   663
				// 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
   664
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   665
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   666
				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
   667
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
				svi[i].image_index = spriteid;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
			}
3089
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 0x09: /* Refittable */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   673
			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
   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 0x0A: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   677
			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
   678
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   679
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   680
		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
   681
			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
   682
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   683
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   684
		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
   685
			FOR_EACH_OBJECT {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
				// XXX: Need to consult this with patchman yet.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
#if 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
				// Documentation claims this is already the
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
				// per-landscape cargo type id, but newships.grf
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
				// assume otherwise.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
				cargo = local_cargo_id_ctype[cargo];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
#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
   695
				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
   696
					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
   697
				} else {
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
   698
					grfmsg(GMS_NOTICE, "ShipVehicleChangeInfo: Invalid cargo type %d, ignoring.", 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
   699
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
			}
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   701
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   702
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   703
		case 0x0D: /* Cargo capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   704
			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
   705
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   706
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   707
		case 0x0F: /* Running cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   708
			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
   709
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   710
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   711
		case 0x10: /* SFX */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   712
			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
   713
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   714
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   715
		case 0x11: /* Cargos available for refitting */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   716
			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
   717
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   718
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   719
		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
   720
			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
   721
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   722
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   723
		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
   724
			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
   725
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   726
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   727
		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
   728
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   729
				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
   730
				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
   731
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   732
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   733
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   734
		case 0x18: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   735
			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
   736
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   737
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   738
		case 0x19: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   739
			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
   740
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   741
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
   742
		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
   743
			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
   744
			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
   745
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   746
		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
   747
		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
   748
		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
   749
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   750
			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
   751
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   752
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   753
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		default:
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   755
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   756
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
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
   763
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
   764
{
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   765
	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
   766
	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
   767
	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
   768
	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
   769
	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
   770
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
   771
	//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
   772
	switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   773
		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
   774
			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
   775
				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
   776
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   777
				// 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
   778
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   779
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   780
				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
   781
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
   782
				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
   783
			}
3006
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   784
			break;
f106b4538f41 (svn r3586) - NewGRF: Load callback masks for all vehicle types.
peter1138
parents: 2971
diff changeset
   785
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   786
		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
   787
			FOR_EACH_OBJECT {
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   788
				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
   789
					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
   790
				} else {
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   791
					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
   792
				}
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   793
			}
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   794
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   795
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   796
		case 0x0A: /* Large */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   797
			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
   798
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   799
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   800
		case 0x0B: /* Cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   801
			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
   802
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   803
3488
d1d5c0f3f69d (svn r4339) - Comment Change: NewGRF, update comments for units of speed
peter1138
parents: 3355
diff changeset
   804
		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
   805
			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
   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 0x0D: /* Acceleration */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   809
			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
   810
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   811
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   812
		case 0x0E: /* Running cost factor */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   813
			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
   814
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   815
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   816
		case 0x0F: /* Passenger capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   817
			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
   818
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   819
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   820
		case 0x11: /* Mail capacity */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   821
			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
   822
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   823
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   824
		case 0x12: /* SFX */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   825
			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
   826
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   827
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   828
		case 0x13: /* Cargos available for refitting */
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   829
			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
   830
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   831
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   832
		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
   833
			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
   834
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   835
3997
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   836
		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
   837
			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
   838
			break;
29c77eab14a4 (svn r5201) - NewGRF: add loading of default refit costs. This information is not yet used
peter1138
parents: 3956
diff changeset
   839
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   840
		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
   841
			FOR_EACH_OBJECT {
8f4969f51719 (svn r6946) - Fix (r6654): This applies to all vehicle types, not just rail vehicles... (mart3p)
peter1138
parents: 4926
diff changeset
   842
				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
   843
				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
   844
			}
3095
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   845
			break;
2d4498efac3b (svn r3684) - NewGRF: Support loading of miscellaneous flags (not used yet)
peter1138
parents: 3089
diff changeset
   846
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   847
		case 0x18: /* Cargo classes allowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   848
			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
   849
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   850
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   851
		case 0x19: /* Cargo classes disallowed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   852
			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
   853
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   854
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
   855
		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
   856
			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
   857
			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
   858
1872
5fe1a92bde30 (svn r2378) - Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data
orudge
parents: 1871
diff changeset
   859
		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
   860
			/* TODO */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   861
			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
   862
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   863
			break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   864
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
   865
		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
   866
			ret = true;
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
   867
			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
   868
	}
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
   869
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
   870
	*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
   871
	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
   872
}
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
   873
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   874
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
   875
{
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
   876
	StationSpec **statspec;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   877
	byte *buf = *bufp;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   878
	int i;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   879
	bool ret = false;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   880
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
   881
	if (stid + numinfo > MAX_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
   882
		grfmsg(GMS_WARN, "StationChangeInfo: Station %u is invalid, max %u, ignoring.", stid + numinfo, MAX_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
   883
		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
   884
	}
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
   885
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
   886
	/* 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
   887
	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
   888
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
   889
	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
   890
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
   891
	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
   892
		/* 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
   893
		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
   894
			if (statspec[i] == NULL) {
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
   895
				grfmsg(GMS_NOTICE, "StationChangeInfo: Attempt to modify undefined station %u, ignoring.", stid + 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
   896
				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
   897
			}
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
   898
		}
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
   899
	}
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
   900
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   901
	switch (prop) {
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   902
		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
   903
			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
   904
				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
   905
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
   906
				/* 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
   907
				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
   908
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
   909
				/* 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
   910
				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
   911
				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
   912
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   913
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   914
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   915
		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
   916
			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
   917
				StationSpec *statspec = _cur_grffile->stations[stid + i];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   918
				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
   919
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   920
				statspec->tiles = grf_load_extended(&buf);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   921
				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
   922
				statspec->copied_renderdata = false;
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   923
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   924
				for (t = 0; t < statspec->tiles; t++) {
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   925
					DrawTileSprites *dts = &statspec->renderdata[t];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   926
					uint seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   927
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
   928
					dts->seq = NULL;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   929
					dts->ground_sprite = grf_load_dword(&buf);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   930
					if (dts->ground_sprite == 0) continue;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
   931
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   932
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   933
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   934
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   935
						// 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
   936
						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
   937
						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
   938
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   939
						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
   940
						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
   941
						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
   942
						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
   943
						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
   944
						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
   945
						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
   946
						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
   947
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   948
						/* Remap flags as ours collide */
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   949
						if (HASBIT(dtss->image, 31)) {
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   950
							CLRBIT(dtss->image, 31);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   951
							SETBIT(dtss->image, 30);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
   952
						}
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
   953
						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
   954
							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
   955
							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
   956
						}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   957
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   958
				}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   959
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   960
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   961
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   962
		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
   963
			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
   964
				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
   965
				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
   966
				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
   967
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
   968
				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
   969
				statspec->renderdata = srcstatspec->renderdata;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
   970
				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
   971
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   972
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   973
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   974
		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
   975
			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
   976
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   977
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   978
		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
   979
			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
   980
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   981
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   982
		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
   983
			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
   984
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   985
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
   986
		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
   987
			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
   988
				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
   989
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
   990
				statspec->copied_layouts = false;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
   991
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   992
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   993
					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
   994
					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
   995
					StationLayout layout;
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
   996
					uint l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
   997
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
   998
					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
   999
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1000
					//debug("l %d > %d ?", length, stat->lengths);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1001
					if (length > statspec->lengths) {
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1002
						statspec->platforms = realloc(statspec->platforms, length);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1003
						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
  1004
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1005
						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
  1006
						memset(statspec->layouts + statspec->lengths, 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1007
						       (length - statspec->lengths) * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1008
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1009
						statspec->lengths = length;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1010
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1011
					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
  1012
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1013
					//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
  1014
					if (number > statspec->platforms[l]) {
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1015
						statspec->layouts[l] = realloc(statspec->layouts[l],
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1016
						                               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
  1017
						// 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
  1018
						memset(statspec->layouts[l] + statspec->platforms[l], 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1019
						       (number - statspec->platforms[l]) * sizeof(**statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1020
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1021
						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
  1022
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1023
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1024
					p = 0;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1025
					layout = malloc(length * number);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1026
					for (l = 0; l < length; l++) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1027
						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
  1028
							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
  1029
						}
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1030
					}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1031
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1032
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1033
					p--;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1034
					free(statspec->layouts[l][p]);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1035
					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
  1036
				}
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
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1039
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1040
		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
  1041
			FOR_EACH_OBJECT {
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1042
				StationSpec *statspec = _cur_grffile->stations[stid + i];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1043
				byte srcid = grf_load_byte(&buf);
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1044
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1045
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1046
				statspec->lengths   = srcstatspec->lengths;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1047
				statspec->platforms = srcstatspec->platforms;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1048
				statspec->layouts   = srcstatspec->layouts;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1049
				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
  1050
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1051
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1052
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1053
		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
  1054
			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
  1055
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1056
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1057
		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
  1058
			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
  1059
			break;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1060
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1061
		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
  1062
			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
  1063
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1064
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1065
		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
  1066
			FOR_EACH_OBJECT statspec[i]->flags = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1067
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1068
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1069
		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
  1070
			FOR_EACH_OBJECT statspec[i]->wires = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1071
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1072
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1073
		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
  1074
			FOR_EACH_OBJECT statspec[i]->blocked = grf_load_byte(&buf);
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1075
			break;
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1076
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1077
		case 0x16: /* TODO Animation info */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1078
			FOR_EACH_OBJECT grf_load_word(&buf);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1079
			ret = true;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1080
			break;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1081
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1082
		case 0x17: /* TODO Animation speed */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1083
			FOR_EACH_OBJECT grf_load_byte(&buf);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1084
			ret = true;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1085
			break;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1086
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1087
		case 0x18: /* TODO Animation triggers */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1088
			FOR_EACH_OBJECT grf_load_word(&buf);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1089
			ret = true;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1090
			break;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  1091
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1092
		default:
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1093
			ret = true;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1094
			break;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1095
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1096
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1097
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1098
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1099
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1100
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
  1101
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
  1102
{
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
	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
  1104
	int i;
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1105
	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
  1106
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
  1107
	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
  1108
		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
  1109
			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
  1110
			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
  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
		case 0x09: /* Minimum length */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1113
			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
  1114
			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
  1115
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
  1116
		case 0x0A: /* Maximum length */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1117
			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
  1118
			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
  1119
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
  1120
		case 0x0B: /* Cost factor */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1121
			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
  1122
			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
  1123
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
  1124
		case 0x0C: /* Maximum speed */
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1125
			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
  1126
			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
  1127
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
  1128
		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
  1129
			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
  1130
				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
  1131
				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
  1132
				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
  1133
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
  1134
				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
  1135
					/* 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
  1136
					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
  1137
				}
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
  1138
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
  1139
				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
  1140
					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
  1141
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
  1142
					if (tableid >= 7) { // skip invalid data
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
  1143
						grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", 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
  1144
						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
  1145
						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
  1146
					}
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
  1147
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
  1148
					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
  1149
						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
  1150
					}
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
  1151
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
  1152
					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
  1153
						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
  1154
				}
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
  1155
			}
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
  1156
			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
  1157
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
  1158
		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
  1159
			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
  1160
			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
  1161
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
  1162
		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
  1163
			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
  1164
			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
  1165
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
  1166
		default:
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1167
			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
  1168
	}
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
  1169
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
  1170
	*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
  1171
	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
  1172
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1173
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1174
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
  1175
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1176
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1177
	int i;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1178
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1179
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1180
	switch (prop) {
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1181
		case 0x08: /* Cost base factor */
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1182
			FOR_EACH_OBJECT {
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1183
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1184
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1185
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1186
				if (price < NUM_PRICES) {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1187
					SetPriceBaseMultiplier(price, factor);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1188
				} else {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1189
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Price %d out of range, ignoring.", price);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1190
				}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1191
			}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1192
			break;
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1193
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1194
		case 0x0A: // Currency display names
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1195
			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
  1196
				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
  1197
				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
  1198
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1199
				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
  1200
					_currency_specs[curidx].name = newone;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1201
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1202
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1203
			break;
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
		case 0x0B: // Currency multipliers
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1206
			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
  1207
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1208
				uint32 rate = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1209
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1210
				if (curidx < NUM_CURRENCY) {
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1211
					/* 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
  1212
					 * 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
  1213
					 * to be compatible */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1214
					_currency_specs[curidx].rate = rate / 1000;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1215
				} else {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1216
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring.", curidx);
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
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1219
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1220
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1221
		case 0x0C: // Currency options
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1222
			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
  1223
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1224
				uint16 options = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1225
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1226
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1227
					_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
  1228
					/* 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
  1229
					 * 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
  1230
					_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
  1231
				} else {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1232
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency option %d out of range, ignoring.", curidx);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1233
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1234
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1235
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1236
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1237
		case 0x0D: // Currency prefix symbol
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1238
			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
  1239
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1240
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1241
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1242
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1243
					memcpy(_currency_specs[curidx].prefix,&tempfix,4);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1244
					_currency_specs[curidx].prefix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1245
				} else {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1246
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring.", curidx);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1247
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1248
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1249
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1250
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1251
		case 0x0E: // Currency suffix symbol
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1252
			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
  1253
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1254
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1255
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1256
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1257
					memcpy(&_currency_specs[curidx].suffix,&tempfix,4);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1258
					_currency_specs[curidx].suffix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1259
				} else {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1260
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring.", curidx);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1261
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1262
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1263
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1264
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1265
		case 0x0F: //  Euro introduction dates
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1266
			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
  1267
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1268
				Year year_euro = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1269
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1270
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1271
					_currency_specs[curidx].to_euro = year_euro;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1272
				} else {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1273
					grfmsg(GMS_WARN, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring.", curidx);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1274
				}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1275
			}
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1276
			break;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1277
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1278
		case 0x09: // Cargo translation table
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1279
		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
  1280
		default:
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1281
			ret = true;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1282
	}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1283
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1284
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1285
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1286
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1287
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1288
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
  1289
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1290
	byte *buf = *bufp;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1291
	int i;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1292
	bool ret = false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1293
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1294
	if (_cur_grffile->sound_offset == 0) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1295
		grfmsg(GMS_WARN, "SoundEffectChangeInfo: No effects defined, skipping.");
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1296
		return false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1297
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1298
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1299
	switch (prop) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1300
		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
  1301
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1302
				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
  1303
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1304
				if (sound >= GetNumSounds()) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1305
					grfmsg(GMS_WARN, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1306
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1307
					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
  1308
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1309
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1310
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1311
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1312
		case 0x09: /* Priority */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1313
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1314
				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
  1315
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1316
				if (sound >= GetNumSounds()) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1317
					grfmsg(GMS_WARN, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1318
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1319
					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
  1320
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1321
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1322
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1323
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1324
		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
  1325
			FOR_EACH_OBJECT {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1326
				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
  1327
				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
  1328
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1329
				if (sound >= GetNumSounds() || orig_sound >= GetNumSounds()) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1330
					grfmsg(GMS_WARN, "SoundEffectChangeInfo: Sound %d or %d not defined (max %d)", sound, orig_sound, GetNumSounds());
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1331
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1332
					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
  1333
					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
  1334
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1335
					/* 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
  1336
					*oldfe = *newfe;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1337
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1338
			}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1339
			break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1340
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1341
		default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1342
			ret = true;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1343
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1344
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1345
	*bufp = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1346
	return ret;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1347
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1348
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1349
/* Action 0x00 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1350
static void FeatureChangeInfo(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
	/* <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
  1356
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
	 * 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
  1358
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	 * 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
  1360
	 * B num-info      how many vehicles/stations to change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
	 * 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
  1362
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
	 * 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
  1365
	 * 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
  1366
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  1368
	static const VCI_Handler handler[] = {
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1369
		/* GSF_TRAIN */        RailVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1370
		/* GSF_ROAD */         RoadVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1371
		/* GSF_SHIP */         ShipVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1372
		/* GSF_AIRCRAFT */     AircraftVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1373
		/* GSF_STATION */      StationChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1374
		/* GSF_CANAL */        NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1375
		/* GSF_BRIDGE */       BridgeChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1376
		/* GSF_TOWNHOUSE */    NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1377
		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1378
		/* GSF_INDUSTRYTILES */NULL,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  1379
		/* GSF_INDUSTRIES */   NULL,
4138
15f4aa024ad4 (svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents: 4077
diff changeset
  1380
		/* 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
  1381
		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1383
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1384
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1385
	uint8 numprops;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1386
	uint8 numinfo;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1387
	byte engine;
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1388
	EngineInfo *ei = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
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
  1390
	if (len == 1) {
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
  1391
		DEBUG(grf, 8) ("Silently ignoring one-byte special sprite 0x00.");
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
  1392
		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
  1393
	}
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
  1394
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1395
	check_length(len, 6, "FeatureChangeInfo");
3714
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1396
	buf++;
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1397
	feature  = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1398
	numprops = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1399
	numinfo  = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  1400
	engine   = grf_load_byte(&buf);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1401
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1402
	DEBUG(grf, 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
  1403
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  1404
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
  1405
	if (feature >= lengthof(handler) || handler[feature] == NULL) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1406
		grfmsg(GMS_WARN, "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
  1407
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1408
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1409
2439
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1410
	if (feature <= GSF_AIRCRAFT) {
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1411
		if (engine + numinfo > _vehcounts[feature]) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1412
			grfmsg(GMS_ERROR, "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
  1413
			return;
c820a9751afc (svn r2965) Fix: newgrf: Add bounds checking to VehicleChangeInfo for vehicles and change
peter1138
parents: 2438
diff changeset
  1414
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1415
		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
  1416
	}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1417
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1418
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1419
		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
  1420
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1421
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1422
		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
  1423
			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
  1424
			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
  1425
			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
  1426
			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
  1427
				/* 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
  1428
				switch (prop) {
3089
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1429
					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
  1430
						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
  1431
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1432
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1433
					case 0x02: /* Decay speed */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1434
						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
  1435
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1436
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1437
					case 0x03: /* Vehicle life */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1438
						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
  1439
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1440
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1441
					case 0x04: /* Model life */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1442
						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
  1443
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1444
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1445
					case 0x06: /* Climates available */
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1446
						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
  1447
						break;
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1448
e5d1c3984821 (svn r3678) - NewGRF Codechange: remove redundant braces and temporary variables.
peter1138
parents: 3033
diff changeset
  1449
					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
  1450
						/* 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
  1451
						 * 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
  1452
						 * credit ;-). --pasky */
5211
651c9272ad22 (svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents: 5210
diff changeset
  1453
						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
  1454
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1455
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1456
					default:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1457
						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
  1458
							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
  1459
						break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1460
				}
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1461
				break;
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1462
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1463
			default:
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1464
				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
  1465
					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
  1466
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1467
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1468
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  1469
		if (ignoring)
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1470
			grfmsg(GMS_NOTICE, "FeatureChangeInfo: Ignoring property 0x%02X (not implemented).", prop);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1474
/* Action 0x00 (GLS_SAFETYSCAN) */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1475
static void SafeChangeInfo(byte *buf, int len)
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1476
{
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1477
	uint8 feature;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1478
	uint8 numprops;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1479
	uint8 numinfo;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1480
	uint8 index;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1481
5447
fdd232ac18d0 (svn r8883) [0.5] -Backport from trunk (r8740, r8793, r8865, r8878):
Darkvater
parents: 5441
diff changeset
  1482
	if (len == 1) {
fdd232ac18d0 (svn r8883) [0.5] -Backport from trunk (r8740, r8793, r8865, r8878):
Darkvater
parents: 5441
diff changeset
  1483
		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
fdd232ac18d0 (svn r8883) [0.5] -Backport from trunk (r8740, r8793, r8865, r8878):
Darkvater
parents: 5441
diff changeset
  1484
		return;
fdd232ac18d0 (svn r8883) [0.5] -Backport from trunk (r8740, r8793, r8865, r8878):
Darkvater
parents: 5441
diff changeset
  1485
	}
fdd232ac18d0 (svn r8883) [0.5] -Backport from trunk (r8740, r8793, r8865, r8878):
Darkvater
parents: 5441
diff changeset
  1486
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1487
	check_length(len, 6, "SafeChangeInfo");
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1488
	buf++;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1489
	feature  = grf_load_byte(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1490
	numprops = grf_load_byte(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1491
	numinfo  = grf_load_byte(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1492
	index    = grf_load_byte(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1493
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1494
	if (feature == GSF_BRIDGE && numprops == 1) {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1495
		uint8 prop = grf_load_byte(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1496
		/* Bridge property 0x0D is redefinition of sprite layout tables, which
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1497
		 * is considered safe. */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1498
		if (prop == 0x0D) return;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1499
	}
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1500
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1501
	SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1502
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1503
	/* Skip remainder of GRF */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1504
	_skip_sprites = -1;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1505
}
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  1506
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
  1507
#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
  1508
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1509
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1510
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1511
 * @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
  1512
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1513
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1514
static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1515
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  1516
	SpriteGroup *group = AllocateSpriteGroup();
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1517
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1518
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1519
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1520
	// 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
  1521
	// 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
  1522
	if ((value >> 8) == 0xFF) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1523
		value &= ~0xFF00;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1524
	} else {
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1525
		value &= ~0x8000;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1526
	}
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1527
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  1528
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1529
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1530
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  1531
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
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
  1533
/**
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
  1534
 * 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
  1535
 * @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
  1536
 * @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
  1537
 * @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
  1538
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1539
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
  1540
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  1541
	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
  1542
	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
  1543
	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
  1544
	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
  1545
	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
  1546
}
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
  1547
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1548
/* 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
  1549
static void NewSpriteSet(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1556
	 * 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
  1557
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
	 *                         In that case, use num-dirs=4.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
	 *                 For stations, must be 12 (hex) for the eighteen
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
	 *                         different sprites that make up a station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
	/* TODO: No stations support. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1564
	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
  1565
	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
  1566
	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
  1567
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1569
	check_length(len, 4, "NewSpriteSet");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1570
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1571
	feature  = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1572
	num_sets = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  1573
	num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
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
  1575
	_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
  1576
	_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
  1577
	_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
  1578
	_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
  1579
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
  1580
	DEBUG(grf, 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
  1581
		"New sprite set at %d of type %d, "
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
  1582
		"consisting of %d sets with %d views each (total %d)",
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
  1583
		_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
  1584
	);
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
  1585
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
  1586
	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
  1587
		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
  1588
		_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
  1589
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
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
  1592
/* 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
  1593
 * defined spritegroup. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  1594
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
  1595
{
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
  1596
	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
  1597
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
  1598
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == 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
  1599
		grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty.", setid, type, 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
  1600
		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
  1601
	}
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
  1602
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
  1603
	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
  1604
}
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
  1605
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
  1606
/* 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
  1607
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
  1608
{
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
  1609
	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
  1610
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1611
	if (spriteid >= _cur_grffile->spriteset_numsets) {
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1612
		grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Sprite set %u invalid, max %u", setid, type, spriteid, _cur_grffile->spriteset_numsets);
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1613
		return NULL;
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1614
	}
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  1615
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
  1616
	/* 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
  1617
	 * 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
  1618
	 * 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
  1619
	if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_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
  1620
		grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Real Sprite IDs 0x%04X - 0x%04X do not (all) exist (max 0x%04X), leaving empty.",
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
  1621
				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
  1622
				_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
  1623
				_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
  1624
		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
  1625
	}
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
  1626
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1627
	if (feature != _cur_grffile->spriteset_feature) {
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1628
		grfmsg(GMS_WARN, "NewSpriteGroup(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping.",
5511
fee376b81447 (svn r10277) [0.5] -Backport from trunk (10116, r10128, r10130, r10131, r10137, r10138):
rubidium
parents: 5497
diff changeset
  1629
				setid, type,
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1630
				_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
  1631
		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
  1632
	}
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1633
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
  1634
	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
  1635
}
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
  1636
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1637
/* 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
  1638
static void NewSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	/* <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
  1641
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	 *                 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
  1646
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
	 * 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
  1650
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1651
	uint8 setid;
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1652
	uint8 type;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1653
	SpriteGroup *group = NULL;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1654
	byte *bufend = buf + len;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  1655
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1656
	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
  1657
	buf++;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1658
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1659
	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
  1660
	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
  1661
	type    = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
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
  1663
	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
  1664
		// 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
  1665
		_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
  1666
		// 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
  1667
		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
  1668
			_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
  1669
	}
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
  1670
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1671
	switch (type) {
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1672
		/* Deterministic Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1673
		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
  1674
		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
  1675
		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
  1676
		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
  1677
		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
  1678
		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
  1679
		{
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
  1680
			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
  1681
			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
  1682
			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
  1683
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
			/* 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
  1685
			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
  1686
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1687
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1688
			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
  1689
			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
  1690
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
			switch (GB(type, 2, 2)) {
3672
73caf2e829f8 (svn r4588) - NewGRF: silence a false compiler warning
peter1138
parents: 3668
diff changeset
  1692
				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
  1693
				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
  1694
				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
  1695
				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
  1696
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1697
5288
7758df538a10 (svn r7437) -Fix (r4583): incorrect minimum size check in some cases for VarAction2
peter1138
parents: 5287
diff changeset
  1698
			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
  1699
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
			/* 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
  1701
			 * 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
  1702
			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
  1703
				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
  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
				if (group->g.determ.num_adjusts > 0) {
3694
ba2b26464b85 (svn r4631) - NewGRF: fix incorrect length check
peter1138
parents: 3676
diff changeset
  1706
					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
  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
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->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
  1710
				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
  1711
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
				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
  1713
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
				/* 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
  1715
				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
  1716
				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
  1717
				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
  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
				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
  1720
				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
  1721
				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
  1722
				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
  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
				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
  1725
					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
  1726
					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
  1727
				} 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
  1728
					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
  1729
					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
  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
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
				/* 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
  1733
			} 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
  1734
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
  1735
			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
  1736
			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
  1737
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
  1738
			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
  1739
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
  1740
			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
  1741
				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
  1742
				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
  1743
				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
  1744
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1745
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
  1746
			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
  1747
			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
  1748
		}
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
  1749
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1750
		/* Randomized Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1751
		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
  1752
		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
  1753
		{
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
  1754
			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
  1755
			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
  1756
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
  1757
			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
  1758
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1759
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1760
			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
  1761
			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
  1762
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
  1763
			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
  1764
			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
  1765
			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
  1766
			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
  1767
			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
  1768
			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
  1769
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
  1770
			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
  1771
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
  1772
			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
  1773
				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
  1774
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1775
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1776
			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
  1777
		}
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1778
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
  1779
		/* 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
  1780
		default:
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  1781
		{
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1782
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  1783
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
  1784
			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
  1785
				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
  1786
				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
  1787
				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
  1788
				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
  1789
				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
  1790
				{
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
  1791
					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
  1792
					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
  1793
					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
  1794
					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
  1795
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
  1796
					if (_cur_grffile->spriteset_start == 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
  1797
						grfmsg(GMS_ERROR, "NewSpriteGroup: No sprite set to work on! Skipping.");
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
  1798
						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
  1799
					}
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
  1800
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
  1801
					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
  1802
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
  1803
					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
  1804
					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
  1805
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
  1806
					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
  1807
					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
  1808
					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
  1809
					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
  1810
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
  1811
					DEBUG(grf, 6) ("NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u 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
  1812
							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
  1813
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
  1814
					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
  1815
						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
  1816
						group->g.real.loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
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
  1817
						DEBUG(grf, 8) ("NewSpriteGroup: + rg->loaded[%i]  = subset %u", i, spriteid);
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
  1818
					}
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
  1819
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
  1820
					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
  1821
						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
  1822
						group->g.real.loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
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
  1823
						DEBUG(grf, 8) ("NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
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
  1824
					}
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
  1825
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
  1826
					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
  1827
				}
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
  1828
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
  1829
				/* Loading of Tile Layout and Production Callback groups would happen here */
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
  1830
				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
  1831
					grfmsg(GMS_WARN, "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
  1832
			}
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
  1833
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
	}
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
  1835
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
  1836
	_cur_grffile->spritegroups[setid] = group;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  1839
/* Action 0x03 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1840
static void FeatureMapSpriteGroup(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
	/* <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
  1843
	 * 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
  1844
	 * cargo-list := <cargo-type> <cid> [cargo-list]
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
	 * B feature       see action 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
	 * 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
  1848
	 *                 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
  1849
	 * 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
  1850
	 * 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
  1851
	 *                 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
  1852
	 * 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
  1853
	 * 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
  1854
	 * 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
  1855
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1856
	/* 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
  1857
	 * 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
  1858
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
	static byte *last_engines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
	static int last_engines_count;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1861
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1862
	uint8 idcount;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1863
	bool wagover;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1864
	uint8 cidcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1865
	int c, i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1867
	check_length(len, 6, "FeatureMapSpriteGroup");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1868
	feature = buf[1];
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  1869
	idcount = buf[2] & 0x7F;
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1870
	wagover = (buf[2] & 0x80) == 0x80;
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1871
	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
  1872
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
  1873
	/* 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
  1874
	 * 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
  1875
	if (idcount == 0) {
4918
0b274276f371 (svn r6894) - Codechange: Lower the verbosity level of some NewGRF warnings
peter1138
parents: 4893
diff changeset
  1876
		grfmsg(GMS_NOTICE, "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
  1877
		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
  1878
	}
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
  1879
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1880
	cidcount = buf[3 + idcount];
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1881
	check_length(len, 4 + idcount + cidcount * 3, "FeatureMapSpriteGroup");
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1882
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1883
	DEBUG(grf, 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
  1884
			feature, idcount, cidcount, wagover);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1885
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1886
	if (feature > GSF_STATION) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1887
		grfmsg(GMS_WARN, "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
  1888
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1889
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  1890
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1891
373
218e83c92cb8 (svn r561) -newgrf: killed some of the magic numbers in the code (pasky)
celestar
parents: 372
diff changeset
  1892
	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
  1893
		// 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
  1894
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
  1895
		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
  1896
			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
  1897
			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
  1898
			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
  1899
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
  1900
			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
  1901
				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
  1902
				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
  1903
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1904
				if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1905
					grfmsg(GMS_WARN, "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
  1906
					       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
  1907
					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
  1908
				}
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
  1909
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
  1910
				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
  1911
				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
  1912
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
  1913
				if (ctype >= NUM_GLOBAL_CID) {
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
  1914
					grfmsg(GMS_WARN, "FeatureMapSpriteGroup: Cargo type %d out of range, skipping.", ctype);
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
  1915
					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
  1916
				}
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
  1917
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
  1918
				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
  1919
			}
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
  1920
		}
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
  1921
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
  1922
		{
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
  1923
			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
  1924
			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
  1925
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1926
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1927
				grfmsg(GMS_WARN, "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
  1928
				       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
  1929
				return;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1930
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1931
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
  1932
			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
  1933
				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
  1934
				StationSpec *statspec = _cur_grffile->stations[stid];
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1935
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
  1936
				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
  1937
				statspec->grfid = _cur_grffile->grfid;
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1938
				statspec->localidx = stid;
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1939
				SetCustomStationSpec(statspec);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1940
			}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1941
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1942
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1943
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1944
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1945
	// FIXME: Tropicset contains things like:
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1946
	// 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
  1947
	// what should we exactly do with that? --pasky
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1948
3635
59265706435c (svn r4540) - NewGRF: don't treat integer values as boolean.
peter1138
parents: 3634
diff changeset
  1949
	if (_cur_grffile->spriteset_start == 0 || _cur_grffile->spritegroups == 0) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1950
		grfmsg(GMS_WARN, "FeatureMapSpriteGroup: No sprite set to work on! Skipping.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1951
		return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1952
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1953
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1954
	if (!wagover && last_engines_count != idcount) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1955
		last_engines = realloc(last_engines, idcount);
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1956
		last_engines_count = idcount;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1957
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1958
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1959
	if (wagover) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1960
		if (last_engines_count == 0) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1961
			grfmsg(GMS_ERROR, "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
  1962
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1963
		}
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1964
		DEBUG(grf, 6) ("FeatureMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1965
				last_engines_count, idcount);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1966
	}
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
  1967
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1968
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1969
	for (i = 0; i < idcount; i++) {
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1970
		uint8 engine_id = buf[3 + i];
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1971
		uint8 engine = engine_id + _vehshifts[feature];
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1972
		byte *bp = &buf[4 + idcount];
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1973
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1974
		if (engine_id > _vehcounts[feature]) {
3630
0f7828d892ae (svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents: 3628
diff changeset
  1975
			grfmsg(GMS_ERROR, "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
  1976
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1977
		}
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  1978
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1979
		DEBUG(grf, 7) ("FeatureMapSpriteGroup: [%d] Engine %d...", i, engine);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1980
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1981
		for (c = 0; c < cidcount; c++) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1982
			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
  1983
			uint16 groupid = grf_load_word(&bp);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1984
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1985
			DEBUG(grf, 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
  1986
2516
b11f1229cefd (svn r3045) -NewGRF, Codechange: Don't attempt to map and empty sprite group to a vehicle.
peter1138
parents: 2515
diff changeset
  1987
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  1988
				grfmsg(GMS_WARN, "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
  1989
				return;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1990
			}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1991
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
  1992
			if (ctype == GC_INVALID) ctype = GC_PURCHASE;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  1993
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
  1994
			if (ctype >= NUM_GLOBAL_CID) {
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
  1995
				grfmsg(GMS_WARN, "FeatureMapSpriteGroup: Cargo type %d out of range, skipping.", ctype);
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
  1996
				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
  1997
			}
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
  1998
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  1999
			if (wagover) {
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  2000
				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
  2001
			} 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
  2002
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2003
				last_engines[i] = engine;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2004
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2006
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2008
	{
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2009
		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
  2010
		uint16 groupid = grf_load_word(&bp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
3630
0f7828d892ae (svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents: 3628
diff changeset
  2012
		DEBUG(grf, 8) ("-- Default group id 0x%04X", groupid);
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2013
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
		for (i = 0; i < idcount; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
			uint8 engine = buf[3 + i] + _vehshifts[feature];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2017
			// 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
  2018
			if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  2019
				grfmsg(GMS_WARN, "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
  2020
				return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2023
			if (wagover) {
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2024
				/* 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
  2025
				 * this indicates we have a helicopter rotor override. */
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2026
				if (feature == GSF_AIRCRAFT && engine == last_engines[i]) {
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2027
					SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]);
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2028
				} else {
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  2029
					// 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
  2030
					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
  2031
				}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2032
			} 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
  2033
				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
  2034
				SetEngineGRF(engine, _cur_grffile);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2035
				last_engines[i] = engine;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2041
/* Action 0x04 */
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  2042
static void FeatureNewName(byte *buf, int len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
	 *
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2046
	 * B veh-type      see action 0 (as 00..07, + 0A
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2047
	 *                 But IF veh-type = 48, then generic text
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2048
	 * 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
  2049
	                   with up to 64 language.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2050
	                   Otherwise, it is a mapping where set bits have meaning
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2051
	                   0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2052
	                   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
  2053
	 * 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
  2054
	 * 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
  2055
	 *                 Byte : ID of vehicle to change
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2056
	 *                 Word : ID of string to change/add
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
	 * 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
  2058
	 *                 which the next name begins. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
	/* 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
  2060
	 * 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
  2061
	 * (completely new scenarios changing all graphics and logically also
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
	 * 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
  2063
	 * name), not only the original four ones. --pasky
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2064
	 * 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
  2065
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2066
	uint8 feature;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2067
	uint8 lang;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2068
	uint8 num;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2069
	uint16 id;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2070
	uint16 endid;
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
  2071
	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
  2072
	bool generic;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2073
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  2074
	check_length(len, 6, "FeatureNewName");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2075
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2076
	feature  = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2077
	lang     = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2078
	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
  2079
	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
  2080
	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
  2081
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
  2082
	CLRBIT(lang, 7);
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2083
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
  2084
	if (feature <= GSF_AIRCRAFT && id < _vehcounts[feature]) {
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2085
		id += _vehshifts[feature];
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2086
	}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2087
	endid    = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
3879
3e9cd6403d73 (svn r4928) CodeChange : Rename functions referring to "Vehicle" for "Feature".
belugas
parents: 3875
diff changeset
  2089
	DEBUG(grf, 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
  2090
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2091
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
  2092
	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
  2093
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2094
	for (; id < endid && len > 0; id++) {
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2095
		const char *name   = grf_load_string(&buf, len);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2096
		size_t name_length = strlen(name) + 1;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2097
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2098
		len -= (int)name_length;
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2099
5497
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2100
		DEBUG(grf, 8) ("FeatureNewName: %d <- %s", id, name);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2101
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2102
		switch (feature) {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2103
			case GSF_TRAIN:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2104
			case GSF_ROAD:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2105
			case GSF_SHIP:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2106
			case GSF_AIRCRAFT: {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2107
				if (id < TOTAL_NUM_ENGINES) {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2108
					StringID string = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_8000_KIRBY_PAUL_TANK_STEAM + id);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2109
					SetCustomEngineName(id, string);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2110
				} else {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2111
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  2112
				}
5497
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2113
				break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2114
			}
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2115
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2116
			default:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2117
				switch (GB(id, 8, 8)) {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2118
					case 0xC4: /* Station class name */
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2119
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2120
							grfmsg(GMS_WARN, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2121
						} else {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2122
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2123
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2124
						}
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2125
						break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2126
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2127
					case 0xC5: /* Station name */
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2128
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2129
							grfmsg(GMS_WARN, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring.", GB(id, 0, 8));
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2130
						} else {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2131
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2132
						}
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2133
						break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2134
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2135
					case 0xC9:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2136
					case 0xD0:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2137
					case 0xDC:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2138
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2139
						break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2140
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2141
					default:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2142
						DEBUG(grf, 7) ("FeatureNewName: Unsupported ID (0x%04X)", id);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2143
						break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2144
				}
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2145
				break;
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  2146
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  2147
#if 0
5497
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2148
			case GSF_CANAL :
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2149
			case GSF_BRIDGE :
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2150
			case GSF_TOWNHOUSE :
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2151
				AddGRFString(_cur_spriteid, id, lang, name);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2152
				switch (GB(id, 8,8)) {
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2153
					case 0xC9: /* House name */
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2154
					default:
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2155
						DEBUG(grf, 7) ("FeatureNewName: Unsupported ID (0x%04X)", id);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2156
				}
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2157
				break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2158
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2159
			case GSF_INDUSTRIES :
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2160
			case 0x48 :   /* for generic strings */
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2161
				AddGRFString(_cur_spriteid, id, lang, name);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2162
				break;
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2163
			default :
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2164
				DEBUG(grf,7) ("FeatureNewName: Unsupported feature (0x%02X)", feature);
b9c8c76d31b7 (svn r9853) [0.5] -Backport from trunk (r9837, r9827, r9785, r9775, r9758, r9716):
rubidium
parents: 5480
diff changeset
  2165
				break;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  2166
#endif
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2167
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2171
/* Action 0x05 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
static void GraphicsNew(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2175
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2176
	 * 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
  2177
	 * 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
  2178
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2179
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2180
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2181
	uint8 type;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2182
	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
  2183
	SpriteID replace = 0;
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2184
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2185
	check_length(len, 2, "GraphicsNew");
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2186
	buf++;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2187
	type = grf_load_byte(&buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2188
	num  = grf_load_extended(&buf);
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2189
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
  2190
	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
  2191
		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
  2192
			if (num != 112 && num != 240) {
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
  2193
				grfmsg(GMS_WARN, "GraphicsNews: Signal graphics sprite count must be 112 or 240, skipping.");
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
  2194
				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
  2195
			}
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
  2196
			_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
  2197
			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
  2198
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
  2199
		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
  2200
			if (num != 48) {
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
  2201
				grfmsg(GMS_WARN, "GraphicsNews: Catenary graphics sprite count must be 48, skipping.");
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
  2202
				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
  2203
			}
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
  2204
			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
  2205
			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
  2206
3709
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2207
		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
  2208
			if (num != 74) {
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2209
				grfmsg(GMS_WARN, "GraphicsNews: Foundation graphics sprite count must be 74, skipping.");
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2210
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2211
			}
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2212
			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
  2213
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2214
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2215
		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
  2216
			if (num != 65) {
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2217
				grfmsg(GMS_WARN, "GraphicsNews: Canal graphics sprite count must be 65, skipping.");
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2218
				return;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2219
			}
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2220
			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
  2221
			break;
be60bcc248bc (svn r4652) - NewGRF: support loading of foundation and canal graphics from NewGRF files via action 5
peter1138
parents: 3708
diff changeset
  2222
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2223
		case 0x0D: /* Coast graphics */
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2224
			if (num != 16) {
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2225
				grfmsg(GMS_WARN, "GraphicsNews: Coast graphics sprite count must be 16, skipping.");
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2226
				return;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2227
			}
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2228
			_coast_base = _cur_spriteid;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2229
			break;
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  2230
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
  2231
		default:
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
  2232
			grfmsg(GMS_NOTICE, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring).\n",
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
  2233
					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
  2234
			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
  2235
	}
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
  2236
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
  2237
	if (replace == 0) {
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
  2238
		grfmsg(GMS_NOTICE, "GraphicsNew: Loading %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, _cur_spriteid);
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
  2239
	} else {
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
  2240
		grfmsg(GMS_NOTICE, "GraphicsNew: Replacing %u sprites of type 0x%02X at SpriteID 0x%04X", num, type, replace);
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
  2241
	}
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
  2242
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
  2243
	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
  2244
		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
  2245
		_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
  2246
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2247
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2249
static uint32 GetParamVal(byte param, uint32 *cond_val)
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2250
{
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2251
	switch (param) {
5340
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2252
		case 0x81: /* current year */
82c981816fcb (svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents: 5338
diff changeset
  2253
			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
  2254
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2255
		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
  2256
			return _opt.landscape;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2257
5161
a064564a4a70 (svn r7266) -Codechange: Make the NewGRF loading stage look like ttdpatch to NewGRFs
peter1138
parents: 5115
diff changeset
  2258
		case 0x84: /* GRF loading stage */
a064564a4a70 (svn r7266) -Codechange: Make the NewGRF loading stage look like ttdpatch to NewGRFs
peter1138
parents: 5115
diff changeset
  2259
			return (_cur_stage > GLS_INIT) | ((_cur_stage == GLS_ACTIVATION) << 9);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2260
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2261
		case 0x85: /* TTDPatch flags, only for bit tests */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2262
			if (cond_val == NULL) {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2263
				/* Supported in Action 0x07 and 0x09, not 0x0D */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2264
				return 0;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2265
			} else {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2266
				uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2267
				*cond_val %= 0x20;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2268
				return param_val;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2269
			}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2270
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2271
		case 0x86: /* road traffic side, bit 4 clear=left, set=right */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2272
			return _opt.road_side << 4;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2273
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2274
		case 0x88: /* GRF ID check */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2275
			return 0;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2276
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2277
		case 0x8B: { /* TTDPatch version */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2278
			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
  2279
			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
  2280
			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
  2281
			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
  2282
			return (major << 24) | (minor << 20) | (revision << 16) | build;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2283
		}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2284
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2285
		case 0x8D: /* TTD Version, 00=DOS, 01=Windows */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2286
			return !_use_dos_palette;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2287
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2288
		case 0x8E: /* Y-offset for train sprites */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2289
			return _traininfo_vehicle_pitch;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2290
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2291
		case 0x92: /* Game mode */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2292
			return _game_mode;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2293
5287
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  2294
		case 0x9A: /* Always -1 */
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  2295
			return -1;
94a6c3c924b2 (svn r7436) -Codechange: Add action7/9/D variable 0x9A (-1)
peter1138
parents: 5234
diff changeset
  2296
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2297
		case 0x9D: /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2298
			return 1;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2299
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2300
		case 0x9E: /* Miscellaneous GRF features */
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2301
			return _misc_grf_features;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  2302
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2303
		default:
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2304
			/* GRF Parameter */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2305
			if (param < 0x80) return _cur_grffile->param[param];
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2306
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2307
			/* In-game variable. */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2308
			grfmsg(GMS_WARN, "Unsupported in-game variable 0x%02X.", param);
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2309
			return -1;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2310
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2311
}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2312
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2313
/* Action 0x06 */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2314
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
  2315
{
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2316
	/* <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
  2317
	 *
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2318
	 * 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
  2319
	 *                 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
  2320
	 * 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
  2321
	 *                 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
  2322
	 *                 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
  2323
	 *                 were specified.
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2324
	 * 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
  2325
	 *                 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
  2326
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2327
	/* Preload the next sprite */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2328
	uint32 pos = FioGetPos();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2329
	uint16 num = FioReadWord();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2330
	uint8 type = FioReadByte();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2331
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2332
	/* 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
  2333
	if (type == 0xFF) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2334
		_preload_sprite = malloc(num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2335
		FioReadBlock(_preload_sprite, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2336
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2337
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2338
	/* 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
  2339
	FioSeekTo(pos, SEEK_SET);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2340
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2341
	if (type != 0xFF) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2342
		grfmsg(GMS_NOTICE, "CfgApply: Ignoring (next sprite is real, unsupported)");
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2343
		return;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2344
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2345
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2346
	/* 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
  2347
	buf++;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2348
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2349
	for (;;) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2350
		uint i;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2351
		uint param_num;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2352
		uint param_size;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2353
		uint offset;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2354
		bool add_value;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2355
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2356
		/* 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
  2357
		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
  2358
		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
  2359
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2360
		/* 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
  2361
		 * 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
  2362
		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
  2363
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2364
		/* 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
  2365
		 * instead of replacing it. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2366
		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
  2367
		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
  2368
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2369
		/* 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
  2370
		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
  2371
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2372
		/* 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
  2373
		 * 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
  2374
		if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur_grffile->param_end) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2375
			grfmsg(GMS_NOTICE, "CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2376
			break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2377
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2378
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2379
		DEBUG(grf, 8) ("CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2380
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2381
		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
  2382
			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
  2383
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2384
			if (add_value) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2385
				_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
  2386
			} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2387
				_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
  2388
			}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2389
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2390
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2391
}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  2392
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2393
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2394
/* Action 0x09 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2395
static void SkipIf(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2396
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2397
	/* <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
  2398
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2399
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2400
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2401
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2402
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2403
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2404
	/* TODO: More params. More condition types. */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2405
	uint8 param;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2406
	uint8 paramsize;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2407
	uint8 condtype;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2408
	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
  2409
	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
  2410
	uint32 cond_val = 0;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2411
	uint32 mask = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2412
	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
  2413
	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
  2414
	GRFLabel *choice = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2416
	check_length(len, 6, "SkipIf");
3714
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2417
	buf++;
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2418
	param     = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2419
	paramsize = grf_load_byte(&buf);
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2420
	condtype  = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2421
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
  2422
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2423
		/* 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
  2424
		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
  2425
	}
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
  2426
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2427
	switch (paramsize) {
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2428
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2429
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2430
		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
  2431
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  2432
	}
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
  2433
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2434
	if (param < 0x80 && _cur_grffile->param_end <= param) {
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2435
		DEBUG(grf, 7) ("Param %d undefined, skipping test", param);
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2436
		return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2437
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2438
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2439
	param_val = GetParamVal(param, &cond_val);
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  2440
3630
0f7828d892ae (svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents: 3628
diff changeset
  2441
	DEBUG(grf, 7) ("Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2442
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2443
	if (param == 0x88) {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2444
		/* GRF ID checks */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2445
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2446
		const GRFConfig *c = GetGRFConfig(cond_val);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2447
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2448
		if (condtype != 10 && c == NULL) {
5406
321f494e7b68 (svn r7979) [0.5] - Fix: Segfault in the newgrf loading code (grfmsg => DEBUG). Do it in the right directory this time. Sorry for da mess :S
celestar
parents: 5399
diff changeset
  2449
			DEBUG(grf, 7) ("GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val));
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2450
			return;
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
  2451
		}
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
  2452
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2453
		switch (condtype) {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2454
			/* Tests 6 to 10 are only for param 0x88, GRFID checks */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2455
			case 6: /* Is GRFID active? */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2456
				result = HASBIT(c->flags, GCF_ACTIVATED);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2457
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2458
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2459
			case 7: /* Is GRFID non-active? */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2460
				result = !HASBIT(c->flags, GCF_ACTIVATED);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2461
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2462
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2463
			case 8: /* GRFID is not but will be active? */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2464
				result = !HASBIT(c->flags, GCF_ACTIVATED) && !HASBIT(c->flags, GCF_DISABLED);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2465
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2466
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2467
			case 9: /* GRFID is or will be active? */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2468
				result = !HASBIT(c->flags, GCF_NOT_FOUND) && !HASBIT(c->flags, GCF_DISABLED);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2469
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2470
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2471
			case 10: /* GRFID is not nor will be active */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2472
				/* This is the only condtype that doesn't get ignored if the GRFID is not found */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2473
				result = c == NULL || HASBIT(c->flags, GCF_DISABLED) || HASBIT(c->flags, GCF_NOT_FOUND);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2474
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2475
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2476
			default: grfmsg(GMS_WARN, "Unsupported GRF test %d. Ignoring", condtype); return;
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
  2477
		}
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2478
	} else {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2479
		/* Parameter or variable tests */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2480
		switch (condtype) {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2481
			case 0: result = !!(param_val & (1 << cond_val));
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2482
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2483
			case 1: result = !(param_val & (1 << cond_val));
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2484
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2485
			case 2: result = (param_val & mask) == cond_val;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2486
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2487
			case 3: result = (param_val & mask) != cond_val;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2488
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2489
			case 4: result = (param_val & mask) < cond_val;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2490
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2491
			case 5: result = (param_val & mask) > cond_val;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2492
				break;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2493
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2494
			default: grfmsg(GMS_WARN, "Unsupported test %d. Ignoring", condtype); return;
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
  2495
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2496
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2497
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  2498
	if (!result) {
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
  2499
		grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2500
		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
  2501
	}
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
  2502
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
  2503
	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
  2504
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
  2505
	/* 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
  2506
	 * 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
  2507
	 * 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
  2508
	 * 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
  2509
	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
  2510
		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
  2511
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
  2512
		/* 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
  2513
		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
  2514
		/* 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
  2515
		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
  2516
			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
  2517
			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
  2518
		}
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
  2519
	}
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
  2520
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
  2521
	if (choice != 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
  2522
		grfmsg(GMS_NOTICE, "Jumping to label 0x%0X at line %d, test was true.", choice->label, 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
  2523
		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
  2524
		_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
  2525
		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
  2526
	}
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
  2527
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
  2528
	grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2529
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2530
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2531
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2532
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2533
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2534
		_skip_sprites = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2535
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2536
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2537
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2538
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2539
/* Action 0x08 (GLS_FILESCAN) */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2540
static void ScanInfo(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
  2541
{
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2542
	uint8 version;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2543
	uint32 grfid;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2544
	const char *name;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2545
	const char *info;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2546
	int name_len;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2547
	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
  2548
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2549
	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
  2550
	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
  2551
	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
  2552
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2553
	_cur_grfconfig->grfid = grfid;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2554
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
  2555
	/* 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
  2556
	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
  2557
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2558
	len -= 6;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2559
	name = (const char*)buf;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2560
	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
  2561
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2562
	if (name_len < len) {
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2563
		_cur_grfconfig->name = TranslateTTDPatchCodes(name);
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2564
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2565
		len -= name_len + 1;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2566
		info = name + name_len + 1;
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2567
		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
  2568
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2569
		if (info_len < len) {
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2570
			_cur_grfconfig->info  = TranslateTTDPatchCodes(info);
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2571
		}
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  2572
	}
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
  2573
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
  2574
	/* 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
  2575
	_skip_sprites = -1;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2576
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  2577
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  2578
/* Action 0x08 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2579
static void GRFInfo(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2580
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2581
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2582
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2583
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2584
	 * 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
  2585
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2586
	 * 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
  2587
	/* TODO: Check version. (We should have own versioning done somehow.) */
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2588
	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
  2589
	uint32 grfid;
1329
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2590
	const char *name;
a8a0d60b0a8e (svn r1833) byte -> char transition: the rest
tron
parents: 1299
diff changeset
  2591
	const char *info;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2592
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
  2593
	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
  2594
	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
  2595
	grfid = grf_load_dword(&buf);
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2596
	name = grf_load_string(&buf, len - 6);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2597
	info = name + strlen(name) + 1;
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
  2598
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
  2599
	_cur_grffile->grfid = grfid;
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  2600
	_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
  2601
	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
  2602
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
  2603
	/* Do swap the GRFID for displaying purposes since people expect that */
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1968
diff changeset
  2604
	DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s",
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
  2605
	               _cur_grffile->filename, version, BSWAP32(grfid), name, info);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2606
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2607
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  2608
/* Action 0x0A */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2609
static void SpriteReplace(byte *buf, int len)
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
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2612
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2613
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2614
	 * 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
  2615
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2616
	 * 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
  2617
	 * 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
  2618
	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
  2619
	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
  2620
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
  2621
	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
  2622
	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
  2623
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
  2624
	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
  2625
		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
  2626
		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
  2627
		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
  2628
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
  2629
		grfmsg(GMS_NOTICE,
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
  2630
			"SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
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
  2631
			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
  2632
		);
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
  2633
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
  2634
		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
  2635
			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
  2636
			_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
  2637
		}
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
  2638
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2639
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2640
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  2641
/* Action 0x0B */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2642
static void GRFError(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2644
	/* <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
  2645
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2646
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2648
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2649
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2650
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2651
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2652
	 * 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
  2653
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2654
	 * 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
  2655
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2656
	 * 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
  2657
	 * 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
  2658
	/* 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
  2659
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2660
	static const char * const msgstr[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2661
		"Requires at least pseudo-TTDPatch version %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2662
		"This file is for %s version of TTD.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2663
		"Designed to be used with %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2664
		"Invalid parameter %s.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2665
	};
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2666
	uint8 severity;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2667
	uint8 msgid;
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2668
	const char *data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2669
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2670
	check_length(len, 6, "GRFError");
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2671
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2672
	buf++; /* Skip the action byte. */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2673
	severity = grf_load_byte(&buf);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2674
	buf++; /* TODO: Language id. */
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2675
	msgid = grf_load_byte(&buf);
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2676
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2677
	data = grf_load_string(&buf, len - 4);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2678
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2679
	// Undocumented TTDPatch feature.
5225
52ddcedcc6f7 (svn r7345) -Codechange: enumification of NewGRF loading stage, and move enum definition to header for future use.
peter1138
parents: 5211
diff changeset
  2680
	if ((severity & 0x80) == 0 && _cur_stage < GLS_ACTIVATION) {
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  2681
		DEBUG(grf, 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
  2682
		return;
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  2683
	}
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2684
	severity &= 0x7F;
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  2685
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2686
	if (msgid == 0xFF) {
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2687
		grfmsg(severity, "%s", data);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2688
	} else {
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2689
		grfmsg(severity, msgstr[msgid], data);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2690
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2691
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2692
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  2693
/* Action 0x0C */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2694
static void GRFComment(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2695
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2696
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2697
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2698
	 * 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
  2699
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
  2700
	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
  2701
5441
3b4236f6925e (svn r8861) [0.5] -Backport from trunk (r8526, r8792, r8825, r8843):
Darkvater
parents: 5406
diff changeset
  2702
	grfmsg(GMS_NOTICE, "GRFComment: %.*s", len - 1, (const char*)(buf + 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2703
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2704
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2705
/* Action 0x0D (GLS_SAFETYSCAN) */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2706
static void SafeParamSet(byte *buf, int len)
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2707
{
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2708
	uint8 target;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2709
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2710
	check_length(len, 5, "SafeParamSet");
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2711
	buf++;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2712
	target = grf_load_byte(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2713
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2714
	/* Only writing GRF parameters is considered safe */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2715
	if (target < 0x80) return;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2716
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2717
	/* GRM could be unsafe, but as here it can only happen after other GRFs
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2718
	 * are loaded, it should be okay. If the GRF tried to use the slots it
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2719
	 * reserved, it would be marked unsafe anyway. GRM for (e.g. bridge)
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2720
	 * sprites  is considered safe. */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2721
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2722
	SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2723
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2724
	/* Skip remainder of GRF */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2725
	_skip_sprites = -1;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2726
}
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  2727
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2728
/* Action 0x0D */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2729
static void ParamSet(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2730
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2731
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2732
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2733
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2734
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2735
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2736
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2737
	 * 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
  2738
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2739
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2740
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2741
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2742
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2743
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2744
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2745
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2746
	 * 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
  2747
	 *         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
  2748
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2749
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2750
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2751
	 */
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
  2752
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
  2753
	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
  2754
	byte oper;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2755
	uint32 src1;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2756
	uint32 src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2757
	uint32 data = 0;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2758
	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
  2759
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
  2760
	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
  2761
	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
  2762
	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
  2763
	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
  2764
	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
  2765
	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
  2766
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2767
	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
  2768
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
  2769
	/* 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
  2770
	 * 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
  2771
	 * 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
  2772
	 * - 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
  2773
	 * - 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
  2774
	 *   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
  2775
	if (oper & 0x80) {
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2776
		if (target < 0x80 && target < _cur_grffile->param_end) {
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2777
			DEBUG(grf, 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
  2778
			return;
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2779
		}
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2780
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  2781
		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
  2782
	}
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
  2783
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
  2784
	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
  2785
		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
  2786
			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
  2787
				/* Patch variables */
4918
0b274276f371 (svn r6894) - Codechange: Lower the verbosity level of some NewGRF warnings
peter1138
parents: 4893
diff changeset
  2788
				grfmsg(GMS_NOTICE, "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
  2789
				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
  2790
			} 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
  2791
				/* 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
  2792
				if (_cur_stage != GLS_ACTIVATION) {
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2793
					/* Ignore GRM during initialization */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2794
					src1 = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2795
				} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2796
					uint8  op      = src1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2797
					uint8  feature = GB(data, 8, 8);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2798
					uint16 count   = GB(data, 16, 16);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2799
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2800
					switch (feature) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2801
						case 0x00: /* Trains */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2802
						case 0x01: /* Road Vehicles */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2803
						case 0x02: /* Ships */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2804
						case 0x03: /* Aircraft */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2805
						{
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2806
							uint start = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2807
							uint size  = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2808
							uint shift = _vehshifts[feature];
4964
0ef1eb7e7f35 (svn r6963) - Fix (r6960): signed/unsigned complaints from MSVC
peter1138
parents: 4961
diff changeset
  2809
							int i;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2810
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2811
							if (op == 6) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2812
								/* 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
  2813
								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
  2814
								break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2815
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2816
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2817
							/* 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
  2818
							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
  2819
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2820
							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
  2821
								if (_grm_engines[shift + i] == 0) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2822
									size++;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2823
								} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2824
									if (op == 2 || op == 3) break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2825
									start = i + 1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2826
									size = 0;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2827
								}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2828
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2829
								if (size == count) break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2830
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2831
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2832
							if (size == count) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2833
								/* Got the slot... */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2834
								if (op == 0 || op == 3) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2835
									grfmsg(GMS_NOTICE, "GRM: Reserving %d vehicles at %d", count, start);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2836
									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
  2837
								}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2838
								src1 = start;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2839
							} else {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2840
								/* Unable to allocate */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2841
								if (op != 4 && op != 5) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2842
									/* Deactivate GRF */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2843
									grfmsg(GMS_FATAL, "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
  2844
									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
  2845
									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
  2846
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
  2847
									_skip_sprites = -1;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2848
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2849
								}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2850
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2851
								grfmsg(GMS_WARN, "GRM: Unable to allocate %d vehicles", count);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2852
								src1 = -1;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2853
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2854
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2855
						}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2856
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2857
						case 0x08: /* General sprites */
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2858
							switch (op) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2859
								case 0:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2860
									/* '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
  2861
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2862
									_cur_spriteid += count;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2863
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2864
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2865
								case 1:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2866
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2867
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2868
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2869
								default:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2870
									grfmsg(GMS_WARN, "GRM: Unsupported operation %d for general sprites", op);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2871
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2872
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2873
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2874
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2875
						default:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2876
							grfmsg(GMS_WARN, "GRM: Unsupported feature 0x%X", feature);
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2877
							return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2878
					}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  2879
				}
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
  2880
			}
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
  2881
		} 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
  2882
			/* 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
  2883
			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
  2884
			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
  2885
				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
  2886
			} 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
  2887
				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
  2888
			}
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
  2889
		}
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
  2890
	} 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
  2891
		/* 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
  2892
		 * 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
  2893
		 * 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
  2894
		 * 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
  2895
		 * of 0 is used instead.  */
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2896
		src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  2897
		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
  2898
	}
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
  2899
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
  2900
	/* 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
  2901
	 * 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
  2902
	 * 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
  2903
	 * 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
  2904
	 * 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
  2905
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
  2906
	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
  2907
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2908
			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
  2909
			break;
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
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2912
			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
  2913
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2914
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2915
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2916
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2917
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2918
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
  2919
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2920
			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
  2921
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2922
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
  2923
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2924
			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
  2925
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2926
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
  2927
		case 0x05:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2928
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2929
				res = src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2930
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2931
				res = src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2932
			}
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
  2933
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2934
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
  2935
		case 0x06:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2936
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2937
				res = (int32)src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2938
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2939
				res = (int32)src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  2940
			}
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
  2941
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2942
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2943
		case 0x07: /* Bitwise AND */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2944
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2945
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2946
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2947
		case 0x08: /* Bitwise OR */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2948
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2949
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2950
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2951
		case 0x09: /* Unsigned division */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2952
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2953
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2954
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2955
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2956
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2957
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2958
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2959
		case 0x0A: /* Signed divison */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2960
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2961
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2962
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2963
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2964
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2965
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2966
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2967
		case 0x0B: /* Unsigned modulo */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2968
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2969
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2970
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2971
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2972
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2973
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2974
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2975
		case 0x0C: /* Signed modulo */
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2976
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2977
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2978
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2979
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2980
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2981
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  2982
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
  2983
		default:
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
  2984
			grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2985
			return;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2986
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2987
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2988
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2989
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2990
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2991
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2992
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2993
		// TODO implement
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2994
		case 0x8F: // Rail track type cost factors
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2995
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2996
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2997
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2998
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  2999
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3000
		case 0x99: // Global ID offset
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3001
			DEBUG(grf, 7) ("ParamSet: Skipping unimplemented target 0x%02X", target);
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3002
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3003
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  3004
		case 0x9E: /* Miscellaneous GRF features */
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  3005
			_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
  3006
			/* 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
  3007
			_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
  3008
			break;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  3009
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3010
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3011
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3012
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3013
				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
  3014
			} else {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3015
				DEBUG(grf, 7) ("ParamSet: Skipping unknown target 0x%02X", target);
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3016
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  3017
			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
  3018
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3019
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3020
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3021
/* Action 0x0E (GLS_SAFETYSCAN) */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3022
static void SafeGRFInhibit(byte *buf, int len)
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3023
{
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3024
	/* <0E> <num> <grfids...>
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3025
	 *
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3026
	 * B num           Number of GRFIDs that follow
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3027
	 * D grfids        GRFIDs of the files to deactivate */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3028
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3029
	byte num;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3030
	int i;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3031
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3032
	check_length(len, 1, "GRFInhibit");
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3033
	buf++, len--;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3034
	num = grf_load_byte(&buf); len--;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3035
	check_length(len, 4 * num, "GRFInhibit");
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3036
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3037
	for (i = 0; i < num; i++) {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3038
		uint32 grfid = grf_load_dword(&buf);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3039
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3040
		/* GRF is unsafe it if tries to deactivate other GRFs */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3041
		if (grfid != _cur_grfconfig->grfid) {
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3042
			SETBIT(_cur_grfconfig->flags, GCF_UNSAFE);
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3043
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3044
			/* Skip remainder of GRF */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3045
			_skip_sprites = -1;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3046
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3047
			return;
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3048
		}
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3049
	}
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3050
}
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3051
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3052
/* Action 0x0E */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3053
static void GRFInhibit(byte *buf, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3054
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3055
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3056
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3057
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3058
	 * 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
  3059
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
  3060
	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
  3061
	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
  3062
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
  3063
	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
  3064
	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
  3065
	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
  3066
	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
  3067
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
  3068
	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
  3069
		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
  3070
		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
  3071
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
  3072
		/* Unset activation flag */
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5340
diff changeset
  3073
		if (file != NULL && file != _cur_grfconfig) {
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
  3074
			grfmsg(GMS_NOTICE, "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
  3075
			SETBIT(file->flags, GCF_DISABLED);
8e7d68b06399 (svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents: 5329
diff changeset
  3076
			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
  3077
		}
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
  3078
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3079
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3080
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  3081
/* 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
  3082
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
  3083
{
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
  3084
	/* <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
  3085
	 *
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
  3086
	 * 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
  3087
	 * 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
  3088
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
  3089
	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
  3090
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
  3091
	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
  3092
	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
  3093
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
  3094
	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
  3095
	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
  3096
	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
  3097
	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
  3098
	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
  3099
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
  3100
	/* 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
  3101
	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
  3102
		_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
  3103
	} 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
  3104
		/* 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
  3105
		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
  3106
		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
  3107
		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
  3108
	}
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
  3109
3630
0f7828d892ae (svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents: 3628
diff changeset
  3110
	grfmsg(GMS_NOTICE, "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
  3111
}
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
  3112
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3113
/* Action 0x11 */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3114
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
  3115
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3116
	/* <11> <num>
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3117
	 *
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3118
	 * 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
  3119
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3120
	uint16 num;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3121
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3122
	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
  3123
	buf++;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3124
	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
  3125
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3126
	_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
  3127
	_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
  3128
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3129
	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
  3130
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3131
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3132
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
  3133
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3134
	const GRFFile *file;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3135
	FileEntry *se = AllocateFileEntry();
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3136
	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
  3137
	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
  3138
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3139
	file = GetFileByGRFID(grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3140
	if (file == NULL || file->sound_offset == 0) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3141
		grfmsg(GMS_WARN, "ImportGRFSound: Source file not available.");
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3142
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3143
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3144
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3145
	if (file->sound_offset + sound >= GetNumSounds()) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3146
		grfmsg(GMS_WARN, "ImportGRFSound: Sound effect %d is invalid.", sound);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3147
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3148
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3149
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3150
	grfmsg(GMS_NOTICE, "ImportGRFSound: Copying sound %d (%d) from file %X", sound, file->sound_offset + sound, grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3151
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  3152
	*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
  3153
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3154
	/* 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
  3155
	se->volume   = 128;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3156
	se->priority = 0;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3157
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3158
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3159
/* 'Action 0xFE' */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3160
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
  3161
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3162
	if (_grf_data_blocks == 0) {
4918
0b274276f371 (svn r6894) - Codechange: Lower the verbosity level of some NewGRF warnings
peter1138
parents: 4893
diff changeset
  3163
		grfmsg(GMS_NOTICE, "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
  3164
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3165
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3166
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3167
	buf++;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3168
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3169
	_grf_data_blocks--;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3170
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3171
	/* 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
  3172
	 * 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
  3173
	if (grf_load_byte(&buf) != _grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3174
		grfmsg(GMS_WARN, "GRFImportBlock: Import type mismatch.");
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3175
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3176
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3177
	switch (_grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3178
		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
  3179
		default: NOT_REACHED(); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3180
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3181
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3182
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3183
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
  3184
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3185
	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
  3186
	FileEntry *se;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3187
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3188
	/* 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
  3189
	 * 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
  3190
	se = AllocateFileEntry();
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3191
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3192
	if (grf_load_dword(&buf) != 'FFIR') {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3193
		grfmsg(GMS_WARN, "LoadGRFSound: Missing RIFF header");
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3194
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3195
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3196
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3197
	/* 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
  3198
	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
  3199
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3200
	if (grf_load_dword(&buf) != 'EVAW') {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3201
		grfmsg(GMS_WARN, "LoadGRFSound: Invalid RIFF type");
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3202
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3203
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3204
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3205
	for (;;) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3206
		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
  3207
		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
  3208
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3209
		switch (tag) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3210
			case ' tmf': /* 'fmt ' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3211
				/* 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
  3212
				if (grf_load_word(&buf) != 1) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3213
					grfmsg(GMS_WARN, "LoadGRFSound: Invalid audio format");
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3214
					return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3215
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3216
				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
  3217
				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
  3218
				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
  3219
				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
  3220
				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
  3221
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3222
				/* 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
  3223
				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
  3224
				break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3225
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3226
			case 'atad': /* 'data' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3227
				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
  3228
				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
  3229
				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
  3230
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3231
				/* 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
  3232
				se->volume = 0x80;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3233
				se->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3234
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3235
				grfmsg(GMS_NOTICE, "LoadGRFSound: channels %u, sample rate %u, bits per sample %u, length %u", se->channels, se->rate, se->bits_per_sample, size);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3236
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3237
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3238
			default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3239
				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
  3240
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3241
		}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3242
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3243
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3244
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
  3245
/* 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
  3246
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
  3247
{
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
  3248
	/* <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
  3249
	 *
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
  3250
	 * 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
  3251
	 * 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
  3252
	 * 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
  3253
	 * 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
  3254
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
  3255
	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
  3256
	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
  3257
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
  3258
	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
  3259
	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
  3260
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
  3261
	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
  3262
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
  3263
	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
  3264
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
  3265
	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
  3266
		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
  3267
		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
  3268
		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
  3269
		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
  3270
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
  3271
		DEBUG(grf, 7) ("LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
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
  3272
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
  3273
		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
  3274
			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
  3275
			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
  3276
			_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
  3277
		}
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
  3278
	}
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
  3279
}
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
  3280
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3281
/* 'Action 0xFF' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3282
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
  3283
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3284
	byte name_len;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3285
	const char *name;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3286
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3287
	if (_grf_data_blocks == 0) {
4918
0b274276f371 (svn r6894) - Codechange: Lower the verbosity level of some NewGRF warnings
peter1138
parents: 4893
diff changeset
  3288
		grfmsg(GMS_NOTICE, "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
  3289
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3290
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3291
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3292
	buf++;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3293
	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
  3294
	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
  3295
	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
  3296
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3297
	grfmsg(GMS_NOTICE, "GRFDataBlock: block name '%s'...", name);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3298
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3299
	_grf_data_blocks--;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3300
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3301
	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
  3302
		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
  3303
		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
  3304
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3305
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3306
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
  3307
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
  3308
/* 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
  3309
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
  3310
{
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
  3311
	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
  3312
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3313
	/* Skip remainder of GRF */
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3314
	_skip_sprites = -1;
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
  3315
}
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
  3316
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
  3317
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
  3318
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
  3319
{
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3320
	_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
  3321
	                   |                                        (1 << 0x0D)  // newairports
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3322
	                   |                                        (1 << 0x0E)  // largestations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3323
	                   |           ((_patches.longbridges ? 1 : 0) << 0x0F)  // longbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3324
	                   |                                        (0 << 0x10)  // loadtime
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3325
	                   |                                        (1 << 0x12)  // presignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3326
	                   |                                        (1 << 0x13)  // extpresignals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3327
	                   | ((_patches.never_expire_vehicles ? 1 : 0) << 0x16)  // enginespersist
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3328
	                   |                                        (1 << 0x1B)  // multihead
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3329
	                   |                                        (1 << 0x1D)  // lowmemory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3330
	                   |                                        (1 << 0x1E); // generalfixes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3331
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3332
	_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
  3333
	                   |        ((_patches.mammoth_trains ? 1 : 0) << 0x08)  // mammothtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3334
	                   |                                        (1 << 0x09)  // trainrefit
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3335
	                   |                                        (0 << 0x0B)  // subsidiaries
5399
1bd8a20f6257 (svn r7956) -Backport from trunk (r7930):
Darkvater
parents: 5393
diff changeset
  3336
	                   |       ((_patches.gradual_loading ? 1 : 0) << 0x0C)  // gradualloading
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3337
	                   |                                        (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
  3338
	                   |                                        (1 << 0x13)  // unifiedmaglevmode - set bit 1 mode
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3339
	                   |                                        (1 << 0x14)  // bridgespeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3340
	                   |                                        (1 << 0x16)  // eternalgame
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3341
	                   |                                        (1 << 0x17)  // newtrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3342
	                   |                                        (1 << 0x18)  // newrvs
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3343
	                   |                                        (1 << 0x19)  // newships
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3344
	                   |                                        (1 << 0x1A)  // newplanes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3345
	                   |           ((_patches.signal_side ? 1 : 0) << 0x1B)  // signalsontrafficside
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3346
	                   |                                        (1 << 0x1C); // electrifiedrailway
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3347
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3348
	_ttdpatch_flags[2] =                                        (1 << 0x01)  // loadallgraphics - obsolote
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3349
	                   |                                        (1 << 0x03)  // semaphores
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3350
	                   |                                        (0 << 0x0B)  // enhancedgui
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3351
	                   |                                        (0 << 0x0C)  // newagerating
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3352
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x0D)  // buildonslopes
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3353
	                   |                                        (0 << 0x0F)  // planespeed
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3354
	                   |                                        (0 << 0x10)  // moreindustriesperclimate - obsolete
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3355
	                   |                                        (0 << 0x11)  // moretoylandfeatures
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3356
	                   |                                        (1 << 0x12)  // newstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3357
	                   |                                        (0 << 0x13)  // tracktypecostdiff
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3358
	                   |                                        (0 << 0x14)  // manualconvert
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3359
	                   |       ((_patches.build_on_slopes ? 1 : 0) << 0x15)  // buildoncoasts
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3360
	                   |                                        (1 << 0x16)  // canals
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3361
	                   |                                        (1 << 0x17)  // newstartyear
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3362
	                   |                                        (0 << 0x18)  // freighttrains
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3363
	                   |                                        (0 << 0x19)  // newhouses
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3364
	                   |                                        (1 << 0x1A)  // newbridges
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3365
	                   |                                        (0 << 0x1B)  // newtownnames
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3366
	                   |                                        (0 << 0x1C)  // moreanimations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3367
	                   |    ((_patches.wagon_speed_limits ? 1 : 0) << 0x1D)  // wagonspeedlimits
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3368
	                   |                                        (1 << 0x1E)  // newshistory
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3369
	                   |                                        (0 << 0x1F); // custombridgeheads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3370
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3371
	_ttdpatch_flags[3] =                                        (0 << 0x00)  // newcargodistribution
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3372
	                   |                                        (1 << 0x01)  // windowsnap
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3373
	                   |                                        (0 << 0x02)  // townbuildnoroad
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3374
	                   |                                        (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
  3375
	                   |                                        (0 << 0x04)  // aichoosechance
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3376
	                   |                                        (1 << 0x05)  // resolutionwidth
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3377
	                   |                                        (1 << 0x06)  // resolutionheight
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3378
	                   |                                        (0 << 0x07)  // newindustries
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3379
	                   |                                        (0 << 0x08)  // fifoloading
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3380
	                   |                                        (0 << 0x09)  // townroadbranchprob
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3381
	                   |                                        (0 << 0x0A)  // tempsnowline
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3382
	                   |                                        (0 << 0x0B)  // newcargo
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3383
	                   |                                        (1 << 0x0C)  // enhancemultiplayer
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3384
	                   |                                        (1 << 0x0D)  // onewayroads
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3385
	                   |   ((_patches.nonuniform_stations ? 1 : 0) << 0x0E)  // irregularstations
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3386
	                   |                                        (1 << 0x0F)  // statistics
4657
188335e8d316 (svn r6533) - Fix (r6532): Somebody forgot to add newsounds to the ttdpatch flags...
peter1138
parents: 4656
diff changeset
  3387
	                   |                                        (1 << 0x10)  // newsounds
4381
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3388
	                   |                                        (1 << 0x11)  // autoreplace
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3389
	                   |                                        (1 << 0x12)  // autoslope
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3390
	                   |                                        (0 << 0x13)  // followvehicle
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3391
	                   |                                        (0 << 0x14)  // trams
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3392
	                   |                                        (0 << 0x15)  // enhancetunnels
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3393
	                   |                                        (0 << 0x16)  // shortrvs
c1af6c934040 (svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
belugas
parents: 4377
diff changeset
  3394
	                   |                                        (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
  3395
}
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
  3396
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3397
static void ResetCustomStations(void)
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3398
{
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3399
	StationSpec *statspec;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3400
	GRFFile *file;
2627
8c964f74bd7b (svn r3169) Little bit of coding style fixing, and change from value to lengthof()
peter1138
parents: 2625
diff changeset
  3401
	uint i;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3402
	uint t;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3403
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3404
	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
  3405
		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
  3406
		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
  3407
			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
  3408
			statspec = file->stations[i];
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3409
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3410
			/* 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
  3411
			if (!statspec->copied_renderdata) {
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3412
				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
  3413
					free((void*)statspec->renderdata[t].seq);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3414
				}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3415
				free(statspec->renderdata);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3416
			}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  3417
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3418
			/* Release platforms and layouts */
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3419
			if (!statspec->copied_layouts) {
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3420
				uint l, p;
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3421
				for (l = 0; l < statspec->lengths; l++) {
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3422
					for (p = 0; p < statspec->platforms[l]; p++) {
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3423
						free(statspec->layouts[l][p]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3424
					}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3425
					free(statspec->layouts[l]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3426
				}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3427
				free(statspec->layouts);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3428
				free(statspec->platforms);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  3429
			}
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
  3430
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
  3431
			/* 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
  3432
			free(statspec);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3433
		}
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
  3434
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
  3435
		/* 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
  3436
		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
  3437
		file->stations = NULL;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3438
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3439
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3440
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3441
static void ResetNewGRF(void)
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3442
{
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3443
	GRFFile *f, *next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3444
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3445
	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
  3446
		next = f->next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3447
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3448
		free(f->filename);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3449
		free(f);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3450
	}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3451
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3452
	_first_grffile = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3453
	_cur_grffile   = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3454
}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3455
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3456
/**
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
  3457
 * 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
  3458
 * 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
  3459
 */
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
  3460
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
  3461
{
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3462
	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
  3463
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3464
	CleanUpStrings();
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3465
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
  3466
	// 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
  3467
	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
  3468
	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
  3469
	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
  3470
	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
  3471
	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
  3472
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
  3473
	// 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
  3474
	// 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
  3475
	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
  3476
		if (_bridge[i].sprite_table != NULL) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3477
			uint j;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3478
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3479
			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
  3480
			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
  3481
		}
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
  3482
	}
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
  3483
	memcpy(&_bridge, &orig_bridge, sizeof(_bridge));
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3484
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3485
	// Reset refit/cargo class data
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3486
	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
  3487
	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
  3488
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3489
	// Reset GRM reservations
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  3490
	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
  3491
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3492
	// Unload sprite group data
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3493
	UnloadWagonOverrides();
3695
aae28fa7190e (svn r4632) - NewGRF: support loading of helicopter rotor sprites (mart3p)
peter1138
parents: 3694
diff changeset
  3494
	UnloadRotorOverrideSprites();
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  3495
	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
  3496
	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
  3497
	ResetEngineListOrder();
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  3498
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  3499
	// Reset price base data
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  3500
	ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3501
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  3502
	/* Reset the curencies array */
5480
497f842b10bf (svn r9471) [0.5] -Backport from trunk (r9467 & r9469):
belugas
parents: 5447
diff changeset
  3503
	ResetCurrencies(false);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  3504
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3505
	// Reset station classes
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3506
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  3507
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  3508
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3509
	/* Reset NewGRF files */
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3510
	ResetNewGRF();
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  3511
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  3512
	// 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
  3513
	AddTypeToEngines();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3514
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
  3515
	/* 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
  3516
	_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
  3517
	_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
  3518
	_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
  3519
	_have_2cc = false;
5209
fa3ad39e2fa7 (svn r7324) -Codechange: reset newgrf signal location data
peter1138
parents: 5161
diff changeset
  3520
	_signal_base = 0;
5210
dc52acfad05c (svn r7325) -Feature: Add support for action 5 type 0x0D, coast sprites.
peter1138
parents: 5209
diff changeset
  3521
	_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
  3522
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3523
	InitializeSoundPool();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3524
	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
  3525
}
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
  3526
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
  3527
/** 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
  3528
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
  3529
{
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
  3530
	/* 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
  3531
	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
  3532
	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
  3533
		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
  3534
		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
  3535
		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
  3536
	}
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
  3537
	_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
  3538
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3539
	/* 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
  3540
	free(_cur_grffile->spritegroups);
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3541
	_cur_grffile->spritegroups = NULL;
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  3542
	_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
  3543
}
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
  3544
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
  3545
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
  3546
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  3547
	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
  3548
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
  3549
	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
  3550
	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
  3551
		/* 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
  3552
		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
  3553
		_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
  3554
		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
  3555
	}
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
  3556
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
  3557
	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
  3558
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3559
	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
  3560
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
  3561
	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
  3562
	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
  3563
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
  3564
	/* 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
  3565
	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
  3566
	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
  3567
	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
  3568
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
  3569
	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
  3570
		_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
  3571
		_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
  3572
	} 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
  3573
		_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
  3574
		_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
  3575
	}
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
  3576
}
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
  3577
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3578
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3579
/** 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
  3580
 * 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
  3581
 * 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
  3582
#define MC(cargo) (1 << cargo)
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3583
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
  3584
	/* Trains */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3585
	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
  3586
	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
  3587
	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
  3588
	/* 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
  3589
	0,
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3590
	/* Ships */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3591
	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
  3592
	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
  3593
	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
  3594
	/* Aircraft */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3595
	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
  3596
	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
  3597
	/* Special/Disaster */
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3598
	0,0
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3599
};
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3600
#undef MC
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3601
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  3602
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3603
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3604
 * 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
  3605
 */
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3606
static void CalculateRefitMasks(void)
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3607
{
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3608
	EngineID engine;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3609
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3610
	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
  3611
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3612
		uint32 not_mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3613
		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
  3614
		byte i;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3615
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3616
		if (cargo_allowed[engine] != 0) {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3617
			// 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
  3618
			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
  3619
				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
  3620
				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
  3621
			}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3622
		} else {
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3623
			// 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
  3624
			if (xor_mask == 0 && (
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3625
						GetEngine(engine)->type != VEH_Train || (
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3626
							RailVehInfo(engine)->capacity != 0 &&
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3627
							!(RailVehInfo(engine)->flags & RVI_WAGON)
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3628
						)
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  3629
					)) {
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3630
				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
  3631
			}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3632
		}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3633
		_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
  3634
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3635
}
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
  3636
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3637
/* 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
  3638
 * 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
  3639
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3640
/* 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
  3641
 * 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
  3642
 * 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
  3643
static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3644
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  3645
	/* 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
  3646
	 * 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
  3647
	 * 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
  3648
	 * "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
  3649
	 * 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
  3650
	 * 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
  3651
	 * 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
  3652
	 * 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
  3653
	 * --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
  3654
	/* 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
  3655
	 * 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
  3656
	 * 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
  3657
	static const SpecialSpriteHandler handlers[][GLS_END] = {
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3658
		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       NULL,       FeatureChangeInfo, },
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
  3659
		/* 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
  3660
		/* 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
  3661
		/* 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
  3662
		/* 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
  3663
		/* 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
  3664
		/* 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
  3665
		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,       SkipIf, },
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3666
		/* 0x08 */ { ScanInfo, NULL,      NULL,            GRFInfo,    GRFInfo, },
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
  3667
		/* 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
  3668
		/* 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
  3669
		/* 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
  3670
		/* 0x0C */ { NULL,     NULL,      NULL,            GRFComment, GRFComment, },
5389
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3671
		/* 0x0D */ { NULL,     SafeParamSet, NULL,         ParamSet,   ParamSet, },
43b0814ea5fa (svn r7946) -Backport from trunk (r7711, r7795, r7831):
Darkvater
parents: 5366
diff changeset
  3672
		/* 0x0E */ { NULL,     SafeGRFInhibit, NULL,       GRFInhibit, GRFInhibit, },
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
  3673
		/* 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
  3674
		/* 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
  3675
		/* 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
  3676
		/* 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
  3677
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3678
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3679
	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
  3680
	byte action;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3681
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3682
	if (_preload_sprite == NULL) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3683
		/* 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
  3684
		 * pseudo sprite content. */
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3685
		buf = malloc(num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3686
		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
  3687
		FioReadBlock(buf, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3688
	} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3689
		/* 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
  3690
		buf = _preload_sprite;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3691
		_preload_sprite = NULL;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3692
		DEBUG(grf, 7) ("DecodeSpecialSprite: Using preloaded pseudo sprite data");
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3693
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3694
		/* 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
  3695
		FioSeekTo(num, SEEK_CUR);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3696
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3697
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
  3698
	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
  3699
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3700
	if (action == 0xFF) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3701
		DEBUG(grf, 7) ("Handling data block in stage %d", stage);
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  3702
		GRFDataBlock(buf, num);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3703
	} else if (action == 0xFE) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3704
		DEBUG(grf, 7) ("Handling import block in stage %d", stage);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  3705
		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
  3706
	} else if (action >= lengthof(handlers)) {
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
  3707
		DEBUG(grf, 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
  3708
	} else if (handlers[action][stage] == NULL) {
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
  3709
		DEBUG(grf, 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
  3710
	} else {
964bd8fe3ce2 (svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents: 2628
diff changeset
  3711
		DEBUG(grf, 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
  3712
		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
  3713
	}
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
  3714
	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
  3715
}
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
  3716
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
  3717
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3718
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
  3719
{
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3720
	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
  3721
	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
  3722
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
  3723
	/* 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
  3724
	 * 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
  3725
	 * 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
  3726
	 * 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
  3727
	 * 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
  3728
	 *
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
  3729
	 * 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
  3730
	 * 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
  3731
	 * 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
  3732
	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
  3733
		_cur_grffile = GetFileByFilename(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
  3734
		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
  3735
		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
  3736
	}
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
  3737
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
  3738
	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
  3739
	_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
  3740
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3741
	_cur_grfconfig = config;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3742
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
  3743
	DEBUG(grf, 7) ("Reading NewGRF-file '%s'", 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
  3744
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
  3745
	/* 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
  3746
	 * 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
  3747
	 * 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
  3748
	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
  3749
		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
  3750
	} else {
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3751
		DEBUG(grf, 7) ("Custom .grf has invalid format.");
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3752
		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
  3753
	}
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
  3754
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
  3755
	_skip_sprites = 0; // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  3756
	_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
  3757
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
  3758
	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
  3759
		byte type = FioReadByte();
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  3760
		_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
  3761
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
  3762
		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
  3763
			if (_skip_sprites == 0) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2935
diff changeset
  3764
				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
  3765
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
  3766
				/* 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
  3767
				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
  3768
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
  3769
				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
  3770
			} 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
  3771
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3772
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3773
		} else {
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
  3774
			if (_skip_sprites == 0) DEBUG(grf, 7) ("Skipping unexpected 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
  3775
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
  3776
			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
  3777
			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
  3778
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
  3779
			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
  3780
				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
  3781
			} 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
  3782
				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
  3783
					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
  3784
					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
  3785
						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
  3786
						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
  3787
					} 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
  3788
						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
  3789
						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
  3790
						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
  3791
					}
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
  3792
				}
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
  3793
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  3794
		}
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
  3795
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
  3796
		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
  3797
	}
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
  3798
}
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
  3799
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
  3800
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
  3801
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
  3802
{
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
  3803
	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
  3804
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  3805
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3806
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
  3807
	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
  3808
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
  3809
	/* 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
  3810
	 * 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
  3811
	 * 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
  3812
	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
  3813
		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
  3814
		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
  3815
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
  3816
		_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
  3817
		_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
  3818
		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
  3819
			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
  3820
4201
3004bdee457d (svn r5685) - Codechange: s/FiosCheckFileExists/FioCheckFileExists/ to unify the naming of these functions.
Darkvater
parents: 4138
diff changeset
  3821
			if (!FioCheckFileExists(c->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
  3822
				// TODO: usrerror()
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
  3823
				error("NewGRF file missing: %s", c->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
  3824
			}
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
  3825
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
  3826
			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
  3827
			LoadNewGRFFile(c, slot++, stage);
5393
55e249a41db4 (svn r7950) -Backport from trunk (r7760, r7766):
Darkvater
parents: 5389
diff changeset
  3828
55e249a41db4 (svn r7950) -Backport from trunk (r7760, r7766):
Darkvater
parents: 5389
diff changeset
  3829
			if (stage == GLS_ACTIVATION) {
55e249a41db4 (svn r7950) -Backport from trunk (r7760, r7766):
Darkvater
parents: 5389
diff changeset
  3830
				ClearTemporaryNewGRFData();
55e249a41db4 (svn r7950) -Backport from trunk (r7760, r7766):
Darkvater
parents: 5389
diff changeset
  3831
				DEBUG(spritecache, 2) ("Currently %i sprites are loaded", _cur_spriteid);
55e249a41db4 (svn r7950) -Backport from trunk (r7760, r7766):
Darkvater
parents: 5389
diff changeset
  3832
			}
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
  3833
		}
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
  3834
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3835
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  3836
	// 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
  3837
	CalculateRefitMasks();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3838
}
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  3839