src/newgrf.cpp
author richk
Tue, 17 Jun 2008 13:22:13 +0000
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
permissions -rw-r--r--
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
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
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
     3
/** @file newgrf.cpp Base of all NewGRF support. */
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     9
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1183
diff changeset
    10
#include "debug.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "fileio.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    12
#include "engine_func.h"
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
    13
#include "engine_base.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
    14
#include "spritecache.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"
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
    18
#include "bridge.h"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
    19
#include "town.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
    20
#include "newgrf_engine.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
    21
#include "newgrf_text.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
    22
#include "fontcache.h"
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
    23
#include "currency.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
    24
#include "landscape.h"
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    25
#include "newgrf_config.h"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
    26
#include "newgrf_house.h"
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    27
#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
    28
#include "newgrf_spritegroup.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    29
#include "newgrf_station.h"
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6416
diff changeset
    30
#include "cargotype.h"
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
    31
#include "industry.h"
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
    32
#include "newgrf_canal.h"
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
    33
#include "newgrf_commons.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    34
#include "newgrf_townname.h"
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    35
#include "newgrf_industries.h"
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
    36
#include "newgrf_fsmports.h"
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    37
#include "gfxinit.h"
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
    38
#include "rev.h"
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    39
#include "fios.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    40
#include "rail.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    41
#include "strings_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    42
#include "gfx_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    43
#include "date_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    44
#include "vehicle_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    45
#include "sound_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    46
#include "string_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    47
#include "road_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    48
#include "player_base.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    49
#include "settings_type.h"
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
    50
#include "map_func.h"
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
    51
#include <map>
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
    52
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    53
#include "table/strings.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    54
#include "table/sprites.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    55
#include "table/town_land.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    56
#include "table/build_industry.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    57
#include "table/landscape_sprite.h"
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
    58
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
/* TTDPatch extended GRF format codec
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
 * (c) Petr Baudis 2004 (GPL'd)
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
    61
 * 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
    62
 *
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
 * Contains portions of documentation by TTDPatch team.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
 * 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
    65
 * 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
    66
 * 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
    67
455
e7ac799e1437 (svn r665) code fixes for newgrf.c/newgrf.h
dominik
parents: 452
diff changeset
    68
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
    69
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
    70
static uint _file_index; // XXX
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
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
    72
static GRFFile *_cur_grffile;
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
    73
GRFFile *_first_grffile;
3707
2999a89e8abd (svn r4650) - NewGRF: use the correct type for _cur_spriteid
peter1138
parents: 3704
diff changeset
    74
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
    75
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
    76
static uint32 _nfo_line;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
    78
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
    79
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
    80
/* 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
    81
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
    82
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
    83
/* 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
    84
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
    85
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
    86
/* 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
    87
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
    88
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
    89
/* Indicates which are the newgrf features currently loaded ingame */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    90
GRFLoadedFeatures _loaded_newgrf_features;
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
    91
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    92
enum GrfDataType {
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    93
	GDT_SOUND,
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    94
};
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    95
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    96
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
    97
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
    98
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
    99
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   100
typedef void (*SpecialSpriteHandler)(byte *buf, size_t len);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
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
   102
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
   103
	MAX_STATIONS = 256,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   104
	MAX_FSM_PORTS = 256,
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
   105
};
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
   106
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   107
/* Temporary data used when loading only */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   108
struct GRFTempEngineData {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   109
	uint16 cargo_allowed;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   110
	uint16 cargo_disallowed;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   111
};
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   112
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   113
static GRFTempEngineData *_gted;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   114
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   115
/* Contains the GRF ID of the owner of a vehicle if it has been reserved.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   116
 * GRM for vehicles is only used if dynamic engine allocation is disabled,
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   117
 * so 256 is the number of original engines. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   118
static uint32 _grm_engines[256];
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   119
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   120
/* Contains the GRF ID of the owner of a cargo if it has been reserved */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   121
static uint32 _grm_cargos[NUM_CARGO * 2];
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   122
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   123
struct GRFLocation {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   124
	uint32 grfid;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   125
	uint32 nfoline;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   126
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   127
	GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { }
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   128
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   129
	bool operator<(const GRFLocation &other) const
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   130
	{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   131
		return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   132
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   133
};
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   134
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   135
static std::map<GRFLocation, SpriteID> _grm_sprites;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   136
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   137
/** DEBUG() function dedicated to newGRF debugging messages
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   138
 * Function is essentialy the same as DEBUG(grf, severity, ...) with the
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   139
 * addition of file:line information when parsing grf files.
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   140
 * NOTE: for the above reason(s) grfmsg() should ONLY be used for
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   141
 * loading/parsing grf files, not for runtime debug messages as there
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   142
 * is no file information available during that time.
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   143
 * @param severity debugging severity level, see debug.h
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   144
 * @param str message in printf() format */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   145
void CDECL grfmsg(int severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
{
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   147
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   151
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   153
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   154
	DEBUG(grf, severity, "[%s:%d] %s", _cur_grfconfig->filename, _nfo_line, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   157
static inline bool check_length(size_t real, size_t wanted, const char *str)
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   158
{
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
   159
	if (real >= wanted) return true;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   160
	grfmsg(0, "%s: Invalid pseudo sprite length %d (expected %d)!", str, real, wanted);
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
   161
	return false;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   162
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   163
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   164
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
   165
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
{
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
   171
	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
   172
	return val | (grf_load_byte(buf) << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   175
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   176
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   177
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   178
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   179
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   180
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   181
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   182
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   183
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
{
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
   185
	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
   186
	return val | (grf_load_word(buf) << 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
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
   189
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
   190
{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   191
	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
   192
		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
   193
		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
   194
		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
   195
		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
   196
			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
   197
			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
   198
	}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
   199
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   200
6416
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   201
static const char *grf_load_string(byte **buf, size_t max_len)
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   202
{
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   203
	const char *string   = *(const char **)buf;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   204
	size_t string_length = ttd_strnlen(string, max_len);
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   205
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   206
	if (string_length == max_len) {
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   207
		/* String was not NUL terminated, so make sure it is now. */
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   208
		(*buf)[string_length - 1] = '\0';
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   209
		grfmsg(7, "String was not terminated with a zero byte.");
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   210
	} else {
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   211
		/* Increase the string length to include the NUL byte. */
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   212
		string_length++;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   213
	}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   214
	*buf += string_length;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   215
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   216
	return string;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   217
}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   218
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   219
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
   220
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   221
	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
   222
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   223
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   224
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   225
	}
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
   226
	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
   227
}
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
   228
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   229
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
   230
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   231
	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
   232
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   233
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   234
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   235
	}
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
   236
	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
   237
}
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
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
   240
typedef std::map<StringID *, uint32> StringIDToGRFIDMapping;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
   241
StringIDToGRFIDMapping _string_to_grf_mapping;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
   242
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   243
/** Used when setting an object's property to map to the GRF's strings
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   244
 * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   245
 * @param grfid Id of the grf file
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   246
 * @param str StringID that we want to have the equivalent in OoenTTD
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   247
 * @return the properly adjusted StringID
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   248
 */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   249
StringID MapGRFStringID(uint32 grfid, StringID str)
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   250
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   251
	/* StringID table for TextIDs 0x4E->0x6D */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   252
	static StringID units_volume[] = {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   253
		STR_NOTHING,    STR_PASSENGERS, STR_TONS,       STR_BAGS,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   254
		STR_LITERS,     STR_ITEMS,      STR_CRATES,     STR_TONS,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   255
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   256
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   257
		STR_TONS,       STR_TONS,       STR_BAGS,       STR_LITERS,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   258
		STR_TONS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   259
		STR_BAGS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   260
		STR_TONS,       STR_NOTHING,    STR_LITERS,     STR_NOTHING
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   261
	};
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   262
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   263
	/* 0xD0 and 0xDC stand for all the TextIDs in the range
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   264
	 * of 0xD000 (misc graphics texts) and 0xDC00 (misc persistent texts).
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   265
	 * These strings are unique to each grf file, and thus require to be used with the
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   266
	 * grfid in which they are declared */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   267
	switch (GB(str, 8, 8)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   268
		case 0xD0: case 0xD1: case 0xD2: case 0xD3:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   269
		case 0xDC:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   270
			return GetGRFStringID(grfid, str);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   271
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   272
		case 0xD4: case 0xD5: case 0xD6: case 0xD7:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   273
			/* Strings embedded via 0x81 have 0x400 added to them (no real
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   274
			 * explanation why...) */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   275
			return GetGRFStringID(grfid, str - 0x400);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   276
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   277
		default: break;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   278
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   279
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   280
#define TEXID_TO_STRINGID(begin, end, stringid) if (str >= begin && str <= end) return str + (stringid - begin)
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   281
	/* We have some changes in our cargo strings, resulting in some missing. */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   282
	TEXID_TO_STRINGID(0x000E, 0x002D, STR_000E);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   283
	TEXID_TO_STRINGID(0x002E, 0x004D, STR_002E);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   284
	if (str >= 0x004E && str <= 0x006D) str = units_volume[str - 0x004E];
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   285
	TEXID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   286
	TEXID_TO_STRINGID(0x008E, 0x00AD, STR_ABBREV_NOTHING);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
   287
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   288
	/* Map building names according to our lang file changes. There are several
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   289
	 * ranges of house ids, all of which need to be remapped to allow newgrfs
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   290
	 * to use original house names. */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   291
	TEXID_TO_STRINGID(0x200F, 0x201F, STR_200F_TALL_OFFICE_BLOCK);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   292
	TEXID_TO_STRINGID(0x2036, 0x2041, STR_2036_COTTAGES);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   293
	TEXID_TO_STRINGID(0x2059, 0x205C, STR_2059_IGLOO);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   294
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   295
	/* Same thing for industries, since the introduction of 4 new strings above STR_482A_PRODUCTION_LAST_MONTH */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   296
	TEXID_TO_STRINGID(0x482A, 0x483B, STR_482A_PRODUCTION_LAST_MONTH);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   297
#undef TEXTID_TO_STRINGID
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   298
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   299
	if (str == STR_NULL) return STR_EMPTY;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   300
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   301
	return str;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   302
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   303
6701
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   304
static uint8 MapDOSColour(uint8 colour)
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   305
{
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   306
	if (_use_dos_palette) return colour;
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   307
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   308
	if (colour < 10) {
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   309
		static uint8 dos_to_win_colour_map[] = { 0, 215, 216, 136, 88, 106, 32, 33, 40, 245 };
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   310
		return dos_to_win_colour_map[colour];
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   311
	}
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   312
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   313
	if (colour >= 245 && colour < 254) return colour - 28;
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   314
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   315
	return colour;
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   316
}
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   317
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   318
static std::map<uint32, uint32> _grf_id_overrides;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   319
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   320
static void SetNewGRFOverride(uint32 source_grfid, uint32 target_grfid)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   321
{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   322
	_grf_id_overrides[source_grfid] = target_grfid;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   323
	grfmsg(5, "SetNewGRFOverride: Added override of 0x%X to 0x%X", BSWAP32(source_grfid), BSWAP32(target_grfid));
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   324
}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   325
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   326
static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 internal_id)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   327
{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   328
	/* Hack for add-on GRFs that need to modify another GRF's engines. This lets
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   329
	 * them use the same engine slots. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   330
	const GRFFile *grf_match = NULL;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   331
	if (_settings_game.vehicle.dynamic_engines) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   332
		uint32 override = _grf_id_overrides[file->grfid];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   333
		if (override != 0) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   334
			grf_match = GetFileByGRFID(override);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   335
			if (grf_match == NULL) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   336
				grfmsg(5, "Tried mapping from GRFID %x to %x but target is not loaded", BSWAP32(file->grfid), BSWAP32(override));
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   337
			} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   338
				grfmsg(5, "Mapping from GRFID %x to %x", BSWAP32(file->grfid), BSWAP32(override));
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   339
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   340
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   341
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   342
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   343
	/* Check if this vehicle is already defined... */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   344
	Engine *e = NULL;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   345
	FOR_ALL_ENGINES(e) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   346
		if (_settings_game.vehicle.dynamic_engines && e->grffile != NULL && e->grffile != file && e->grffile != grf_match) continue;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   347
		if (e->type != type) continue;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   348
		if (e->internal_id != internal_id) continue;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   349
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   350
		if (e->grffile == NULL) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   351
			e->grffile = file;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   352
			grfmsg(5, "Replaced engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   353
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   354
		return e;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   355
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   356
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   357
	uint engine_pool_size = GetEnginePoolSize();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   358
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   359
	/* ... it's not, so create a new one based off an existing engine */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   360
	e = new Engine(type, internal_id);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   361
	e->grffile = file;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   362
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   363
	if (engine_pool_size != GetEnginePoolSize()) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   364
		/* Resize temporary engine data ... */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   365
		_gted = ReallocT(_gted, GetEnginePoolSize());
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   366
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   367
		/* and blank the new block. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   368
		size_t len = (GetEnginePoolSize() - engine_pool_size) * sizeof(*_gted);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   369
		memset(_gted + engine_pool_size, 0, len);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   370
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   371
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   372
	grfmsg(5, "Created new engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   373
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   374
	return e;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   375
}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   376
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   377
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   378
{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   379
	extern uint32 GetNewGRFOverride(uint32 grfid);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   380
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   381
	const GRFFile *grf_match = NULL;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   382
	if (_settings_game.vehicle.dynamic_engines) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   383
		uint32 override = _grf_id_overrides[file->grfid];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   384
		if (override != 0) grf_match = GetFileByGRFID(override);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   385
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   386
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   387
	const Engine *e = NULL;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   388
	FOR_ALL_ENGINES(e) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   389
		if (_settings_game.vehicle.dynamic_engines && e->grffile != file && (grf_match == NULL || e->grffile != grf_match)) continue;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   390
		if (e->type != type) continue;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   391
		if (e->internal_id != internal_id) continue;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   392
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   393
		return e->index;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   394
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   395
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   396
	return INVALID_ENGINE;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   397
}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   398
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   399
/** Map the colour modifiers of TTDPatch to those that Open is using.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   400
 * @param grf_sprite pointer to the structure been modified
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   401
 */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   402
static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite)
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   403
{
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   404
	if (HasBit(grf_sprite->pal, 14)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   405
		ClrBit(grf_sprite->pal, 14);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   406
		SetBit(grf_sprite->sprite, SPRITE_MODIFIER_OPAQUE);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   407
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   408
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   409
	if (HasBit(grf_sprite->sprite, 14)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   410
		ClrBit(grf_sprite->sprite, 14);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   411
		SetBit(grf_sprite->sprite, PALETTE_MODIFIER_TRANSPARENT);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   412
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   413
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   414
	if (HasBit(grf_sprite->sprite, 15)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   415
		ClrBit(grf_sprite->sprite, 15);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   416
		SetBit(grf_sprite->sprite, PALETTE_MODIFIER_COLOR);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   417
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   418
}
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   419
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   420
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
   421
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   422
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
   423
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	byte *buf = *bufp;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   425
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   427
	for (int i = 0; i < numinfo; i++) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   428
		Engine *e = GetNewEngine(_cur_grffile, VEH_TRAIN, engine + i);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   429
		EngineInfo *ei = &e->info;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   430
		RailVehicleInfo *rvi = &e->u.rail;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   431
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   432
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   433
			case 0x05: { // Track type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
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
   436
				switch (tracktype) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   437
					case 0: rvi->railtype = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   438
					case 1: rvi->railtype = RAILTYPE_MONO; break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   439
					case 2: rvi->railtype = RAILTYPE_MAGLEV; 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
   440
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   441
						grfmsg(1, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype);
3026
6401a6942660 (svn r3606) - NewGRF: Convert from TTDP railtype values to our own railtypes. (These are currently the same, but won't be forever...)
peter1138
parents: 3023
diff changeset
   442
						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
   443
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   444
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   445
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   446
			case 0x08: // AI passenger service
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   447
				/* Tells the AI that this engine is designed for
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   448
				 * passenger services and shouldn't be used for freight. */
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   449
				rvi->ai_passenger_only = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   450
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   451
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   452
			case 0x09: { // Speed (1 unit is 1 kmh)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
				uint16 speed = grf_load_word(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   454
				if (speed == 0xFFFF) speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   456
				rvi->max_speed = speed;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   457
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   458
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   459
			case 0x0B: // Power
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   460
				rvi->power = grf_load_word(&buf);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   461
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   462
				/* Set engine / wagon state based on power */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   463
				if (rvi->power != 0) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   464
					if (rvi->railveh_type == RAILVEH_WAGON) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   465
						rvi->railveh_type = RAILVEH_SINGLEHEAD;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   466
					}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   467
				} else {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   468
					rvi->railveh_type = RAILVEH_WAGON;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   469
				}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   470
				break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   471
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   472
			case 0x0D: // Running cost factor
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   473
				rvi->running_cost = grf_load_byte(&buf);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   474
				break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   475
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   476
			case 0x0E: { // Running cost base
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   479
				/* These magic numbers are used in GRFs to specify the base cost:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   480
				 * http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   481
				 */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   482
				if (base == 0) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   483
					rvi->running_cost_class = 0xFF;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   484
				} else if (base < 0x4B34 || base > 0x4C54 || (base - 0x4B34) % 6 != 0) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   485
					grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   486
				} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   487
					/* Convert the magic number to an index into the price data */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   488
					rvi->running_cost_class = (base - 0x4B34) / 6;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   490
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   491
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   492
			case 0x12: { // Sprite ID
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
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
   495
				/* 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
   496
				 * 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
   497
				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
   498
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   499
				rvi->image_index = spriteid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   500
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   501
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   502
			case 0x13: { // Dual-headed
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   505
				if (dual != 0) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   506
					rvi->railveh_type = RAILVEH_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   508
					rvi->railveh_type = rvi->power == 0 ?
6126
40a18030c3aa (svn r8465) -Regression (r8455): Switching from dual to single head should switch to wagon if power is zero. .Or something.
peter1138
parents: 6119
diff changeset
   509
						RAILVEH_WAGON : RAILVEH_SINGLEHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   511
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   512
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   513
			case 0x14: // Cargo capacity
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   514
				rvi->capacity = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   515
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   516
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   517
			case 0x15: { // Cargo type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   520
				if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   521
					rvi->cargo_type = ctype;
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   522
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   523
					rvi->cargo_type = CT_INVALID;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
   524
					grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   525
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   526
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   527
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   528
			case 0x16: // Weight
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   529
				SB(rvi->weight, 0, 8, grf_load_byte(&buf));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   530
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   531
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   532
			case 0x17: // Cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   533
				rvi->base_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   534
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   535
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   536
			case 0x18: // AI rank
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   537
				rvi->ai_rank = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   538
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   539
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   540
			case 0x19: { // Engine traction type
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   541
				/* What do the individual numbers mean?
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   542
				 * 0x00 .. 0x07: Steam
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   543
				 * 0x08 .. 0x27: Diesel
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   544
				 * 0x28 .. 0x31: Electric
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   545
				 * 0x32 .. 0x37: Monorail
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   546
				 * 0x38 .. 0x41: Maglev
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   547
				 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
				uint8 traction = grf_load_byte(&buf);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   549
				EngineClass engclass;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   551
				if (traction <= 0x07) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   552
					engclass = EC_STEAM;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   553
				} else if (traction <= 0x27) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   554
					engclass = EC_DIESEL;
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
   555
				} else if (traction <= 0x31) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   556
					engclass = EC_ELECTRIC;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   557
				} else if (traction <= 0x37) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   558
					engclass = EC_MONORAIL;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   559
				} else if (traction <= 0x41) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
   560
					engclass = EC_MAGLEV;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   561
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
					break;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   563
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   564
				if (rvi->railtype == RAILTYPE_RAIL     && engclass >= EC_ELECTRIC) rvi->railtype = RAILTYPE_ELECTRIC;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   565
				if (rvi->railtype == RAILTYPE_ELECTRIC && engclass  < EC_ELECTRIC) rvi->railtype = RAILTYPE_RAIL;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   566
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   567
				rvi->engclass = engclass;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   568
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   569
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   570
			case 0x1A: // Alter purchase list sort order
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   571
				AlterRailVehListOrder(e->index, grf_load_byte(&buf));
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   572
				break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   573
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   574
			case 0x1B: // Powered wagons power bonus
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   575
				rvi->pow_wag_power = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   576
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   577
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   578
			case 0x1C: // Refit cost
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   579
				ei->refit_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   580
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   581
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   582
			case 0x1D: // Refit cargo
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   583
				ei->refit_mask = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   584
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   585
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   586
			case 0x1E: // Callback
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   587
				ei->callbackmask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   588
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   589
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   590
			case 0x1F: // Tractive effort coefficient
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   591
				rvi->tractive_effort = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   592
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   593
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   594
			case 0x20: // Air drag
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   595
				/** @todo Air drag for trains. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   596
				grf_load_byte(&buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   597
				ret = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   598
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   599
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   600
			case 0x21: // Shorter vehicle
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   601
				rvi->shorten_factor = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   602
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   603
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   604
			case 0x22: // Visual effect
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   605
				/** @see note in engine.h about rvi->visual_effect */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   606
				rvi->visual_effect = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   607
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   608
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   609
			case 0x23: // Powered wagons weight bonus
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   610
				rvi->pow_wag_weight = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   611
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   612
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   613
			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
   614
				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
   615
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   616
				if (weight > 4) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   617
					grfmsg(2, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8);
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   618
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   619
					SB(rvi->weight, 8, 8, weight);
2542
fdea27216e48 (svn r3071) -NewGRF: Add support for rail vehicle weight greater than 255 tons.
peter1138
parents: 2530
diff changeset
   620
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   621
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   622
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   623
			case 0x25: // User-defined bit mask to set when checking veh. var. 42
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   624
				rvi->user_def_data = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   625
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   626
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   627
			case 0x26: // Retire vehicle early
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   628
				ei->retire_early = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   629
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   630
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   631
			case 0x27: // Miscellaneous flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   632
				ei->misc_flags = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   633
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   634
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   635
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   636
			case 0x28: // Cargo classes allowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   637
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   638
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   639
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   640
			case 0x29: // Cargo classes disallowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   641
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   642
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   643
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   644
			case 0x2A: // Long format introduction date (days since year 0)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   645
				ei->base_intro = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   646
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   647
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   648
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   649
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   650
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   651
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
	}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   653
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	return ret;
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
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   658
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
   659
{
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   660
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   661
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   662
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   663
	for (int i = 0; i < numinfo; i++) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   664
		Engine *e = GetNewEngine(_cur_grffile, VEH_ROAD, engine + i);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   665
		EngineInfo *ei = &e->info;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   666
		RoadVehicleInfo *rvi = &e->u.road;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   667
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   668
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   669
			case 0x08: // Speed (1 unit is 0.5 kmh)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   670
				rvi->max_speed = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   671
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   672
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   673
			case 0x09: // Running cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   674
				rvi->running_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   675
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   676
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   677
			case 0x0A: { // Running cost base
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   678
				uint32 base= grf_load_dword(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   679
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   680
				/* These magic numbers are used in GRFs to specify the base cost:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   681
				 * http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   682
				 */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   683
				if (base == 0) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   684
					rvi->running_cost_class = 0xFF;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   685
				} else if (base < 0x4B34 || base > 0x4C54 || (base - 0x4B34) % 6 != 0) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   686
					grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   687
				} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   688
					/* Convert the magic number to an index into the price data */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   689
					rvi->running_cost_class = (base - 0x4B34) / 6;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   690
				}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   691
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   692
				break;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   693
			}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   694
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   695
			case 0x0E: { // Sprite ID
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   696
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   697
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   698
				/* cars have different custom id in the GRF file */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   699
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   700
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   701
				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
   702
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   703
				rvi->image_index = spriteid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   704
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   705
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   706
			case 0x0F: // Cargo capacity
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   707
				rvi->capacity = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   708
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   709
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   710
			case 0x10: { // Cargo type
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   711
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   712
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   713
				if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   714
					rvi->cargo_type = cargo;
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   715
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   716
					rvi->cargo_type = CT_INVALID;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
   717
					grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   718
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   719
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   721
			case 0x11: // Cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   722
				rvi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   723
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   724
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   725
			case 0x12: // SFX
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   726
				rvi->sfx = (SoundFx)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   727
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   728
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   729
			case 0x13: // Power in 10hp
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   730
			case 0x14: // Weight in 1/4 tons
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   731
			case 0x15: // Speed in mph*0.8
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   732
				/** @todo Support for road vehicles realistic power
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   733
				 * computations (called rvpower in TTDPatch) is just
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   734
				 * missing in OTTD yet. --pasky */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   735
				grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   736
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   737
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   738
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   739
			case 0x16: // Cargos available for refitting
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   740
				ei->refit_mask = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   741
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   742
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   743
			case 0x17: // Callback mask
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   744
				ei->callbackmask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   745
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   746
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   747
			case 0x18: // Tractive effort
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   748
			case 0x19: // Air drag
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   749
				/** @todo Tractive effort and air drag for road vehicles. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   750
				grf_load_byte(&buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   751
				ret = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   752
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   753
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   754
			case 0x1A: // Refit cost
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   755
				ei->refit_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   756
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   757
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   758
			case 0x1B: // Retire vehicle early
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   759
				ei->retire_early = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   760
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   761
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   762
			case 0x1C: // Miscellaneous flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   763
				ei->misc_flags = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   764
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   765
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   766
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   767
			case 0x1D: // Cargo classes allowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   768
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   769
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   770
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   771
			case 0x1E: // Cargo classes disallowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   772
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   773
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   774
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   775
			case 0x1F: // Long format introduction date (days since year 0)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   776
				ei->base_intro = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   777
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   778
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   779
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   780
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   781
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   782
		}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   783
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   784
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   785
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   786
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   787
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   788
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   789
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
   790
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	byte *buf = *bufp;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   792
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   794
	for (int i = 0; i < numinfo; i++) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   795
		Engine *e = GetNewEngine(_cur_grffile, VEH_SHIP, engine + i);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   796
		EngineInfo *ei = &e->info;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   797
		ShipVehicleInfo *svi = &e->u.ship;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   798
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   799
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   800
			case 0x08: { // Sprite ID
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   803
				/* ships have different custom id in the GRF file */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   804
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   805
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   806
				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
   807
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   808
				svi->image_index = spriteid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   809
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   810
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   811
			case 0x09: // Refittable
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   812
				svi->refittable = (grf_load_byte(&buf) != 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   813
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   814
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   815
			case 0x0A: // Cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   816
				svi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   817
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   818
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   819
			case 0x0B: // Speed (1 unit is 0.5 kmh)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   820
				svi->max_speed = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   821
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   822
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   823
			case 0x0C: { // Cargo type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   826
				if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   827
					svi->cargo_type = cargo;
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   828
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   829
					svi->cargo_type = CT_INVALID;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
   830
					grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
2846
ac8731dd4121 (svn r3394) - NewGRF fix: ignore non-climate dependent cargo types. The spec is rather vague on this, but we don't support newcargos anyway.
peter1138
parents: 2840
diff changeset
   831
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   832
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   833
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   834
			case 0x0D: // Cargo capacity
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   835
				svi->capacity = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   836
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   837
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   838
			case 0x0F: // Running cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   839
				svi->running_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   840
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   841
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   842
			case 0x10: // SFX
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   843
				svi->sfx = (SoundFx)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   844
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   845
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   846
			case 0x11: // Cargos available for refitting
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   847
				ei->refit_mask = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   848
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   849
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   850
			case 0x12: // Callback mask
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   851
				ei->callbackmask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   852
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   853
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   854
			case 0x13: // Refit cost
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   855
				ei->refit_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   856
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   857
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   858
			case 0x14: // Ocean speed fraction
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   859
			case 0x15: // Canal speed fraction
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   860
				/** @todo Speed fractions for ships on oceans and canals */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   861
				grf_load_byte(&buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   862
				ret = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   863
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   864
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   865
			case 0x16: // Retire vehicle early
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   866
				ei->retire_early = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   867
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   868
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   869
			case 0x17: // Miscellaneous flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   870
				ei->misc_flags = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   871
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   872
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   873
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   874
			case 0x18: // Cargo classes allowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   875
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   876
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   877
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   878
			case 0x19: // Cargo classes disallowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   879
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   880
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   881
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   882
			case 0x1A: // Long format introduction date (days since year 0)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   883
				ei->base_intro = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   884
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   885
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   886
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   887
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   888
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   889
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
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
   896
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
   897
{
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
   898
	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
   899
	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
   900
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   901
	for (int i = 0; i < numinfo; i++) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   902
		Engine *e = GetNewEngine(_cur_grffile, VEH_AIRCRAFT, engine + i);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   903
		EngineInfo *ei = &e->info;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   904
		AircraftVehicleInfo *avi = &e->u.air;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   905
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   906
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   907
			case 0x08: { // Sprite ID
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
   908
				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
   909
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   910
				/* aircraft have different custom id in the GRF file */
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   911
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   912
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   913
				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
   914
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   915
				avi->image_index = spriteid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   916
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   917
6862
0b2c0e2b5356 (svn r10976) [NewGRF_ports] -Change: Additional changes to further support seaplanes. Checks now made in IsAircraftBuildable for seaplane requirement.
richk
parents: 6856
diff changeset
   918
			case 0x09: { // Helicopter
0b2c0e2b5356 (svn r10976) [NewGRF_ports] -Change: Additional changes to further support seaplanes. Checks now made in IsAircraftBuildable for seaplane requirement.
richk
parents: 6856
diff changeset
   919
				uint subtype = grf_load_byte(&buf);
0b2c0e2b5356 (svn r10976) [NewGRF_ports] -Change: Additional changes to further support seaplanes. Checks now made in IsAircraftBuildable for seaplane requirement.
richk
parents: 6856
diff changeset
   920
				if ((subtype & 0x03) == 0) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   921
					avi->subtype = AIR_HELI;
4926
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   922
				} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   923
					SB(avi->subtype, 0, 1, 1); // AIR_CTOL
4926
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   924
				}
6862
0b2c0e2b5356 (svn r10976) [NewGRF_ports] -Change: Additional changes to further support seaplanes. Checks now made in IsAircraftBuildable for seaplane requirement.
richk
parents: 6856
diff changeset
   925
			} break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   926
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   927
			case 0x0A: // Large
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   928
				SB(avi->subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   929
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   930
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   931
			case 0x0B: // Cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   932
				avi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   933
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   934
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   935
			case 0x0C: // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   936
				avi->max_speed = (grf_load_byte(&buf) * 129) / 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   937
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   938
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   939
			case 0x0D: // Acceleration
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   940
				avi->acceleration = (grf_load_byte(&buf) * 129) / 10;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   941
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   942
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   943
			case 0x0E: // Running cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   944
				avi->running_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   945
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   946
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   947
			case 0x0F: // Passenger capacity
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   948
				avi->passenger_capacity = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   949
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   950
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   951
			case 0x11: // Mail capacity
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   952
				avi->mail_capacity = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   953
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   954
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   955
			case 0x12: // SFX
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   956
				avi->sfx = (SoundFx)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   957
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   958
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   959
			case 0x13: // Cargos available for refitting
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   960
				ei->refit_mask = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   961
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   962
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   963
			case 0x14: // Callback mask
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   964
				ei->callbackmask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   965
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   966
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   967
			case 0x15: // Refit cost
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   968
				ei->refit_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   969
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   970
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   971
			case 0x16: // Retire vehicle early
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   972
				ei->retire_early = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   973
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   974
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   975
			case 0x17: // Miscellaneous flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   976
				ei->misc_flags = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   977
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
10305
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   978
				if ((ei->misc_flags & 0x06) == 0x06) {
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   979
					avi->airport_required = AIRPORT_SEA_ONLY;
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   980
				} else if ((ei->misc_flags & 0x04) == 0x04) {
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   981
					avi->airport_required = AIRPORT_SEA_OR_LAND;
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   982
				} else {
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   983
					avi->airport_required = AIRPORT_LAND_ONLY;
e90761e37744 (svn r12846) [NewGRF_ports] -Change: Added clearer support for seaplanes.
richk
parents: 10280
diff changeset
   984
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   985
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   986
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   987
			case 0x18: // Cargo classes allowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   988
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   989
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   990
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   991
			case 0x19: // Cargo classes disallowed
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
   992
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   993
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   994
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   995
			case 0x1A: // Long format introduction date (days since year 0)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   996
				ei->base_intro = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   997
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   998
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   999
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1000
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1001
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1002
		}
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
  1003
	}
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
  1004
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
  1005
	*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
  1006
	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
  1007
}
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
  1008
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1009
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
  1010
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1011
	byte *buf = *bufp;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1012
	bool ret = false;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1013
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
  1014
	if (stid + numinfo > MAX_STATIONS) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1015
		grfmsg(1, "StationChangeInfo: Station %u is invalid, max %u, ignoring", stid + numinfo, MAX_STATIONS);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1016
		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
  1017
	}
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
  1018
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
  1019
	/* Allocate station specs if necessary */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1020
	if (_cur_grffile->stations == NULL) _cur_grffile->stations = CallocT<StationSpec*>(MAX_STATIONS);
3768
46d328178509 (svn r4760) - Newstations: change the way custom stations are allocated when loading from GRF, as the current way was flawed (reallocing memory which is referenced elsewhere)
peter1138
parents: 3761
diff changeset
  1021
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1022
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1023
		StationSpec *statspec = _cur_grffile->stations[stid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1024
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1025
		/* Check that the station we are modifying is defined. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1026
		if (statspec == NULL && prop != 0x08) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1027
			grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1028
			continue;
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
  1029
		}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1030
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1031
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1032
			case 0x08: { // Class ID
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1033
				StationSpec **spec = &_cur_grffile->stations[stid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1034
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
  1035
				/* Property 0x08 is special; it is where the station is allocated */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1036
				if (*spec == NULL) *spec = CallocT<StationSpec>(1);
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
  1037
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
  1038
				/* Swap classid because we read it in BE meaning WAYP or DFLT */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1039
				uint32 classid = grf_load_dword(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1040
				(*spec)->sclass = AllocateStationClass(BSWAP32(classid));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1041
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1042
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1043
			case 0x09: // Define sprite layout
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1044
				statspec->tiles = grf_load_extended(&buf);
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1045
				statspec->renderdata = CallocT<DrawTileSprites>(statspec->tiles);
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1046
				statspec->copied_renderdata = false;
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1047
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1048
				for (uint t = 0; t < statspec->tiles; t++) {
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1049
					DrawTileSprites *dts = &statspec->renderdata[t];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
  1050
					uint seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1051
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
  1052
					dts->seq = NULL;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1053
					dts->ground.sprite = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1054
					dts->ground.pal = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1055
					if (dts->ground.sprite == 0) continue;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1056
					if (HasBit(dts->ground.pal, 15)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1057
						ClrBit(dts->ground.pal, 15);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1058
						SetBit(dts->ground.sprite, SPRITE_MODIFIER_USE_OFFSET);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1059
					}
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1060
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1061
					MapSpriteMappingRecolour(&dts->ground);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1062
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1063
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1064
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1065
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  1066
						/* no relative bounding box support */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1067
						dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1068
						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
  1069
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1070
						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
  1071
						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
  1072
						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
  1073
						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
  1074
						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
  1075
						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
  1076
						dtss->size_z = grf_load_byte(&buf);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1077
						dtss->image.sprite = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1078
						dtss->image.pal = grf_load_word(&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
  1079
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  1080
						/* Remap flags as ours collide */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1081
						if (HasBit(dtss->image.pal, 15)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1082
							ClrBit(dtss->image.pal, 15);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1083
							SetBit(dtss->image.sprite, SPRITE_MODIFIER_USE_OFFSET);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1084
						}
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1085
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1086
						MapSpriteMappingRecolour(&dtss->image);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1087
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1088
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1089
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1090
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1091
			case 0x0A: { // Copy sprite layout
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
  1092
				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
  1093
				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
  1094
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1095
				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
  1096
				statspec->renderdata = srcstatspec->renderdata;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1097
				statspec->copied_renderdata = true;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1098
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1099
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1100
			case 0x0B: // Callback mask
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1101
				statspec->callbackmask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1102
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1103
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1104
			case 0x0C: // Disallowed number of platforms
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1105
				statspec->disallowed_platforms = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1106
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1107
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1108
			case 0x0D: // Disallowed platform lengths
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1109
				statspec->disallowed_lengths = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1110
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1111
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1112
			case 0x0E: // Define custom layout
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1113
				statspec->copied_layouts = false;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1114
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1115
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1116
					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
  1117
					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
  1118
					StationLayout layout;
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
  1119
					uint l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1120
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1121
					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
  1122
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1123
					//debug("l %d > %d ?", length, stat->lengths);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1124
					if (length > statspec->lengths) {
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1125
						statspec->platforms = ReallocT(statspec->platforms, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1126
						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
  1127
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1128
						statspec->layouts = ReallocT(statspec->layouts, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1129
						memset(statspec->layouts + statspec->lengths, 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1130
						       (length - statspec->lengths) * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1131
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1132
						statspec->lengths = length;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1133
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1134
					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
  1135
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1136
					//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
  1137
					if (number > statspec->platforms[l]) {
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1138
						statspec->layouts[l] = ReallocT(statspec->layouts[l], number);
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  1139
						/* 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
  1140
						memset(statspec->layouts[l] + statspec->platforms[l], 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1141
						       (number - statspec->platforms[l]) * sizeof(**statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1142
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1143
						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
  1144
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1145
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1146
					p = 0;
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1147
					layout = MallocT<byte>(length * number);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1148
					for (l = 0; l < length; l++) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1149
						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
  1150
							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
  1151
						}
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1152
					}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1153
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1154
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1155
					p--;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1156
					free(statspec->layouts[l][p]);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1157
					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
  1158
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1159
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1160
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1161
			case 0x0F: { // Copy custom layout
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1162
				byte srcid = grf_load_byte(&buf);
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1163
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1164
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1165
				statspec->lengths   = srcstatspec->lengths;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1166
				statspec->platforms = srcstatspec->platforms;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1167
				statspec->layouts   = srcstatspec->layouts;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1168
				statspec->copied_layouts = true;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1169
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1170
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1171
			case 0x10: // Little/lots cargo threshold
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1172
				statspec->cargo_threshold = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1173
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1174
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1175
			case 0x11: // Pylon placement
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1176
				statspec->pylons = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1177
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1178
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1179
			case 0x12: // Cargo types for random triggers
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1180
				statspec->cargo_triggers = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1181
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1182
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1183
			case 0x13: // General flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1184
				statspec->flags = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1185
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1186
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1187
			case 0x14: // Overhead wire placement
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1188
				statspec->wires = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1189
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1190
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1191
			case 0x15: // Blocked tiles
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1192
				statspec->blocked = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1193
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1194
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1195
			case 0x16: // Animation info
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1196
				statspec->anim_frames = grf_load_byte(&buf);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1197
				statspec->anim_status = grf_load_byte(&buf);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1198
				break;
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1199
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1200
			case 0x17: // Animation speed
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1201
				statspec->anim_speed = grf_load_byte(&buf);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1202
				break;
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1203
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1204
			case 0x18: // Animation triggers
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1205
				statspec->anim_triggers = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1206
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1207
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1208
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1209
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1210
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1211
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1212
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1213
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1214
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1215
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1216
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1217
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1218
static bool CanalChangeInfo(uint id, int numinfo, int prop, byte **bufp, int len)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1219
{
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1220
	byte *buf = *bufp;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1221
	bool ret = false;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1222
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1223
	if (id + numinfo > CF_END) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1224
		grfmsg(1, "CanalChangeInfo: Canal feature %u is invalid, max %u, ignoreing", id + numinfo, CF_END);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1225
		return false;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1226
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1227
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1228
	for (int i = 0; i < numinfo; i++) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1229
		WaterFeature *wf = &_water_feature[id + i];
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1230
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1231
		switch (prop) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1232
			case 0x08:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1233
				wf->callbackmask = grf_load_byte(&buf);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1234
				break;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1235
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1236
			case 0x09:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1237
				wf->flags = grf_load_byte(&buf);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1238
				break;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1239
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1240
			default:
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1241
				ret = true;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1242
				break;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1243
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1244
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1245
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1246
	*bufp = buf;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1247
	return ret;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1248
}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1249
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
  1250
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
  1251
{
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
  1252
	byte *buf = *bufp;
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1253
	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
  1254
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1255
	if (brid + numinfo > MAX_BRIDGES) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1256
		grfmsg(1, "BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo, MAX_BRIDGES);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1257
		return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1258
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1259
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1260
	for (int i = 0; i < numinfo; i++) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1261
		BridgeSpec *bridge = &_bridge[brid + i];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1262
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1263
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1264
			case 0x08: // Year of availability
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1265
				bridge->avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1266
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1267
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1268
			case 0x09: // Minimum length
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1269
				bridge->min_length = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1270
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1271
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1272
			case 0x0A: // Maximum length
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1273
				bridge->max_length = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1274
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1275
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1276
			case 0x0B: // Cost factor
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1277
				bridge->price = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1278
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1279
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1280
			case 0x0C: // Maximum speed
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1281
				bridge->speed = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1282
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1283
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1284
			case 0x0D: { // Bridge sprite tables
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
  1285
				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
  1286
				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
  1287
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
  1288
				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
  1289
					/* Allocate memory for sprite table pointers and zero out */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1290
					bridge->sprite_table = CallocT<PalSpriteID*>(7);
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
  1291
				}
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
  1292
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
  1293
				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
  1294
					if (tableid >= 7) { // skip invalid data
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1295
						grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid);
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1296
						for (byte sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf);
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
  1297
						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
  1298
					}
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
  1299
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
  1300
					if (bridge->sprite_table[tableid] == NULL) {
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  1301
						bridge->sprite_table[tableid] = MallocT<PalSpriteID>(32);
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
  1302
					}
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
  1303
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1304
					for (byte sprite = 0; sprite < 32; sprite++) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1305
						SpriteID image = grf_load_word(&buf);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1306
						SpriteID pal   = grf_load_word(&buf);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1307
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1308
						bridge->sprite_table[tableid][sprite].sprite = image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1309
						bridge->sprite_table[tableid][sprite].pal    = pal;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1310
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1311
						MapSpriteMappingRecolour(&bridge->sprite_table[tableid][sprite]);
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1312
					}
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
  1313
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1314
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1315
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1316
			case 0x0E: // Flags; bit 0 - disable far pillars
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1317
				bridge->flags = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1318
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1319
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1320
			case 0x0F: // Long format year of availability (year since year 0)
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1321
				bridge->avail_year = Clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1322
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1323
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1324
			case 0x10: { // purchase string
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1325
				StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1326
				if (newone != STR_UNDEFINED) bridge->material = newone;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1327
				} break;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1328
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1329
			case 0x11: // description of bridge with rails or roads
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1330
			case 0x12: {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1331
				StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1332
				if (newone != STR_UNDEFINED) bridge->transport_name[prop - 0x11] = newone;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1333
				} break;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1334
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1335
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1336
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1337
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1338
		}
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
  1339
	}
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
  1340
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
  1341
	*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
  1342
	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
  1343
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1344
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1345
static bool TownHouseChangeInfo(uint hid, int numinfo, int prop, byte **bufp, int len)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1346
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1347
	byte *buf = *bufp;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1348
	bool ret = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1349
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1350
	if (hid + numinfo > HOUSE_MAX) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1351
		grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, HOUSE_MAX);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1352
		return false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1353
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1354
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1355
	/* Allocate house specs if they haven't been allocated already. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1356
	if (_cur_grffile->housespec == NULL) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1357
		_cur_grffile->housespec = CallocT<HouseSpec*>(HOUSE_MAX);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1358
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1359
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1360
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1361
		HouseSpec *housespec = _cur_grffile->housespec[hid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1362
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1363
		if (prop != 0x08 && housespec == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1364
			grfmsg(2, "TownHouseChangeInfo: Attempt to modify undefined house %u. Ignoring.", hid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1365
			continue;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1366
		}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1367
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1368
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1369
			case 0x08: { // Substitute building type, and definition of a new house
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1370
				HouseSpec **house = &_cur_grffile->housespec[hid + i];
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1371
				byte subs_id = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1372
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1373
				if (subs_id == 0xFF) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1374
					/* Instead of defining a new house, a substitute house id
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1375
					 * of 0xFF disables the old house with the current id. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1376
					_house_specs[hid + i].enabled = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1377
					continue;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1378
				} else if (subs_id >= NEW_HOUSE_OFFSET) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1379
					/* The substitute id must be one of the original houses. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1380
					grfmsg(2, "TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1381
					return false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1382
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1383
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1384
				/* Allocate space for this house. */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1385
				if (*house == NULL) *house = CallocT<HouseSpec>(1);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1386
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1387
				housespec = *house;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1388
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1389
				memcpy(housespec, &_house_specs[subs_id], sizeof(_house_specs[subs_id]));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1390
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1391
				housespec->enabled = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1392
				housespec->local_id = hid + i;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1393
				housespec->substitute_id = subs_id;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1394
				housespec->grffile = _cur_grffile;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1395
				housespec->random_colour[0] = 0x04;  // those 4 random colours are the base colour
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1396
				housespec->random_colour[1] = 0x08;  // for all new houses
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1397
				housespec->random_colour[2] = 0x0C;  // they stand for red, blue, orange and green
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1398
				housespec->random_colour[3] = 0x06;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1399
6800
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1400
				/* Make sure that the third cargo type is valid in this
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1401
				 * climate. This can cause problems when copying the properties
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1402
				 * of a house that accepts food, where the new house is valid
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1403
				 * in the temperate climate. */
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1404
				if (!GetCargo(housespec->accepts_cargo[2])->IsValid()) {
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1405
					housespec->cargo_acceptance[2] = 0;
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1406
				}
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1407
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1408
				/**
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1409
				 * New houses do not (currently) expect to have a default start
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1410
				 * date before 1930, as this breaks the build date stuff.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1411
				 * @see FinaliseHouseArray() for more details.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1412
				 */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1413
				if (housespec->min_year < 1930) housespec->min_year = 1930;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1414
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1415
				_loaded_newgrf_features.has_newhouses = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1416
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1417
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1418
			case 0x09: // Building flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1419
				housespec->building_flags = (BuildingFlags)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1420
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1421
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1422
			case 0x0A: { // Availability years
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1423
				uint16 years = grf_load_word(&buf);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1424
				housespec->min_year = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1425
				housespec->max_year = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1426
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1427
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1428
			case 0x0B: // Population
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1429
				housespec->population = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1430
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1431
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1432
			case 0x0C: // Mail generation multiplier
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1433
				housespec->mail_generation = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1434
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1435
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1436
			case 0x0D: // Passenger acceptance
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1437
			case 0x0E: // Mail acceptance
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1438
				housespec->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1439
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1440
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1441
			case 0x0F: { // Goods/candy, food/fizzy drinks acceptance
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1442
				int8 goods = grf_load_byte(&buf);
6667
437af4c23305 (svn r9366) -Codechange: Unify the different houses acceptances attributes on their cargo counterpart, as well as specifying cargo slot.
belugas
parents: 6658
diff changeset
  1443
437af4c23305 (svn r9366) -Codechange: Unify the different houses acceptances attributes on their cargo counterpart, as well as specifying cargo slot.
belugas
parents: 6658
diff changeset
  1444
				/* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance.
437af4c23305 (svn r9366) -Codechange: Unify the different houses acceptances attributes on their cargo counterpart, as well as specifying cargo slot.
belugas
parents: 6658
diff changeset
  1445
				 * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1446
				CargoID cid = (goods >= 0) ? ((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) :
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1447
						((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_FIZZY_DRINKS : CT_FOOD);
6667
437af4c23305 (svn r9366) -Codechange: Unify the different houses acceptances attributes on their cargo counterpart, as well as specifying cargo slot.
belugas
parents: 6658
diff changeset
  1448
6800
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1449
				/* Make sure the cargo type is valid in this climate. */
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1450
				if (!GetCargo(cid)->IsValid()) goods = 0;
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1451
6c09e1e86fcb (svn r10872) [NewGRF_ports] -Sync: with trunk r10765:10871.
rubidium
parents: 6789
diff changeset
  1452
				housespec->accepts_cargo[2] = cid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1453
				housespec->cargo_acceptance[2] = abs(goods); // but we do need positive value here
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1454
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1455
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1456
			case 0x10: // Local authority rating decrease on removal
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1457
				housespec->remove_rating_decrease = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1458
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1459
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1460
			case 0x11: // Removal cost multiplier
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1461
				housespec->removal_cost = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1462
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1463
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1464
			case 0x12: // Building name ID
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1465
				housespec->building_name = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1466
				_string_to_grf_mapping[&housespec->building_name] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1467
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1468
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1469
			case 0x13: // Building availability mask
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1470
				housespec->building_availability = (HouseZones)grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1471
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1472
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1473
			case 0x14: // House callback flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1474
				housespec->callback_mask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1475
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1476
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1477
			case 0x15: { // House override byte
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1478
				byte override = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1479
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1480
				/* The house being overridden must be an original house. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1481
				if (override >= NEW_HOUSE_OFFSET) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1482
					grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1483
					continue;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1484
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1485
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1486
				_house_mngr.Add(hid + i, _cur_grffile->grfid, override);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1487
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1488
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1489
			case 0x16: // Periodic refresh multiplier
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1490
				housespec->processing_time = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1491
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1492
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1493
			case 0x17: // Four random colours to use
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1494
				for (uint j = 0; j < 4; j++) housespec->random_colour[j] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1495
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1496
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1497
			case 0x18: // Relative probability of appearing
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1498
				housespec->probability = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1499
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1500
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1501
			case 0x19: // Extra flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1502
				housespec->extra_flags = (HouseExtraFlags)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1503
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1504
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1505
			case 0x1A: // Animation frames
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1506
				housespec->animation_frames = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1507
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1508
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1509
			case 0x1B: // Animation speed
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1510
				housespec->animation_speed = Clamp(grf_load_byte(&buf), 2, 16);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1511
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1512
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1513
			case 0x1C: // Class of the building type
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1514
				housespec->class_id = AllocateHouseClassID(grf_load_byte(&buf), _cur_grffile->grfid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1515
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1516
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1517
			case 0x1D: // Callback flags 2
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1518
				housespec->callback_mask |= (grf_load_byte(&buf) << 8);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1519
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1520
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1521
			case 0x1E: { // Accepted cargo types
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1522
				uint32 cargotypes = grf_load_dword(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1523
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1524
				/* Check if the cargo types should not be changed */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1525
				if (cargotypes == 0xFFFFFFFF) break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1526
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1527
				for (uint j = 0; j < 3; j++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1528
					/* Get the cargo number from the 'list' */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1529
					uint8 cargo_part = GB(cargotypes, 8 * j, 8);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1530
					CargoID cargo = GetCargoTranslation(cargo_part, _cur_grffile);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1531
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1532
					if (cargo == CT_INVALID) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1533
						/* Disable acceptance of invalid cargo type */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1534
						housespec->cargo_acceptance[j] = 0;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1535
					} else {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1536
						housespec->accepts_cargo[j] = cargo;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1537
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1538
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1539
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1540
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1541
			case 0x1F: // Minimum life span
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1542
				housespec->minimum_life = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1543
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1544
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1545
			case 0x20: { // @todo Cargo acceptance watch list
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1546
				byte count = grf_load_byte(&buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1547
				for (byte j = 0; j < count; j++) grf_load_byte(&buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1548
				ret = true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1549
			} break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1550
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1551
			case 0x21: // long introduction year
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1552
				housespec->min_year = grf_load_word(&buf);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1553
				break;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1554
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1555
			case 0x22: // long maximum year
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1556
				housespec->max_year = grf_load_word(&buf);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1557
				break;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1558
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1559
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1560
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1561
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1562
		}
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1563
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1564
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1565
	*bufp = buf;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1566
	return ret;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1567
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1568
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1569
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
  1570
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1571
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1572
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1573
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1574
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1575
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1576
			case 0x08: { // Cost base factor
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1577
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1578
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1579
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1580
				if (price < NUM_PRICES) {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1581
					SetPriceBaseMultiplier(price, factor);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1582
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1583
					grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1584
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1585
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1586
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1587
			case 0x09: // Cargo translation table
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1588
				/* This is loaded during the reservation stage, so just skip it here. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1589
				/* Each entry is 4 bytes. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1590
				buf += 4;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1591
				break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1592
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1593
			case 0x0A: { // Currency display names
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1594
				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
  1595
				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
  1596
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1597
				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
  1598
					_currency_specs[curidx].name = newone;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1599
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1600
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1601
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1602
			case 0x0B: { // Currency multipliers
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1603
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1604
				uint32 rate = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1605
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1606
				if (curidx < NUM_CURRENCY) {
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1607
					/* 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
  1608
					 * 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
  1609
					 * to be compatible */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1610
					_currency_specs[curidx].rate = rate / 1000;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1611
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1612
					grfmsg(1, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1613
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1614
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1615
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1616
			case 0x0C: { // Currency options
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1617
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1618
				uint16 options = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1619
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1620
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1621
					_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
  1622
					/* 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
  1623
					 * 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
  1624
					_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
  1625
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1626
					grfmsg(1, "GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1627
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1628
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1629
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1630
			case 0x0D: { // Currency prefix symbol
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1631
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1632
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1633
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1634
				if (curidx < NUM_CURRENCY) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1635
					memcpy(_currency_specs[curidx].prefix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1636
					_currency_specs[curidx].prefix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1637
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1638
					grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1639
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1640
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1641
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1642
			case 0x0E: { // Currency suffix symbol
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1643
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1644
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1645
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1646
				if (curidx < NUM_CURRENCY) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  1647
					memcpy(&_currency_specs[curidx].suffix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1648
					_currency_specs[curidx].suffix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1649
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1650
					grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1651
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1652
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1653
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1654
			case 0x0F: { //  Euro introduction dates
4625
3e45c59b5d64 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
  1655
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1656
				Year year_euro = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1657
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1658
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1659
					_currency_specs[curidx].to_euro = year_euro;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1660
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1661
					grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1662
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1663
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1664
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1665
			case 0x10: // Snow line height table
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1666
				if (numinfo > 1 || IsSnowLineSet()) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1667
					grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1668
				} else if (len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1669
					grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (%d)", len);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1670
				} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1671
					byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1672
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1673
					for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1674
						for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1675
							table[i][j] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1676
						}
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  1677
					}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1678
					SetSnowLine(table);
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  1679
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1680
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1681
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  1682
			case 0x11: // GRF match for engine allocation
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  1683
				/* This is loaded during the reservation stage, so just skip it here. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  1684
				/* Each entry is 8 bytes. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  1685
				buf += 8;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  1686
				break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  1687
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1688
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1689
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1690
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1691
		}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1692
	}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1693
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1694
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1695
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1696
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1697
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1698
static bool CargoChangeInfo(uint cid, int numinfo, int prop, byte **bufp, int len)
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1699
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1700
	byte *buf = *bufp;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1701
	bool ret = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1702
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1703
	if (cid + numinfo > NUM_CARGO) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1704
		grfmsg(2, "CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, NUM_CARGO - 1);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1705
		return false;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1706
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1707
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1708
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1709
		CargoSpec *cs = &_cargo[cid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1710
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1711
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1712
			case 0x08: /* Bit number of cargo */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1713
				cs->bitnum = grf_load_byte(&buf);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1714
				if (cs->IsValid()) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1715
					cs->grfid = _cur_grffile->grfid;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1716
					SetBit(_cargo_mask, cid + i);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1717
				} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1718
					ClrBit(_cargo_mask, cid + i);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1719
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1720
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1721
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1722
			case 0x09: /* String ID for cargo type name */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1723
				cs->name = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1724
				_string_to_grf_mapping[&cs->name] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1725
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1726
6732
ca1b466db422 (svn r10653) [NewGRF_ports] -Sync: with trunk r10602-10651
richk
parents: 6722
diff changeset
  1727
			case 0x0A: /* String for 1 unit of cargo */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1728
				cs->name_single = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1729
				_string_to_grf_mapping[&cs->name_single] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1730
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1731
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1732
			case 0x0B:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1733
				/* String for units of cargo. This is different in OpenTTD to TTDPatch
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1734
				 * (e.g. 10 tonnes of coal) */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1735
				cs->units_volume = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1736
				_string_to_grf_mapping[&cs->units_volume] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1737
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1738
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1739
			case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1740
				cs->quantifier = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1741
				_string_to_grf_mapping[&cs->quantifier] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1742
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1743
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1744
			case 0x0D: /* String for two letter cargo abbreviation */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1745
				cs->abbrev = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  1746
				_string_to_grf_mapping[&cs->abbrev] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1747
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1748
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1749
			case 0x0E: /* Sprite ID for cargo icon */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1750
				cs->sprite = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1751
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1752
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1753
			case 0x0F: /* Weight of one unit of cargo */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1754
				cs->weight = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1755
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1756
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1757
			case 0x10: /* Used for payment calculation */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1758
				cs->transit_days[0] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1759
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1760
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1761
			case 0x11: /* Used for payment calculation */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1762
				cs->transit_days[1] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1763
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1764
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1765
			case 0x12: /* Base cargo price */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1766
				cs->initial_payment = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1767
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1768
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1769
			case 0x13: /* Colour for station rating bars */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1770
				cs->rating_colour = MapDOSColour(grf_load_byte(&buf));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1771
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1772
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1773
			case 0x14: /* Colour for cargo graph */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1774
				cs->legend_colour = MapDOSColour(grf_load_byte(&buf));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1775
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1776
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1777
			case 0x15: /* Freight status */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1778
				cs->is_freight = (grf_load_byte(&buf) != 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1779
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1780
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1781
			case 0x16: /* Cargo classes */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1782
				cs->classes = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1783
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1784
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1785
			case 0x17: /* Cargo label */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1786
				cs->label = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1787
				cs->label = BSWAP32(cs->label);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1788
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1789
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1790
			case 0x18: { /* Town growth substitute type */
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1791
				uint8 substitute_type = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1792
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1793
				switch (substitute_type) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1794
					case 0x00: cs->town_effect = TE_PASSENGERS; break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1795
					case 0x02: cs->town_effect = TE_MAIL; break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1796
					case 0x05: cs->town_effect = TE_GOODS; break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1797
					case 0x09: cs->town_effect = TE_WATER; break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1798
					case 0x0B: cs->town_effect = TE_FOOD; break;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1799
					default:
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1800
						grfmsg(1, "CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1801
					case 0xFF: cs->town_effect = TE_NONE; break;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1802
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1803
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1804
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1805
			case 0x19: /* Town growth coefficient */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1806
				cs->multipliertowngrowth = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1807
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1808
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1809
			case 0x1A: /* Bitmask of callbacks to use */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1810
				cs->callback_mask = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1811
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1812
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1813
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1814
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1815
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1816
		}
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1817
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1818
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1819
	*bufp = buf;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1820
	return ret;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1821
}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1822
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1823
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1824
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
  1825
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1826
	byte *buf = *bufp;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1827
	bool ret = false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1828
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1829
	if (_cur_grffile->sound_offset == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1830
		grfmsg(1, "SoundEffectChangeInfo: No effects defined, skipping");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1831
		return false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1832
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1833
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1834
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1835
		uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1836
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1837
		if (sound >= GetNumSounds()) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1838
			grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1839
			continue;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1840
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1841
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1842
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1843
			case 0x08: // Relative volume
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1844
				GetSound(sound)->volume = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1845
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1846
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1847
			case 0x09: // Priority
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1848
				GetSound(sound)->priority = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1849
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1850
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1851
			case 0x0A: { // Override old sound
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1852
				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
  1853
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1854
				if (orig_sound >= GetNumSounds()) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1855
					grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, GetNumSounds());
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1856
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1857
					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
  1858
					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
  1859
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1860
					/* 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
  1861
					*oldfe = *newfe;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1862
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1863
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1864
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1865
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1866
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1867
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1868
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1869
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1870
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1871
	*bufp = buf;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1872
	return ret;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1873
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1874
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1875
static bool IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, byte **bufp, int len)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1876
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1877
	byte *buf = *bufp;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1878
	bool ret = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1879
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1880
	if (indtid + numinfo > NUM_INDUSTRYTILES) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1881
		grfmsg(1, "IndustryTilesChangeInfo: Too many industry tiles loaded (%u), max (%u). Ignoring.", indtid + numinfo, NUM_INDUSTRYTILES);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1882
		return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1883
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1884
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1885
	/* Allocate industry tile specs if they haven't been allocated already. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1886
	if (_cur_grffile->indtspec == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1887
		_cur_grffile->indtspec = CallocT<IndustryTileSpec*>(NUM_INDUSTRYTILES);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1888
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1889
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1890
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1891
		IndustryTileSpec *tsp = _cur_grffile->indtspec[indtid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1892
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1893
		if (prop != 0x08 && tsp == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1894
			grfmsg(2, "IndustryTilesChangeInfo: Attempt to modify undefined industry tile %u. Ignoring.", indtid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1895
			continue;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1896
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1897
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1898
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1899
			case 0x08: { // Substitute industry tile type
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1900
				IndustryTileSpec **tilespec = &_cur_grffile->indtspec[indtid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1901
				byte subs_id = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1902
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6865
diff changeset
  1903
				if (subs_id >= NEW_INDUSTRYTILEOFFSET) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1904
					/* The substitute id must be one of the original industry tile. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1905
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1906
					return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1907
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1908
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1909
				/* Allocate space for this industry. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1910
				if (*tilespec == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1911
					int tempid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1912
					*tilespec = CallocT<IndustryTileSpec>(1);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1913
					tsp = *tilespec;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1914
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1915
					memcpy(tsp, &_industry_tile_specs[subs_id], sizeof(_industry_tile_specs[subs_id]));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1916
					tsp->enabled = true;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1917
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1918
					/* A copied tile should not have the animation infos copied too.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1919
					 * The anim_state should be left untouched, though
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1920
					 * It is up to the author to animate them himself */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1921
					tsp->anim_production = INDUSTRYTILE_NOANIM;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1922
					tsp->anim_next = INDUSTRYTILE_NOANIM;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1923
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1924
					tsp->grf_prop.local_id = indtid + i;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1925
					tsp->grf_prop.subst_id = subs_id;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1926
					tsp->grf_prop.grffile = _cur_grffile;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1927
					tempid = _industile_mngr.AddEntityID(indtid + i, _cur_grffile->grfid, subs_id); // pre-reserve the tile slot
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1928
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1929
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1930
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1931
			case 0x09: { // Industry tile override
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1932
				byte ovrid = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1933
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1934
				/* The industry being overridden must be an original industry. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1935
				if (ovrid >= NEW_INDUSTRYTILEOFFSET) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1936
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1937
					return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1938
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1939
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1940
				_industile_mngr.Add(indtid + i, _cur_grffile->grfid, ovrid);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1941
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1942
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1943
			case 0x0A: // Tile acceptance
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1944
			case 0x0B:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1945
			case 0x0C: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1946
				uint16 acctp = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1947
				tsp->accepts_cargo[prop - 0x0A] = GetCargoTranslation(GB(acctp, 0, 8), _cur_grffile);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1948
				tsp->acceptance[prop - 0x0A] = GB(acctp, 8, 8);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1949
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1950
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1951
			case 0x0D: // Land shape flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1952
				tsp->slopes_refused = (Slope)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1953
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1954
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1955
			case 0x0E: // Callback flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1956
				tsp->callback_flags = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1957
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1958
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1959
			case 0x0F: // Animation information
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1960
				tsp->animation_info = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1961
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1962
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1963
			case 0x10: // Animation speed
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1964
				tsp->animation_speed = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1965
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1966
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1967
			case 0x11: // Triggers for callback 25
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1968
				tsp->animation_triggers = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1969
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1970
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1971
			case 0x12: // Special flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1972
				tsp->animation_special_flags = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1973
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1974
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1975
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1976
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1977
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1978
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1979
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1980
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1981
	*bufp = buf;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1982
	return ret;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1983
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1984
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1985
static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1986
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1987
	byte *buf = *bufp;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1988
	bool ret = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1989
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1990
	if (indid + numinfo > NUM_INDUSTRYTYPES) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1991
		grfmsg(1, "IndustriesChangeInfo: Too many industries loaded (%u), max (%u). Ignoring.", indid + numinfo, NUM_INDUSTRYTYPES);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1992
		return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1993
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1994
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1995
	grfmsg(1, "IndustriesChangeInfo: newid %u", indid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1996
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1997
	/* Allocate industry specs if they haven't been allocated already. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1998
	if (_cur_grffile->industryspec == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1999
		_cur_grffile->industryspec = CallocT<IndustrySpec*>(NUM_INDUSTRYTYPES);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2000
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2001
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2002
	for (int i = 0; i < numinfo; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2003
		IndustrySpec *indsp = _cur_grffile->industryspec[indid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2004
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2005
		if (prop != 0x08 && indsp == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2006
			grfmsg(2, "IndustriesChangeInfo: Attempt to modify undefined industry %u. Ignoring.", indid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2007
			continue;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2008
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2009
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2010
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2011
			case 0x08: { // Substitute industry type
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2012
				IndustrySpec **indspec = &_cur_grffile->industryspec[indid + i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2013
				byte subs_id = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2014
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2015
				if (subs_id == 0xFF) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2016
					/* Instead of defining a new industry, a substitute industry id
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2017
					 * of 0xFF disables the old industry with the current id. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2018
					_industry_specs[indid + i].enabled = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2019
					continue;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2020
				} else if (subs_id >= NEW_INDUSTRYOFFSET) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2021
					/* The substitute id must be one of the original industry. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2022
					grfmsg(2, "_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2023
					return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2024
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2025
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2026
				/* Allocate space for this industry.
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2027
				 * Only need to do it once. If ever it is called again, it should not
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2028
				 * do anything */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2029
				if (*indspec == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2030
					*indspec = CallocT<IndustrySpec>(1);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2031
					indsp = *indspec;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2032
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2033
					memcpy(indsp, &_origin_industry_specs[subs_id], sizeof(_industry_specs[subs_id]));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2034
					indsp->enabled = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2035
					indsp->grf_prop.local_id = indid + i;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2036
					indsp->grf_prop.subst_id = subs_id;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2037
					indsp->grf_prop.grffile = _cur_grffile;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2038
					/* If the grf industry needs to check its surounding upon creation, it should
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2039
					 * rely on callbacks, not on the original placement functions */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2040
					indsp->check_proc = CHECK_NOTHING;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2041
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2042
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2043
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2044
			case 0x09: { // Industry type override
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2045
				byte ovrid = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2046
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2047
				/* The industry being overridden must be an original industry. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2048
				if (ovrid >= NEW_INDUSTRYOFFSET) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2049
					grfmsg(2, "IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2050
					return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2051
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2052
				indsp->grf_prop.override = ovrid;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2053
				_industry_mngr.Add(indid + i, _cur_grffile->grfid, ovrid);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2054
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2055
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2056
			case 0x0A: { // Set industry layout(s)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2057
				indsp->num_table = grf_load_byte(&buf); // Number of layaouts
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2058
				uint32 defsize = grf_load_dword(&buf);  // Total size of the definition
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2059
				IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2060
				IndustryTileTable *itt = CallocT<IndustryTileTable>(defsize); // Temporary array to read the tile layouts from the GRF
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2061
				int size;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2062
				IndustryTileTable *copy_from;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2063
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2064
				for (byte j = 0; j < indsp->num_table; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2065
					for (int k = 0;; k++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2066
						itt[k].ti.x = grf_load_byte(&buf); // Offsets from northermost tile
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2067
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2068
						if (itt[k].ti.x == 0xFE && k == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2069
							/* This means we have to borrow the layout from an old industry */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2070
							IndustryType type = grf_load_byte(&buf);  //industry holding required layout
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2071
							byte laynbr = grf_load_byte(&buf);        //layout number to borrow
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2072
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2073
							copy_from = (IndustryTileTable*)_origin_industry_specs[type].table[laynbr];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2074
							for (size = 1;; size++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2075
								if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.y == 0) break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2076
							}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2077
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2078
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2079
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2080
						itt[k].ti.y = grf_load_byte(&buf); // Or table definition finalisation
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2081
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2082
						if (itt[k].ti.x == 0 && itt[k].ti.y == 0x80) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2083
							/*  Not the same terminator.  The one we are using is rather
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2084
							 x= -80, y = x .  So, adjust it. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2085
							itt[k].ti.x = -0x80;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2086
							itt[k].ti.y =  0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2087
							itt[k].gfx  =  0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2088
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2089
							size = k + 1;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2090
							copy_from = itt;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2091
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2092
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2093
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2094
						itt[k].gfx = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2095
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2096
						if (itt[k].gfx == 0xFE) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2097
							/* Use a new tile from this GRF */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2098
							int local_tile_id = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2099
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2100
							/* Read the ID from the _industile_mngr. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2101
							int tempid = _industile_mngr.GetID(local_tile_id, _cur_grffile->grfid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2102
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2103
							if (tempid == INVALID_INDUSTRYTILE) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2104
								grfmsg(2, "IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2105
							} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2106
								/* Declared as been valid, can be used */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2107
								itt[k].gfx = tempid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2108
								size = k + 1;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2109
								copy_from = itt;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2110
							}
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2111
						} else if (itt[k].gfx == 0xFF) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2112
							itt[k].ti.x = (int8)GB(itt[k].ti.x, 0, 8);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  2113
							itt[k].ti.y = (int8)GB(itt[k].ti.y, 0, 8);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2114
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2115
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2116
					tile_table[j] = CallocT<IndustryTileTable>(size);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2117
					memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2118
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2119
				/* Install final layout construction in the industry spec */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2120
				indsp->table = tile_table;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2121
				SetBit(indsp->cleanup_flag, 1);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2122
				free(itt);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2123
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2124
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2125
			case 0x0B: // Industry production flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2126
				indsp->life_type = (IndustryLifeType)grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2127
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2128
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2129
			case 0x0C: // Industry closure message
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2130
				indsp->closure_text = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2131
				_string_to_grf_mapping[&indsp->closure_text] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2132
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2133
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2134
			case 0x0D: // Production increase message
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2135
				indsp->production_up_text = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2136
				_string_to_grf_mapping[&indsp->production_up_text] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2137
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2138
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2139
			case 0x0E: // Production decrease message
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2140
				indsp->production_down_text = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2141
				_string_to_grf_mapping[&indsp->production_down_text] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2142
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2143
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2144
			case 0x0F: // Fund cost multiplier
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2145
				indsp->cost_multiplier = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2146
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2147
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2148
			case 0x10: // Production cargo types
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2149
				for (byte j = 0; j < 2; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2150
					indsp->produced_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2151
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2152
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2153
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2154
			case 0x11: // Acceptance cargo types
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2155
				for (byte j = 0; j < 3; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2156
					indsp->accepts_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2157
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2158
				grf_load_byte(&buf); // Unnused, eat it up
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2159
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2160
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2161
			case 0x12: // Production multipliers
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2162
			case 0x13:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2163
				indsp->production_rate[prop - 0x12] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2164
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2165
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2166
			case 0x14: // Minimal amount of cargo distributed
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2167
				indsp->minimal_cargo = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2168
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2169
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2170
			case 0x15: { // Random sound effects
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2171
				indsp->number_of_sounds = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2172
				uint8 *sounds = MallocT<uint8>(indsp->number_of_sounds);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2173
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2174
				for (uint8 j = 0; j < indsp->number_of_sounds; j++) sounds[j] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2175
				indsp->random_sounds = sounds;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2176
				SetBit(indsp->cleanup_flag, 0);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2177
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2178
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2179
			case 0x16: // Conflicting industry types
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2180
				for (byte j = 0; j < 3; j++) indsp->conflicting[j] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2181
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2182
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2183
			case 0x17: // Probability in random game
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2184
				indsp->appear_creation[_settings_game.game_creation.landscape] = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2185
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2186
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2187
			case 0x18: // Probability during gameplay
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2188
				indsp->appear_ingame[_settings_game.game_creation.landscape] = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2189
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2190
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2191
			case 0x19: // Map color
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2192
				indsp->map_colour = MapDOSColour(grf_load_byte(&buf));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2193
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2194
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2195
			case 0x1A: // Special industry flags to define special behavior
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2196
				indsp->behaviour = (IndustryBehaviour)grf_load_dword(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2197
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2198
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2199
			case 0x1B: // New industry text ID
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2200
				indsp->new_industry_text = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2201
				_string_to_grf_mapping[&indsp->new_industry_text] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2202
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2203
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2204
			case 0x1C: // Input cargo multipliers for the three input cargo types
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2205
			case 0x1D:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2206
			case 0x1E: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2207
					uint32 multiples = grf_load_dword(&buf);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2208
					indsp->input_cargo_multiplier[prop - 0x1C][0] = GB(multiples, 0, 15);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2209
					indsp->input_cargo_multiplier[prop - 0x1C][1] = GB(multiples, 15, 15);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2210
				} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2211
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2212
			case 0x1F: // Industry name
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2213
				indsp->name = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2214
				_string_to_grf_mapping[&indsp->name] = _cur_grffile->grfid;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2215
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2216
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2217
			case 0x20: // Prospecting success chance
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2218
				indsp->prospecting_chance = grf_load_dword(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2219
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2220
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2221
			case 0x21:   // Callback flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2222
			case 0x22: { // Callback additional flags
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2223
				byte aflag = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2224
				SB(indsp->callback_flags, (prop - 0x21) * 8, 8, aflag);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2225
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2226
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2227
			case 0x23: // removal cost multiplier
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2228
				indsp->removal_cost_multiplier = grf_load_dword(&buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2229
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2230
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2231
			case 0x24: // name for nearby station
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2232
				indsp->station_name = grf_load_word(&buf);
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  2233
				_string_to_grf_mapping[&indsp->station_name] = _cur_grffile->grfid;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2234
				break;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2235
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2236
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2237
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2238
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2239
		}
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2240
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2241
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2242
	*bufp = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2243
	return ret;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2244
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2245
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2246
static void ReadBlocksInto(FSMblockmap *block, byte **buf)
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2247
{
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2248
	byte *blocklist = MallocT<byte>(1);
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2249
	byte numblocks = 1;
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2250
	byte firstblock = grf_load_byte(buf);
6865
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2251
	switch (firstblock) {
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2252
	case 0x7E:
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2253
		{
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2254
			/* read multiblock */
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2255
			numblocks = 0;
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2256
			byte nextblock = grf_load_byte(buf);
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2257
			while (nextblock != 0x7F) {
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2258
				numblocks++;
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2259
				blocklist = ReallocT(blocklist, numblocks);
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2260
				blocklist[numblocks - 1] = nextblock;
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2261
				nextblock = grf_load_byte(buf);
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2262
			}
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2263
			block->Initialise(blocklist, numblocks);
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2264
		} break;
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2265
	case 0xFF:
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2266
		block->SetAll();
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2267
		break;
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2268
	default:
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2269
		blocklist[0] = firstblock;
6865
2b39c3ca4fda (svn r10988) [NewGRF_ports] -Feature: 0xFF in a block list indicates SetAll. This is best used in the release block, where it effectively releases all currently held blocks.
richk
parents: 6863
diff changeset
  2270
		block->Initialise(blocklist, numblocks);
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2271
	}
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2272
}
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2273
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2274
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2275
static bool FSMPortChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int len)
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2276
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2277
	byte *buf = *bufp;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2278
	bool ret = false;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2279
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2280
	if (stid + numinfo > MAX_FSM_PORTS) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2281
		grfmsg(1, "StationChangeInfo: Station %u is invalid, max %u, ignoring", stid + numinfo, MAX_FSM_PORTS);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2282
		return false;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2283
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2284
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2285
	/* Allocate station specs if necessary */
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2286
	if (_cur_grffile->fsmports == NULL) _cur_grffile->fsmports = CallocT<FSMportsSpec*>(MAX_FSM_PORTS);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2287
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2288
	for (int i = 0; i < numinfo; i++) {
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2289
		FSMportsSpec *fsmportspec = _cur_grffile->fsmports[stid + i];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2290
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2291
		/* Check that the station we are modifying is defined. */
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2292
		if (fsmportspec == NULL && prop != 0x08) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2293
			grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2294
			continue;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2295
		}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2296
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2297
		switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2298
			case 0x08: { // Class ID
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2299
				FSMportsSpec **fsmportspec = &_cur_grffile->fsmports[stid + i];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2300
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2301
				/* Property 0x08 is special; it is where the station is allocated */
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2302
				if (*fsmportspec == NULL) *fsmportspec = CallocT<FSMportsSpec>(1);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2303
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2304
				/* Swap classid because we read it in BE meaning WAYP or DFLT */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2305
				uint32 classid = grf_load_dword(&buf);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2306
				(*fsmportspec)->sclass = AllocateFSMportsClass(BSWAP32(classid));
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2307
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2308
				/* create new AirportClass for this airport */
6854
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
  2309
				(*fsmportspec)->portFSM = new AirportFTAClass(*fsmportspec);
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2310
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2311
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2312
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2313
			case 0x09: // Define sprite layout
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2314
				fsmportspec->tiles = grf_load_extended(&buf);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2315
				fsmportspec->renderdata = CallocT<DrawTileSprites>(fsmportspec->tiles);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2316
				fsmportspec->copied_renderdata = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2317
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2318
				for (uint t = 0; t < fsmportspec->tiles; t++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2319
					DrawTileSprites *dts = &fsmportspec->renderdata[t];
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2320
					uint seq_count = 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2321
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2322
					dts->seq = NULL;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2323
					dts->ground.sprite = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2324
					dts->ground.pal = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2325
					if (dts->ground.sprite == 0) continue;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2326
					if (HasBit(dts->ground.pal, 15)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2327
						ClrBit(dts->ground.pal, 15);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2328
						SetBit(dts->ground.sprite, SPRITE_MODIFIER_USE_OFFSET);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2329
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2330
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2331
					while (buf < *bufp + len) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2332
						DrawTileSeqStruct *dtss;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2333
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2334
						/* no relative bounding box support */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2335
						dts->seq = ReallocT((DrawTileSeqStruct*)dts->seq, ++seq_count);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2336
						dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2337
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2338
						dtss->delta_x = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2339
						if ((byte) dtss->delta_x == 0x80) break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2340
						dtss->delta_y = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2341
						dtss->delta_z = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2342
						dtss->size_x = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2343
						dtss->size_y = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2344
						dtss->size_z = grf_load_byte(&buf);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2345
						dtss->image.sprite = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2346
						dtss->image.pal = grf_load_word(&buf);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2347
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2348
						/* Remap flags as ours collide */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2349
						if (HasBit(dtss->image.pal, 15)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2350
							ClrBit(dtss->image.pal, 15);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2351
							SetBit(dtss->image.sprite, SPRITE_MODIFIER_USE_OFFSET);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2352
						}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2353
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2354
						if (HasBit(dtss->image.pal, 14)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2355
							ClrBit(dtss->image.pal, 14);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2356
							SetBit(dtss->image.sprite, SPRITE_MODIFIER_OPAQUE);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2357
						}
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2358
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2359
						if (HasBit(dtss->image.sprite, 15)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2360
							ClrBit(dtss->image.sprite, 15);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2361
							SetBit(dtss->image.sprite, PALETTE_MODIFIER_COLOR);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2362
						}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2363
						if (HasBit(dtss->image.sprite, 14)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2364
							ClrBit(dtss->image.sprite, 14);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2365
							SetBit(dtss->image.sprite, PALETTE_MODIFIER_TRANSPARENT);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2366
						}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2367
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2368
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2369
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2370
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2371
			case 0x0A: { // Copy sprite layout
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2372
				byte srcid = grf_load_byte(&buf);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2373
				const FSMportsSpec *srcfsmportspec = _cur_grffile->fsmports[srcid];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2374
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2375
				fsmportspec->tiles = srcfsmportspec->tiles;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2376
				fsmportspec->renderdata = srcfsmportspec->renderdata;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2377
				fsmportspec->copied_renderdata = true;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2378
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2379
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2380
			case 0x0B: // Callback mask
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2381
				fsmportspec->callbackmask = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2382
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2383
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2384
			case 0x0E: // Define custom layout
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2385
				fsmportspec->copied_layouts = false;
6835
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2386
				fsmportspec->numlayouts = grf_load_byte(&buf);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2387
				fsmportspec->size_x = ReallocT(fsmportspec->size_x, fsmportspec->numlayouts);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2388
				memset(fsmportspec->size_x, 0, fsmportspec->numlayouts);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2389
				fsmportspec->size_y = ReallocT(fsmportspec->size_y, fsmportspec->numlayouts);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2390
				memset(fsmportspec->size_y, 0, fsmportspec->numlayouts);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2391
				fsmportspec->layouts = ReallocT(fsmportspec->layouts, fsmportspec->numlayouts);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2392
				for (uint set = 0; set < fsmportspec->numlayouts; set++) {
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2393
					byte orientation = grf_load_byte(&buf);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2394
					byte x = grf_load_byte(&buf);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2395
					byte y = grf_load_byte(&buf);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2396
					FSMportsLayout layout;
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2397
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2398
					if (x == 0 || y == 0) break;
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2399
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2400
					fsmportspec->size_x[set] = x;
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2401
					fsmportspec->size_y[set] = y;
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2402
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2403
					layout = MallocT<byte>((x * y) + 2);
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2404
					layout[0] = orientation;
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2405
					layout[1] = grf_load_byte(&buf); //minipic sprite ID
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2406
					for (byte l = 2; l < (x * y) + 2; l++) {
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2407
						layout[l] = grf_load_byte(&buf);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2408
					}
6835
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2409
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2410
					fsmportspec->layouts[set] = layout;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2411
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2412
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2413
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2414
			case 0x0F: { // Copy custom layout
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2415
				byte srcid = grf_load_byte(&buf);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2416
				const FSMportsSpec *srcfsmportspec = _cur_grffile->fsmports[srcid];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2417
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6742
diff changeset
  2418
				fsmportspec->size_x   = srcfsmportspec->size_x;
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6742
diff changeset
  2419
				fsmportspec->size_y     = srcfsmportspec->size_y;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2420
				fsmportspec->layouts   = srcfsmportspec->layouts;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2421
				fsmportspec->copied_layouts = true;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2422
			} break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2423
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2424
			case 0x10: // Little/lots cargo threshold
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2425
				fsmportspec->cargo_threshold = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2426
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2427
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2428
			case 0x13: // General flags
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2429
				fsmportspec->flags = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2430
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2431
10280
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2432
			case 0x16: // Animation info
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2433
				fsmportspec->anim_frames = grf_load_byte(&buf);
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2434
				fsmportspec->anim_status = grf_load_byte(&buf);
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2435
				break;
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2436
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2437
			case 0x17: // Animation speed
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2438
				fsmportspec->anim_speed = grf_load_byte(&buf);
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2439
				break;
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2440
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2441
			case 0x18: // Animation triggers
ffc3a406abe7 (svn r12812) [NewGRF_ports] -Change: Added animation variables to fsmportspec and newgrf loader.
richk
parents: 10274
diff changeset
  2442
				fsmportspec->anim_triggers = grf_load_word(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2443
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2444
6781
9615adc94f08 (svn r10852) [NewGRF_ports] -Fix: Added reading of Prop 19 Vehicle Feature.
richk
parents: 6771
diff changeset
  2445
			case 0x19: // Vehicle Type
9615adc94f08 (svn r10852) [NewGRF_ports] -Fix: Added reading of Prop 19 Vehicle Feature.
richk
parents: 6771
diff changeset
  2446
				grf_load_byte(&buf);
9615adc94f08 (svn r10852) [NewGRF_ports] -Fix: Added reading of Prop 19 Vehicle Feature.
richk
parents: 6771
diff changeset
  2447
				ret = true;
9615adc94f08 (svn r10852) [NewGRF_ports] -Fix: Added reading of Prop 19 Vehicle Feature.
richk
parents: 6771
diff changeset
  2448
				break;
9615adc94f08 (svn r10852) [NewGRF_ports] -Fix: Added reading of Prop 19 Vehicle Feature.
richk
parents: 6771
diff changeset
  2449
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2450
			case 0x1A: // Finite State Machine and Movement Orders
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  2451
				fsmportspec->portFSM->num_positions = grf_load_byte(&buf);
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  2452
				fsmportspec->portFSM->layout = MallocT<AirportFTA>(fsmportspec->portFSM->num_positions);
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  2453
				fsmportspec->portFSM->moving_data = MallocT<AirportMovingData>(fsmportspec->portFSM->num_positions);
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6742
diff changeset
  2454
				fsmportspec->portFSM->size_x = fsmportspec->size_x[0];
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6742
diff changeset
  2455
				fsmportspec->portFSM->size_y = fsmportspec->size_y[0];
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  2456
				for (byte element = 0; element < fsmportspec->portFSM->num_positions; element++) {
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2457
					AirportMovingData md;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2458
					md.x = grf_load_word(&buf);
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2459
					md.y = grf_load_word(&buf);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2460
					md.z = grf_load_word(&buf);
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2461
					md.state = grf_load_byte(&buf);
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2462
					md.flag = grf_load_word(&buf);  // needs unpacking / recoding but only until fsmport system complete
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2463
					md.direction = (Direction)((md.flag >> 1) & 0x07);  // not required in new fsmport system
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2464
					md.block = grf_load_byte(&buf);
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2465
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2466
					fsmportspec->portFSM->moving_data[element] = md;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2467
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2468
					byte count = grf_load_byte(&buf);
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2469
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2470
					/* always store one position */
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2471
					AirportFTA *current = &fsmportspec->portFSM->layout[element];
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2472
					current->position = element;
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2473
					current->heading = grf_load_byte(&buf);
6805
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6801
diff changeset
  2474
					if (current->heading >= 0x7B && current->heading <= 0x7E) { //read special byte
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6801
diff changeset
  2475
						current->special = grf_load_byte(&buf);
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6801
diff changeset
  2476
					}
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2477
					ReadBlocksInto(&current->reserveblock, &buf);
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2478
					ReadBlocksInto(&current->releaseblock, &buf);
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2479
					current->next_position = grf_load_byte(&buf);
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2480
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2481
					for (uint step = 1; step < count; step++)
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2482
					{
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2483
						AirportFTA *newNode = MallocT<AirportFTA>(1);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2484
						newNode->position = element;
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2485
						newNode->heading = grf_load_byte(&buf);
6805
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6801
diff changeset
  2486
						if (newNode->heading >= 0x7B && newNode->heading <= 0x7E) { //read special byte
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6801
diff changeset
  2487
							newNode->special = grf_load_byte(&buf);
2b3ed8e47662 (svn r10879) [NewGRF_ports] -Feature: Added support for special orders, with addition of <data> byte in FSM command:
richk
parents: 6801
diff changeset
  2488
						}
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2489
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2490
						ReadBlocksInto(&newNode->reserveblock, &buf);
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2491
						ReadBlocksInto(&newNode->releaseblock, &buf);
6737
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2492
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2493
						newNode->next_position = grf_load_byte(&buf);
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2494
						current->next = newNode;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2495
						current = current->next;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2496
					}
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2497
					current->next = NULL;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2498
				}
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2499
				break;
2b971fcc9a08 (svn r10682) [NewGRF_ports] -Feature: Added code to import FSM from within the newgrf, and allocate to compatible structures within Airport. Eventually, it will load to its own dedicated structures.
richk
parents: 6734
diff changeset
  2500
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2501
			case 0x1C: // Entry points
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2502
				fsmportspec->portFSM->entry_points = MallocT<byte>(4);
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2503
				//TODO: store entry points
6835
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2504
				for (uint entry = 0; entry < 4; entry++) {
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2505
					fsmportspec->portFSM->entry_points[entry] = grf_load_byte(&buf);
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2506
				}
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2507
				break;
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2508
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2509
			case 0x1D: // Hangar locations
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  2510
				fsmportspec->portFSM->num_depots = grf_load_byte(&buf);
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6862
diff changeset
  2511
				fsmportspec->portFSM->depots = MallocT<FSMDepots>(fsmportspec->portFSM->num_depots);
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  2512
				for (uint depot = 0; depot < fsmportspec->portFSM->num_depots; depot++) {
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6862
diff changeset
  2513
					FSMDepots fsmdepot;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6862
diff changeset
  2514
					fsmdepot.tile_pos.x = grf_load_byte(&buf);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6862
diff changeset
  2515
					fsmdepot.tile_pos.y = grf_load_byte(&buf);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6862
diff changeset
  2516
					fsmdepot.FSMposition = grf_load_byte(&buf);  //identifies position in FSM associated with main depot location for multi-tile depots
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6862
diff changeset
  2517
					fsmportspec->portFSM->depots[depot] = fsmdepot;
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2518
				}
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2519
				break;
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2520
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2521
			case 0x1E: // Terminal groups
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2522
				{
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2523
					uint num_termgroups = grf_load_byte(&buf);
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2524
					fsmportspec->portFSM->terminals = MallocT<byte>(num_termgroups + 1);
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2525
					fsmportspec->portFSM->terminals[0] = num_termgroups;
6835
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2526
					for (uint terms = 0; terms < num_termgroups; terms++) {
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2527
						fsmportspec->portFSM->terminals[terms + 1] = grf_load_byte(&buf);
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2528
					}
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2529
				}
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2530
				break;
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2531
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2532
			case 0x1F: // Helipad groups
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2533
				{
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2534
					uint num_helipads = grf_load_byte(&buf);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2535
					fsmportspec->portFSM->helipads = MallocT<byte>(num_helipads + 1);
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2536
					fsmportspec->portFSM->helipads[0] = num_helipads;
6835
0364f49694ea (svn r10918) [NewGRF_ports] -Fix: do not mark NewGRF properties as "unknown"/"unhandled" when you have handled them correctly during load.
rubidium
parents: 6817
diff changeset
  2537
					for (uint helipads = 0; helipads < num_helipads; helipads++) {
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6737
diff changeset
  2538
						fsmportspec->portFSM->helipads[helipads + 1] = grf_load_byte(&buf);
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2539
					}
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2540
				}
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2541
				break;
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6732
diff changeset
  2542
6771
5bb52a8ad34e (svn r10825) [NewGRF_ports] -Feature: Airport subtype (prop 20) is now read. This restricts buildlist and usage of airports to the selected vehicle subtype.
richk
parents: 6770
diff changeset
  2543
			case 0x20: // Port Subtype
5bb52a8ad34e (svn r10825) [NewGRF_ports] -Feature: Airport subtype (prop 20) is now read. This restricts buildlist and usage of airports to the selected vehicle subtype.
richk
parents: 6770
diff changeset
  2544
				fsmportspec->portFSM->flags = (AirportFTAClass::Flags)grf_load_byte(&buf);
5bb52a8ad34e (svn r10825) [NewGRF_ports] -Feature: Airport subtype (prop 20) is now read. This restricts buildlist and usage of airports to the selected vehicle subtype.
richk
parents: 6770
diff changeset
  2545
				break;
5bb52a8ad34e (svn r10825) [NewGRF_ports] -Feature: Airport subtype (prop 20) is now read. This restricts buildlist and usage of airports to the selected vehicle subtype.
richk
parents: 6770
diff changeset
  2546
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2547
			case 0x22: // Catchment Area
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2548
				fsmportspec->portFSM->catchment = grf_load_byte(&buf);
6741
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2549
				break;
7d8234e82216 (svn r10741) [NewGRF_ports] -Feature: Added multiblock import from newgrf. Catchment area (Prop 22) added.
richk
parents: 6739
diff changeset
  2550
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2551
			case 0x23: // Define placement layout mask
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2552
				{
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2553
					byte numlayouts = grf_load_byte(&buf);
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2554
					fsmportspec->layout_mask = ReallocT(fsmportspec->layout_mask, numlayouts);
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6800
diff changeset
  2555
					for (uint set = 0; set < numlayouts; set++) {
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2556
						byte orientation = grf_load_byte(&buf);
6817
ef4c1d63b69f (svn r10897) [NewGRF_ports] -Cleanup: Removed superfluous comments.
richk
parents: 6805
diff changeset
  2557
						byte x = grf_load_byte(&buf);
6789
8817427af899 (svn r10861) [NewGRF_ports] -Change: Updates to spec now reflected in newgrf.cpp. No trailing 00 00 in Prop 0E. Prop 19 now identifies which hangar each coordinate is for. (allows multi-tile depots).
richk
parents: 6781
diff changeset
  2558
						byte y = grf_load_byte(&buf);
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2559
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2560
						FSMportsLayout layout;
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2561
						layout = MallocT<byte>((x * y) + 2);
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2562
						layout[0] = orientation;
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2563
						layout[1] = 0x00; //no minipic sprite ID
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6800
diff changeset
  2564
						for (byte l = 2; l < (x * y) + 2; l++) {
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2565
							layout[l] = grf_load_byte(&buf);
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2566
						}
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6800
diff changeset
  2567
						fsmportspec->layout_mask[set] = layout;
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2568
					}
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2569
					grf_load_byte(&buf);
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2570
					grf_load_byte(&buf);
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2571
				}
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2572
				break;
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6766
diff changeset
  2573
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2574
			case 0x24: // Noise of airport
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2575
				fsmportspec->portFSM->noise_level = grf_load_byte(&buf);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2576
				break;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2577
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2578
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2579
				ret = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2580
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2581
		}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2582
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2583
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2584
	*bufp = buf;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2585
	return ret;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2586
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2587
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2588
/* Action 0x00 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2589
static void FeatureChangeInfo(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2590
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2591
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2592
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2593
	/* <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
  2594
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2595
	 * 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
  2596
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2597
	 * 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
  2598
	 * B num-info      how many vehicles/stations to change
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2599
	 * E id            ID of first vehicle/station to change, if num-info is
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2600
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2601
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2602
	 * 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
  2603
	 * 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
  2604
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2605
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  2606
	static const VCI_Handler handler[] = {
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2607
		/* GSF_TRAIN */        RailVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2608
		/* GSF_ROAD */         RoadVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2609
		/* GSF_SHIP */         ShipVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2610
		/* GSF_AIRCRAFT */     AircraftVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2611
		/* GSF_STATION */      StationChangeInfo,
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2612
		/* GSF_CANAL */        CanalChangeInfo,
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2613
		/* GSF_BRIDGE */       BridgeChangeInfo,
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2614
		/* GSF_TOWNHOUSE */    TownHouseChangeInfo,
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2615
		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2616
		/* GSF_INDUSTRYTILES */IndustrytilesChangeInfo,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2617
		/* GSF_INDUSTRIES */   IndustriesChangeInfo,
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2618
		/* GSF_CARGOS */       NULL, /* Cargo is handled during reservation */
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  2619
		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2620
		/* GSF_FSMPORTS */     FSMPortChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2621
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2622
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2623
	if (!check_length(len, 6, "FeatureChangeInfo")) return;
3714
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  2624
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2625
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2626
	uint8 numprops = grf_load_byte(&buf);
6614
b41f2210a494 (svn r9108) -Fix(9093) : MSVC was a bit unhappy with some of the type changes. So basically, widening the types makes the difference
belugas
parents: 6610
diff changeset
  2627
	uint numinfo  = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2628
	uint engine   = grf_load_extended(&buf);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2629
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2630
	grfmsg(6, "FeatureChangeInfo: feature %d, %d properties, to apply to %d+%d",
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  2631
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  2632
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
  2633
	if (feature >= lengthof(handler) || handler[feature] == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2634
		grfmsg(1, "FeatureChangeInfo: Unsupported feature %d, skipping", feature);
391
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2635
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2636
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2637
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2638
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2639
		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
  2640
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2641
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2642
		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
  2643
			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
  2644
			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
  2645
			case GSF_SHIP:
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2646
			case GSF_AIRCRAFT: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2647
				bool handled = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2648
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2649
				for (uint i = 0; i < numinfo; i++) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2650
					Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, engine + i);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2651
					EngineInfo *ei = &e->info;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2652
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2653
					/* Common properties for vehicles */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2654
					switch (prop) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2655
						case 0x00: // Introduction date
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2656
							ei->base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2657
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2658
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2659
						case 0x02: // Decay speed
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2660
							ei->decay_speed = grf_load_byte(&buf);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2661
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2662
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2663
						case 0x03: // Vehicle life
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2664
							ei->lifelength = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2665
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2666
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2667
						case 0x04: // Model life
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2668
							ei->base_life = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2669
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2670
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2671
						case 0x06: // Climates available
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2672
							ei->climates = grf_load_byte(&buf);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2673
							// XXX sometimes a grf wants hidden vehicles :o
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2674
							if (ei->climates == 0) ei->climates = 0x80;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2675
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2676
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2677
						case 0x07: // Loading speed
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2678
							/* Hyronymus explained me what does
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2679
							 * this mean and insists on having a
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2680
							 * credit ;-). --pasky */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2681
							ei->load_amount = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2682
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2683
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2684
						default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2685
							handled = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2686
							break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2687
					}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2688
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2689
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2690
				if (handled) break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2691
			} /* FALL THROUGH */
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2692
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2693
			default:
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2694
				if (handler[feature](engine, numinfo, prop, &buf, bufend - 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
  2695
					ignoring = true;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2696
				}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2697
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2698
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2699
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2700
		if (ignoring) grfmsg(1, "FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented)", prop, feature);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2701
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2702
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2703
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2704
/* Action 0x00 (GLS_SAFETYSCAN) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2705
static void SafeChangeInfo(byte *buf, size_t len)
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2706
{
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2707
	if (!check_length(len, 6, "SafeChangeInfo")) return;
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2708
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2709
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2710
	uint8 numprops = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2711
	grf_load_byte(&buf);     // num-info
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2712
	grf_load_extended(&buf); // id
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2713
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2714
	if (feature == GSF_BRIDGE && numprops == 1) {
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2715
		uint8 prop = grf_load_byte(&buf);
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2716
		/* Bridge property 0x0D is redefinition of sprite layout tables, which
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2717
		 * is considered safe. */
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2718
		if (prop == 0x0D) return;
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2719
	}
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2720
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2721
	SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2722
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2723
	/* Skip remainder of GRF */
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2724
	_skip_sprites = -1;
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2725
}
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  2726
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2727
/* Action 0x00 (GLS_RESERVE) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2728
static void ReserveChangeInfo(byte *buf, size_t len)
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2729
{
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2730
	byte *bufend = buf + len;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2731
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2732
	if (!check_length(len, 6, "ReserveChangeInfo")) return;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2733
	buf++;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2734
	uint8 feature  = grf_load_byte(&buf);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2735
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2736
	if (feature != GSF_CARGOS && feature != GSF_GLOBALVAR) return;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2737
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2738
	uint8 numprops = grf_load_byte(&buf);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2739
	uint8 numinfo  = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2740
	uint8 index    = grf_load_extended(&buf);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2741
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2742
	while (numprops-- && buf < bufend) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2743
		uint8 prop = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2744
		bool ignoring = false;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2745
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2746
		switch (feature) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2747
			default: NOT_REACHED();
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2748
			case GSF_CARGOS:
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2749
				ignoring = CargoChangeInfo(index, numinfo, prop, &buf, bufend - buf);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2750
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2751
			case GSF_GLOBALVAR:
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2752
				switch (prop) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2753
					case 0x09: // Cargo Translation Table
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2754
						if (index != 0) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2755
							grfmsg(1, "ReserveChangeInfo: Cargo translation table must start at zero");
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2756
							return;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2757
						}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2758
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2759
						free(_cur_grffile->cargo_list);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2760
						_cur_grffile->cargo_max = numinfo;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2761
						_cur_grffile->cargo_list = MallocT<CargoLabel>(numinfo);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2762
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2763
						for (uint i = 0; i < numinfo; i++) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2764
							CargoLabel cl = grf_load_dword(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2765
							_cur_grffile->cargo_list[i] = BSWAP32(cl);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2766
						}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2767
						break;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2768
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2769
					case 0x11: // GRF match for engine allocation
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2770
						for (uint i = 0; i < numinfo; i++) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2771
							uint32 s = grf_load_dword(&buf);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2772
							uint32 t = grf_load_dword(&buf);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2773
							SetNewGRFOverride(s, t);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2774
						}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2775
						break;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2776
				}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2777
				break;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2778
		}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2779
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2780
		if (ignoring) grfmsg(2, "ReserveChangeInfo: Ignoring property 0x%02X (not implemented)", prop);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2781
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2782
}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2783
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2784
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2785
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2786
 * @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
  2787
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2788
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2789
static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2790
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2791
	SpriteGroup *group = AllocateSpriteGroup();
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2792
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2793
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2794
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  2795
	/* Old style callback results have the highest byte 0xFF so signify it is a callback result
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  2796
	 * 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
  2797
	if ((value >> 8) == 0xFF) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2798
		value &= ~0xFF00;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2799
	} else {
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2800
		value &= ~0x8000;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2801
	}
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2802
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2803
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2804
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2805
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2806
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2807
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
  2808
/**
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
  2809
 * Creates a spritegroup representing a sprite number result.
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2810
 * @param sprite The sprite number.
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2811
 * @param num_sprites The number of sprites per set.
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
  2812
 * @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
  2813
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2814
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
  2815
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2816
	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
  2817
	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
  2818
	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
  2819
	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
  2820
	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
  2821
}
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
  2822
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2823
/* Action 0x01 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2824
static void NewSpriteSet(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2825
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2826
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2827
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2828
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2829
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2830
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2831
	 * 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
  2832
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2833
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2834
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2835
	 *                         In that case, use num-dirs=4.
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2836
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2837
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2838
	if (!check_length(len, 4, "NewSpriteSet")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2839
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2840
	uint8 feature   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2841
	uint8 num_sets  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2842
	uint16 num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2843
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
  2844
	_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
  2845
	_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
  2846
	_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
  2847
	_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
  2848
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2849
	grfmsg(7, "New sprite set at %d of type %d, consisting of %d sets with %d views each (total %d)",
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2850
		_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
  2851
	);
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
  2852
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2853
	for (int i = 0; i < num_sets * num_ents; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2854
		_nfo_line++;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2855
		LoadNextSprite(_cur_spriteid++, _file_index, _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
  2856
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2857
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2858
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2859
/* Action 0x01 (SKIP) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2860
static void SkipAct1(byte *buf, size_t len)
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2861
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2862
	if (!check_length(len, 4, "SkipAct1")) return;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2863
	buf++;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2864
	grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2865
	uint8 num_sets  = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2866
	uint16 num_ents = grf_load_extended(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2867
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2868
	_skip_sprites = num_sets * num_ents;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2869
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2870
	grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2871
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2872
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
  2873
/* 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
  2874
 * defined spritegroup. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2875
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
  2876
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2877
	if (HasBit(groupid, 15)) return NewCallBackResultSpriteGroup(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
  2878
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
  2879
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2880
		grfmsg(1, "GetGroupFromGroupID(0x%02X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid);
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  2881
		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
  2882
	}
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
  2883
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
  2884
	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
  2885
}
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
  2886
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
  2887
/* 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
  2888
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
  2889
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2890
	if (HasBit(spriteid, 15)) return NewCallBackResultSpriteGroup(spriteid);
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
  2891
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2892
	if (spriteid >= _cur_grffile->spriteset_numsets) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2893
		grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set %u invalid, max %u", setid, type, spriteid, _cur_grffile->spriteset_numsets);
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2894
		return NULL;
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2895
	}
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2896
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
  2897
	/* 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
  2898
	 * 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
  2899
	 * 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
  2900
	if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2901
		grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Real Sprite IDs 0x%04X - 0x%04X do not (all) exist (max 0x%04X), leaving empty",
3666
975cd26c8df7 (svn r4581) - NewGRF: replace replicated action 2 code with two functions to simplify code somewhat. Also check that a sprite id is
peter1138
parents: 3648
diff changeset
  2902
				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
  2903
				_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
  2904
				_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
  2905
		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
  2906
	}
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
  2907
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2908
	if (feature != _cur_grffile->spriteset_feature) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  2909
		grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping",
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2910
				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
  2911
				_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
  2912
		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
  2913
	}
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2914
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
  2915
	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
  2916
}
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
  2917
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2918
/* Action 0x02 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  2919
static void NewSpriteGroup(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2920
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2921
	/* <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
  2922
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2923
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2924
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2925
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2926
	 *                 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
  2927
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2928
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2929
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2930
	 * V feature-specific-data (huge mess, don't even look it up --pasky) */
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2931
	SpriteGroup *group = NULL;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2932
	byte *bufend = buf + len;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2933
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2934
	if (!check_length(len, 5, "NewSpriteGroup")) return;
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2935
	buf++;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2936
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2937
	uint8 feature = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2938
	uint8 setid   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2939
	uint8 type    = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2940
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
  2941
	if (setid >= _cur_grffile->spritegroups_count) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  2942
		/* Allocate memory for new sprite group references. */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  2943
		_cur_grffile->spritegroups = ReallocT(_cur_grffile->spritegroups, setid + 1);
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  2944
		/* Initialise new space to NULL */
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2945
		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
  2946
			_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
  2947
	}
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
  2948
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2949
	switch (type) {
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2950
		/* Deterministic Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2951
		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
  2952
		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
  2953
		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
  2954
		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
  2955
		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
  2956
		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
  2957
		{
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
  2958
			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
  2959
			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
  2960
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2961
			/* Check we can load the var size parameter */
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2962
			if (!check_length(bufend - buf, 1, "NewSpriteGroup (Deterministic) (1)")) return;
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2963
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2964
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2965
			group->type = SGT_DETERMINISTIC;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2966
			group->g.determ.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
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
  2967
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2968
			switch (GB(type, 2, 2)) {
3672
73caf2e829f8 (svn r4588) - NewGRF: silence a false compiler warning
peter1138
parents: 3668
diff changeset
  2969
				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
  2970
				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
  2971
				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
  2972
				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
  2973
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2974
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2975
			if (!check_length(bufend - buf, 5 + varsize, "NewSpriteGroup (Deterministic) (2)")) return;
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
  2976
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2977
			/* 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
  2978
			 * 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
  2979
			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
  2980
				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
  2981
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2982
				if (group->g.determ.num_adjusts > 0) {
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  2983
					if (!check_length(bufend - buf, 2 + varsize + 3, "NewSpriteGroup (Deterministic) (3)")) return;
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
  2984
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2985
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2986
				group->g.determ.num_adjusts++;
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  2987
				group->g.determ.adjusts = ReallocT(group->g.determ.adjusts, group->g.determ.num_adjusts);
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
  2988
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2989
				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
  2990
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2991
				/* The first var adjust doesn't have an operation specified, so we set it to add. */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2992
				adjust->operation = group->g.determ.num_adjusts == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)grf_load_byte(&buf);
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
  2993
				adjust->variable  = grf_load_byte(&buf);
5868
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2994
				if (adjust->variable == 0x7E) {
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2995
					/* Link subroutine group */
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2996
					adjust->subroutine = GetGroupFromGroupID(setid, type, grf_load_byte(&buf));
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2997
				} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2998
					adjust->parameter = IsInsideMM(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0;
5868
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2999
				}
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
  3000
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3001
				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
  3002
				adjust->shift_num = GB(varadjust, 0, 5);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  3003
				adjust->type      = (DeterministicSpriteGroupAdjustType)GB(varadjust, 6, 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
  3004
				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
  3005
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3006
				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
  3007
					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
  3008
					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
  3009
				} 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
  3010
					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
  3011
					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
  3012
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3013
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3014
				/* Continue reading var adjusts while bit 5 is set. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3015
			} while (HasBit(varadjust, 5));
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
  3016
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3017
			group->g.determ.num_ranges = grf_load_byte(&buf);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3018
			if (group->g.determ.num_ranges > 0) group->g.determ.ranges = CallocT<DeterministicSpriteGroupRange>(group->g.determ.num_ranges);
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
  3019
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  3020
			if (!check_length(bufend - buf, 2 + (2 + 2 * varsize) * group->g.determ.num_ranges, "NewSpriteGroup (Deterministic)")) return;
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
  3021
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3022
			for (uint i = 0; i < group->g.determ.num_ranges; i++) {
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
  3023
				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
  3024
				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
  3025
				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
  3026
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3027
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
  3028
			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
  3029
			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
  3030
		}
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
  3031
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3032
		/* Randomized Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3033
		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
  3034
		case 0x83: // Parent scope
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3035
		case 0x84: // Relative scope
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3036
		{
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3037
			if (!check_length(bufend - buf, HasBit(type, 2) ? 8 : 7, "NewSpriteGroup (Randomized) (1)")) return;
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3038
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3039
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3040
			group->type = SGT_RANDOMIZED;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3041
			group->g.random.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
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
  3042
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3043
			if (HasBit(type, 2)) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3044
				if (feature <= GSF_AIRCRAFT) group->g.random.var_scope = VSG_SCOPE_RELATIVE;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3045
				group->g.random.count = grf_load_byte(&buf);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3046
			}
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3047
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3048
			uint8 triggers = grf_load_byte(&buf);
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
  3049
			group->g.random.triggers       = GB(triggers, 0, 7);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3050
			group->g.random.cmp_mode       = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
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
  3051
			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
  3052
			group->g.random.num_groups     = grf_load_byte(&buf);
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  3053
			group->g.random.groups = CallocT<const SpriteGroup*>(group->g.random.num_groups);
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
  3054
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  3055
			if (!check_length(bufend - buf, 2 * group->g.random.num_groups, "NewSpriteGroup (Randomized) (2)")) return;
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
  3056
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3057
			for (uint i = 0; i < group->g.random.num_groups; i++) {
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
  3058
				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
  3059
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3060
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3061
			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
  3062
		}
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3063
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
  3064
		/* 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
  3065
		default:
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3066
		{
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  3067
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  3068
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
  3069
			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
  3070
				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
  3071
				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
  3072
				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
  3073
				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
  3074
				case GSF_STATION:
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3075
				case GSF_CANAL:
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3076
				case GSF_CARGOS:
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3077
				case GSF_FSMPORTS:
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
  3078
				{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3079
					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
  3080
					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
  3081
					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
  3082
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3083
					if (_cur_grffile->spriteset_start == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3084
						grfmsg(0, "NewSpriteGroup: No sprite set to work on! Skipping");
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3085
						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
  3086
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3087
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  3088
					if (!check_length(bufend - buf, 2 * num_loaded + 2 * num_loading, "NewSpriteGroup (Real) (1)")) return;
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
  3089
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3090
					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
  3091
					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
  3092
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3093
					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
  3094
					group->g.real.num_loading = num_loading;
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  3095
					if (num_loaded  > 0) group->g.real.loaded = CallocT<const SpriteGroup*>(num_loaded);
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  3096
					if (num_loading > 0) group->g.real.loading = CallocT<const SpriteGroup*>(num_loading);
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3097
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3098
					grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading",
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3099
							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
  3100
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3101
					for (uint i = 0; i < num_loaded; i++) {
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
  3102
						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
  3103
						group->g.real.loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3104
						grfmsg(8, "NewSpriteGroup: + rg->loaded[%i]  = subset %u", i, spriteid);
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3105
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3106
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3107
					for (uint i = 0; i < num_loading; i++) {
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
  3108
						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
  3109
						group->g.real.loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid, sprites);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3110
						grfmsg(8, "NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
3668
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3111
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3112
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3113
					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
  3114
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  3115
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3116
				case GSF_TOWNHOUSE:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3117
				case GSF_INDUSTRYTILES: {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3118
					byte sprites     = _cur_grffile->spriteset_numents;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3119
					byte num_sprites = max((uint8)1, type);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3120
					uint i;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3121
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3122
					group = AllocateSpriteGroup();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3123
					group->type = SGT_TILELAYOUT;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3124
					group->g.layout.num_sprites = sprites;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3125
					group->g.layout.dts = CallocT<DrawTileSprites>(1);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3126
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3127
					/* Groundsprite */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3128
					group->g.layout.dts->ground.sprite = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3129
					group->g.layout.dts->ground.pal    = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3130
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3131
					/* Remap transparent/colour modifier bits */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3132
					MapSpriteMappingRecolour(&group->g.layout.dts->ground);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3133
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3134
					if (HasBit(group->g.layout.dts->ground.pal, 15)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3135
						/* Bit 31 set means this is a custom sprite, so rewrite it to the
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3136
						 * last spriteset defined. */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3137
						SpriteID sprite = _cur_grffile->spriteset_start + GB(group->g.layout.dts->ground.sprite, 0, 14) * sprites;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3138
						SB(group->g.layout.dts->ground.sprite, 0, SPRITE_WIDTH, sprite);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3139
						ClrBit(group->g.layout.dts->ground.pal, 15);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3140
					}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3141
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3142
					group->g.layout.dts->seq = CallocT<DrawTileSeqStruct>(num_sprites + 1);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3143
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3144
					for (i = 0; i < num_sprites; i++) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3145
						DrawTileSeqStruct *seq = (DrawTileSeqStruct*)&group->g.layout.dts->seq[i];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3146
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3147
						seq->image.sprite = grf_load_word(&buf);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3148
						seq->image.pal   = grf_load_word(&buf);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3149
						seq->delta_x = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3150
						seq->delta_y = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3151
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3152
						MapSpriteMappingRecolour(&seq->image);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3153
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3154
						if (HasBit(seq->image.pal, 15)) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3155
							/* Bit 31 set means this is a custom sprite, so rewrite it to the
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3156
							 * last spriteset defined. */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3157
							SpriteID sprite = _cur_grffile->spriteset_start + GB(seq->image.sprite, 0, 14) * sprites;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3158
							SB(seq->image.sprite, 0, SPRITE_WIDTH, sprite);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3159
							ClrBit(seq->image.pal, 15);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3160
						}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3161
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3162
						if (type > 0) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3163
							seq->delta_z = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3164
							if ((byte)seq->delta_z == 0x80) continue;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3165
						}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3166
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3167
						seq->size_x = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3168
						seq->size_y = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3169
						seq->size_z = grf_load_byte(&buf);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3170
					}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3171
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3172
					/* Set the terminator value. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3173
					((DrawTileSeqStruct*)group->g.layout.dts->seq)[i].delta_x = (byte)0x80;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3174
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3175
					break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3176
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3177
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3178
				case GSF_INDUSTRIES: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3179
					if (type > 1) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3180
						grfmsg(1, "NewSpriteGroup: Unsupported industry production version %d, skipping", type);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3181
						break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3182
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3183
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3184
					group = AllocateSpriteGroup();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3185
					group->type = SGT_INDUSTRY_PRODUCTION;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3186
					group->g.indprod.version = type;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3187
					if (type == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3188
						for (uint i = 0; i < 3; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3189
							group->g.indprod.substract_input[i] = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3190
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3191
						for (uint i = 0; i < 2; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3192
							group->g.indprod.add_output[i] = grf_load_word(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3193
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3194
						group->g.indprod.again = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3195
					} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3196
						for (uint i = 0; i < 3; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3197
							group->g.indprod.substract_input[i] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3198
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3199
						for (uint i = 0; i < 2; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3200
							group->g.indprod.add_output[i] = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3201
						}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3202
						group->g.indprod.again = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3203
					}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3204
					break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3205
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3206
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
  3207
				/* Loading of Tile Layout and Production Callback groups would happen here */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3208
				default: grfmsg(1, "NewSpriteGroup: Unsupported feature %d, skipping", feature);
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  3209
			}
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
  3210
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3211
	}
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
  3212
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
  3213
	_cur_grffile->spritegroups[setid] = group;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3215
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3216
static CargoID TranslateCargo(uint8 feature, uint8 ctype)
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3217
{
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3218
	/* Special cargo types for purchase list and stations */
6474
24e7ceeb25f5 (svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents: 6473
diff changeset
  3219
	if (feature == GSF_STATION && ctype == 0xFE) return CT_DEFAULT_NA;
24e7ceeb25f5 (svn r8891) -Codechange: Remove remains of global cargo scheme. All cargo mapping is now dealt with only in NewGRF code, on load where possible.
peter1138
parents: 6473
diff changeset
  3220
	if (ctype == 0xFF) return CT_PURCHASE;
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3221
6687
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3222
	if (_cur_grffile->cargo_max == 0) {
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3223
		/* No cargo table, so use bitnum values */
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3224
		if (ctype >= 32) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3225
			grfmsg(1, "TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype);
6687
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3226
			return CT_INVALID;
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3227
		}
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3228
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3229
		for (CargoID c = 0; c < NUM_CARGO; c++) {
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3230
			const CargoSpec *cs = GetCargo(c);
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3231
			if (!cs->IsValid()) continue;
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3232
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3233
			if (cs->bitnum == ctype) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3234
				grfmsg(6, "TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, c);
6687
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3235
				return c;
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3236
			}
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3237
		}
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3238
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3239
		grfmsg(5, "TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype);
6687
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3240
		return CT_INVALID;
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3241
	}
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3242
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3243
	/* Check if the cargo type is out of bounds of the cargo translation table */
6687
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3244
	if (ctype >= _cur_grffile->cargo_max) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3245
		grfmsg(1, "TranslateCargo: Cargo type %d out of range (max %d), skipping.", ctype, _cur_grffile->cargo_max - 1);
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3246
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3247
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3248
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3249
	/* Look up the cargo label from the translation table */
6687
d2ef5eda4562 (svn r9413) -Codechange: Remove default cargo translation table and use bitnums directly if no table is provided. This lets pre-cargolabel cargo definitions work.
peter1138
parents: 6685
diff changeset
  3250
	CargoLabel cl = _cur_grffile->cargo_list[ctype];
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3251
	if (cl == 0) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3252
		grfmsg(5, "TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype);
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3253
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3254
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3255
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3256
	ctype = GetCargoIDByLabel(cl);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3257
	if (ctype == CT_INVALID) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3258
		grfmsg(5, "TranslateCargo: Cargo '%c%c%c%c' unsupported, skipping.", GB(cl, 24, 8), GB(cl, 16, 8), GB(cl, 8, 8), GB(cl, 0, 8));
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3259
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3260
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3261
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3262
	grfmsg(6, "TranslateCargo: Cargo '%c%c%c%c' mapped to cargo type %d.", GB(cl, 24, 8), GB(cl, 16, 8), GB(cl, 8, 8), GB(cl, 0, 8), ctype);
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3263
	return ctype;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3264
}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  3265
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3266
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3267
static bool IsValidGroupID(uint16 groupid, const char *function)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3268
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3269
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3270
		grfmsg(1, "%s: Spriteset 0x%04X out of range (maximum 0x%02X) or empty, skipping.", function, groupid, _cur_grffile->spritegroups_count - 1);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3271
		return false;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3272
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3273
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3274
	return true;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3275
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3276
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3277
static void VehicleMapSpriteGroup(byte *buf, byte feature, uint8 idcount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3278
{
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3279
	static EngineID *last_engines;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3280
	static uint last_engines_count;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3281
	bool wagover = false;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3282
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3283
	/* Test for 'wagon override' flag */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3284
	if (HasBit(idcount, 7)) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3285
		wagover = true;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3286
		/* Strip off the flag */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3287
		idcount = GB(idcount, 0, 7);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3288
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  3289
		if (last_engines_count == 0) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3290
			grfmsg(0, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with");
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  3291
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  3292
		}
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3293
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3294
		grfmsg(6, "VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3295
				last_engines_count, idcount);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3296
	} else {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3297
		if (last_engines_count != idcount) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3298
			last_engines = ReallocT(last_engines, idcount);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3299
			last_engines_count = idcount;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3300
		}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3301
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3302
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3303
	EngineID *engines = AllocaM(EngineID, idcount);
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3304
	for (uint i = 0; i < idcount; i++) {
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3305
		engines[i] = GetNewEngine(_cur_grffile, (VehicleType)feature, grf_load_extended(&buf))->index;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3306
		if (!wagover) last_engines[i] = engines[i];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3307
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3308
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3309
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3310
	for (uint c = 0; c < cidcount; c++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3311
		uint8 ctype = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3312
		uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3313
		if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) continue;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3314
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3315
		grfmsg(8, "VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3316
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3317
		ctype = TranslateCargo(feature, ctype);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3318
		if (ctype == CT_INVALID) continue;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3319
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3320
		for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3321
			EngineID engine = engines[i];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3322
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3323
			grfmsg(7, "VehicleMapSpriteGroup: [%d] Engine %d...", i, engine);
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
  3324
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3325
			if (wagover) {
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  3326
				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
  3327
			} 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
  3328
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3329
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3330
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3331
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3332
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3333
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3334
	if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) return;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3335
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3336
	grfmsg(8, "-- Default group id 0x%04X", groupid);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3337
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3338
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3339
		EngineID engine = engines[i];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3340
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3341
		if (wagover) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3342
			SetWagonOverrideSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3343
		} else {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3344
			SetCustomEngineSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid]);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3345
			SetEngineGRF(engine, _cur_grffile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3346
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3347
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3348
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3349
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3350
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3351
static void CanalMapSpriteGroup(byte *buf, uint8 idcount)
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3352
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3353
	CanalFeature *cfs = AllocaM(CanalFeature, idcount);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3354
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3355
		cfs[i] = (CanalFeature)grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3356
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3357
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3358
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3359
	buf += cidcount * 3;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3360
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3361
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3362
	if (!IsValidGroupID(groupid, "CanalMapSpriteGroup")) return;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3363
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3364
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3365
		CanalFeature cf = cfs[i];
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3366
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3367
		if (cf >= CF_END) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3368
			grfmsg(1, "CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3369
			continue;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3370
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3371
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3372
		_water_feature[cf].group = _cur_grffile->spritegroups[groupid];
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3373
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3374
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3375
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3376
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3377
static void StationMapSpriteGroup(byte *buf, uint8 idcount)
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3378
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3379
	uint8 *stations = AllocaM(uint8, idcount);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3380
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3381
		stations[i] = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3382
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3383
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3384
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3385
	for (uint c = 0; c < cidcount; c++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3386
		uint8 ctype = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3387
		uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3388
		if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) continue;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3389
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3390
		ctype = TranslateCargo(GSF_STATION, ctype);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3391
		if (ctype == CT_INVALID) continue;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3392
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3393
		for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3394
			StationSpec *statspec = _cur_grffile->stations[stations[i]];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3395
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3396
			if (statspec == NULL) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3397
				grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3398
				return;
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3399
			}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3400
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3401
			statspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid];
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3402
		}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3403
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3404
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3405
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3406
	if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) return;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3407
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3408
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3409
		StationSpec *statspec = _cur_grffile->stations[stations[i]];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3410
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3411
		if (statspec == NULL) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3412
			grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3413
			continue;
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3414
		}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3415
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3416
		statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3417
		statspec->grffile = _cur_grffile;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3418
		statspec->localidx = stations[i];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3419
		SetCustomStationSpec(statspec);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3420
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3421
}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3422
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3423
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3424
static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount)
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3425
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3426
	uint8 *houses = AllocaM(uint8, idcount);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3427
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3428
		houses[i] = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3429
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3430
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3431
	/* Skip the cargo type section, we only care about the default group */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3432
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3433
	buf += cidcount * 3;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3434
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3435
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3436
	if (!IsValidGroupID(groupid, "TownHouseMapSpriteGroup")) return;
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3437
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3438
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3439
		HouseSpec *hs = _cur_grffile->housespec[houses[i]];
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3440
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3441
		if (hs == NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3442
			grfmsg(1, "TownHouseMapSpriteGroup: Too many houses defined, skipping");
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3443
			return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3444
		}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3445
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3446
		hs->spritegroup = _cur_grffile->spritegroups[groupid];
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3447
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3448
}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3449
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3450
static void IndustryMapSpriteGroup(byte *buf, uint8 idcount)
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3451
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3452
	uint8 *industries = AllocaM(uint8, idcount);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3453
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3454
		industries[i] = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3455
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3456
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3457
	/* Skip the cargo type section, we only care about the default group */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3458
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3459
	buf += cidcount * 3;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3460
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3461
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3462
	if (!IsValidGroupID(groupid, "IndustryMapSpriteGroup")) return;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3463
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3464
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3465
		IndustrySpec *indsp = _cur_grffile->industryspec[industries[i]];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3466
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3467
		if (indsp == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3468
			grfmsg(1, "IndustryMapSpriteGroup: Too many industries defined, skipping");
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3469
			return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3470
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3471
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3472
		indsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3473
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3474
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3475
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3476
static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount)
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3477
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3478
	uint8 *indtiles = AllocaM(uint8, idcount);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3479
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3480
		indtiles[i] = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3481
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3482
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3483
	/* Skip the cargo type section, we only care about the default group */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3484
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3485
	buf += cidcount * 3;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3486
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3487
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3488
	if (!IsValidGroupID(groupid, "IndustrytileMapSpriteGroup")) return;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3489
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3490
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3491
		IndustryTileSpec *indtsp = _cur_grffile->indtspec[indtiles[i]];
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3492
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3493
		if (indtsp == NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3494
			grfmsg(1, "IndustrytileMapSpriteGroup: Too many industry tiles defined, skipping");
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3495
			return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3496
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3497
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3498
		indtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3499
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3500
}
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3501
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3502
static void CargoMapSpriteGroup(byte *buf, uint8 idcount)
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3503
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3504
	CargoID *cargos = AllocaM(CargoID, idcount);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3505
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3506
		cargos[i] = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3507
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3508
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3509
	/* Skip the cargo type section, we only care about the default group */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3510
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3511
	buf += cidcount * 3;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3512
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3513
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3514
	if (!IsValidGroupID(groupid, "CargoMapSpriteGroup")) return;
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3515
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3516
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3517
		CargoID cid = cargos[i];
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3518
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3519
		if (cid >= NUM_CARGO) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3520
			grfmsg(1, "CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid);
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3521
			continue;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3522
		}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3523
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3524
		CargoSpec *cs = &_cargo[cid];
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3525
		cs->grfid = _cur_grffile->grfid;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3526
		cs->group = _cur_grffile->spritegroups[groupid];
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3527
	}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3528
}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3529
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3530
static void FSMportsMapSpriteGroup(byte *buf, uint8 idcount)
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3531
{
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3532
	uint8 *stations = (uint8*)alloca(idcount * sizeof(*stations));
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3533
	for (uint i = 0; i < idcount; i++) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3534
		stations[i] = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3535
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3536
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3537
	uint8 cidcount = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3538
	for (uint c = 0; c < cidcount; c++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3539
		uint8 ctype = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3540
		uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3541
		if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) continue;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3542
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3543
		ctype = TranslateCargo(GSF_STATION, ctype);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3544
		if (ctype == CT_INVALID) continue;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3545
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3546
		for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3547
			FSMportsSpec *fsmportsspec = _cur_grffile->fsmports[stations[i]];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3548
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3549
			if (fsmportsspec == NULL) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3550
				grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3551
				return;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3552
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3553
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3554
			fsmportsspec->spritegroup[ctype] = _cur_grffile->spritegroups[groupid];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3555
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3556
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3557
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3558
	uint16 groupid = grf_load_word(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3559
	if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) return;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3560
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3561
	for (uint i = 0; i < idcount; i++) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3562
		FSMportsSpec *fsmportsspec = _cur_grffile->fsmports[stations[i]];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3563
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3564
		if (fsmportsspec == NULL) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3565
			grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3566
			continue;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3567
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3568
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3569
		fsmportsspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3570
		fsmportsspec->grffile = _cur_grffile;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3571
		fsmportsspec->localidx = stations[i];
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3572
		SetCustomFSMportsSpec(fsmportsspec);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3573
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3574
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3575
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3576
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3577
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3578
/* Action 0x03 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3579
static void FeatureMapSpriteGroup(byte *buf, size_t len)
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3580
{
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3581
	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3582
	 * id-list    := [<id>] [id-list]
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3583
	 * cargo-list := <cargo-type> <cid> [cargo-list]
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3584
	 *
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3585
	 * B feature       see action 0
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3586
	 * B n-id          bits 0-6: how many IDs this definition applies to
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3587
	 *                 bit 7: if set, this is a wagon override definition (see below)
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3588
	 * B ids           the IDs for which this definition applies
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3589
	 * B num-cid       number of cargo IDs (sprite group IDs) in this definition
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3590
	 *                 can be zero, in that case the def-cid is used always
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3591
	 * B cargo-type    type of this cargo type (e.g. mail=2, wood=7, see below)
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3592
	 * W cid           cargo ID (sprite group ID) for this type of cargo
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3593
	 * W def-cid       default cargo ID (sprite group ID) */
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3594
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3595
	if (_cur_grffile->spritegroups == 0) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3596
		grfmsg(1, "FeatureMapSpriteGroup: No sprite groups to work on! Skipping");
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3597
		return;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3598
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3599
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3600
	if (!check_length(len, 6, "FeatureMapSpriteGroup")) return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3601
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3602
	buf++;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3603
	uint8 feature = grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3604
	uint8 idcount = grf_load_byte(&buf);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3605
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3606
	/* If idcount is zero, this is a feature callback */
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3607
	if (idcount == 0) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3608
		/* Skip number of cargo ids? */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3609
		grf_load_byte(&buf);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3610
		uint16 groupid = grf_load_word(&buf);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3611
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3612
		grfmsg(6, "FeatureMapSpriteGroup: Adding generic feature callback for feature %d", feature);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3613
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3614
		AddGenericCallback(feature, _cur_grffile, _cur_grffile->spritegroups[groupid]);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3615
		return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3616
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3617
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3618
	grfmsg(6, "FeatureMapSpriteGroup: Feature %d, %d ids", feature, idcount);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3619
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3620
	switch (feature) {
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3621
		case GSF_TRAIN:
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3622
		case GSF_ROAD:
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3623
		case GSF_SHIP:
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3624
		case GSF_AIRCRAFT:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3625
			VehicleMapSpriteGroup(buf, feature, idcount);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3626
			return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3627
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3628
		case GSF_CANAL:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3629
			CanalMapSpriteGroup(buf, idcount);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3630
			return;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3631
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3632
		case GSF_STATION:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3633
			StationMapSpriteGroup(buf, idcount);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3634
			return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3635
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3636
		case GSF_TOWNHOUSE:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3637
			TownHouseMapSpriteGroup(buf, idcount);
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3638
			return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3639
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3640
		case GSF_INDUSTRIES:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3641
			IndustryMapSpriteGroup(buf, idcount);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3642
			return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3643
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3644
		case GSF_INDUSTRYTILES:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3645
			IndustrytileMapSpriteGroup(buf, idcount);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3646
			return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3647
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3648
		case GSF_CARGOS:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3649
			CargoMapSpriteGroup(buf, idcount);
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3650
			return;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3651
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3652
		case GSF_FSMPORTS:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3653
			FSMportsMapSpriteGroup(buf, idcount);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3654
			return;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  3655
6689
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3656
		default:
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3657
			grfmsg(1, "FeatureMapSpriteGroup: Unsupported feature %d, skipping", feature);
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3658
			return;
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3659
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3660
}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3661
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3662
/* Action 0x04 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3663
static void FeatureNewName(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3664
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3665
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3666
	 *
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3667
	 * B veh-type      see action 0 (as 00..07, + 0A
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3668
	 *                 But IF veh-type = 48, then generic text
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3669
	 * 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
  3670
	                   with up to 64 language.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3671
	                   Otherwise, it is a mapping where set bits have meaning
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3672
	                   0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3673
	                   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
  3674
	 * 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
  3675
	 * 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
  3676
	 *                 Byte : ID of vehicle to change
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3677
	 *                 Word : ID of string to change/add
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3678
	 * 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
  3679
	 *                 which the next name begins. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3680
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
  3681
	bool new_scheme = _cur_grffile->grf_version >= 7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3682
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  3683
	if (!check_length(len, 6, "FeatureNewName")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3684
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3685
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3686
	uint8 lang     = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3687
	uint8 num      = grf_load_byte(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3688
	bool generic   = HasBit(lang, 7);
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3689
	uint16 id;
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3690
	if (generic) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3691
		id = grf_load_word(&buf);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3692
	} else if (feature <= GSF_AIRCRAFT) {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3693
		id = grf_load_extended(&buf);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3694
	} else {
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3695
		id = grf_load_byte(&buf);
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3696
	}
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
  3697
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3698
	ClrBit(lang, 7);
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3699
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3700
	uint16 endid = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3701
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3702
	grfmsg(6, "FeatureNewName: About to rename engines %d..%d (feature %d) in language 0x%02X",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3703
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3704
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
  3705
	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
  3706
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3707
	for (; id < endid && len > 0; id++) {
6416
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3708
		const char *name   = grf_load_string(&buf, len);
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3709
		size_t name_length = strlen(name) + 1;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3710
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3711
		len -= (int)name_length;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3712
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3713
		grfmsg(8, "FeatureNewName: 0x%04X <- %s", id, name);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3714
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3715
		switch (feature) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3716
			case GSF_TRAIN:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3717
			case GSF_ROAD:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3718
			case GSF_SHIP:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3719
			case GSF_AIRCRAFT:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3720
				if (!generic) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3721
					Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, id);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3722
					StringID string = AddGRFString(_cur_grffile->grfid, e->index, lang, new_scheme, name, e->info.string_id);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3723
					e->info.string_id = string;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3724
				} else {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3725
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  3726
				}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3727
				break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3728
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3729
			case GSF_INDUSTRIES: {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3730
				AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3731
				break;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3732
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3733
6755
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3734
			case GSF_FSMPORTS: {
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3735
				switch (GB(id, 8, 8)) {
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3736
					case 0xCD: // FSMport class name
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3737
						if (_cur_grffile->fsmports == NULL || _cur_grffile->fsmports[GB(id, 0, 8)] == NULL) {
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3738
							grfmsg(1, "FeatureNewName: Attempt to name undefined fsmport class 0x%X, ignoring", GB(id, 0, 8));
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3739
						} else {
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3740
							FSMportsClassID sclass = _cur_grffile->fsmports[GB(id, 0, 8)]->sclass;
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3741
							SetFSMportsClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3742
						}
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3743
						break;
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3744
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3745
					case 0xCE: // FSMport name
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3746
						if (_cur_grffile->fsmports == NULL || _cur_grffile->fsmports[GB(id, 0, 8)] == NULL) {
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3747
							grfmsg(1, "FeatureNewName: Attempt to name undefined fsmport 0x%X, ignoring", GB(id, 0, 8));
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3748
						} else {
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3749
							_cur_grffile->fsmports[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3750
						}
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3751
						break;
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3752
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3753
					default:
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3754
						grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3755
						break;
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3756
				}
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3757
				break;
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3758
			}
1997cef8a94f (svn r10795) [NewGRF_ports] -Change: GSF_FSMPORTS now uses separate explicit Case, rather than default fallthrough.
richk
parents: 6750
diff changeset
  3759
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3760
			case GSF_TOWNHOUSE:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3761
			default:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3762
				switch (GB(id, 8, 8)) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3763
					case 0xC4: // Station class name
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3764
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3765
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3766
						} else {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3767
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3768
							SetStationClassName(sclass, AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED));
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  3769
						}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3770
						break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3771
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3772
					case 0xC5: // Station name
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3773
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3774
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3775
						} else {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3776
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3777
						}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3778
						break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3779
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3780
					case 0xC9: // House name
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3781
						if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3782
							grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3783
						} else {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  3784
							_cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3785
						}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3786
						break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3787
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3788
					case 0xD0:
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3789
					case 0xD1:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3790
					case 0xD2:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3791
					case 0xD3:
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3792
					case 0xDC:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3793
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3794
						break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3795
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3796
					default:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3797
						grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3798
						break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3799
				}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3800
				break;
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  3801
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  3802
#if 0
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3803
				case GSF_CANAL :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3804
				case GSF_BRIDGE :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3805
					AddGRFString(_cur_spriteid, id, lang, name);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3806
					switch (GB(id, 8, 8)) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  3807
						case 0xC9: // House name
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3808
						default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3809
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3810
					}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3811
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3812
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3813
				default :
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3814
					grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3815
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3816
#endif
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3817
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3818
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3819
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3820
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3821
/**
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3822
 * Sanitize incoming sprite offsets for Action 5 graphics replacements.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3823
 * @param num         the number of sprites to load.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3824
 * @param offset      offset from the base.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3825
 * @param max_sprites the maximum number of sprites that can be loaded in this action 5.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3826
 * @param name        used for error warnings.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3827
 * @return the number of sprites that is going to be skipped
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3828
 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3829
static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites, const char *name)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3830
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3831
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3832
	if (offset >= max_sprites) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3833
		grfmsg(1, "GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3834
		uint orig_num = num;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3835
		num = 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3836
		return orig_num;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3837
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3838
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3839
	if (offset + num > max_sprites) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3840
		grfmsg(4, "GraphicsNew: %s sprite overflow, truncating...", name);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3841
		uint orig_num = num;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3842
		num = max(max_sprites - offset, 0);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3843
		return orig_num - num;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3844
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3845
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3846
	return 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3847
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3848
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3849
/* Action 0x05 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3850
static void GraphicsNew(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3851
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3852
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3853
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3854
	 * 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
  3855
	 * 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
  3856
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3857
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3858
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3859
	enum Action5BlockType {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3860
		A5BLOCK_FIXED,                ///< Only allow replacing a whole block of sprites. (TTDP compatible)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3861
		A5BLOCK_ALLOW_OFFSET,         ///< Allow replacing any subset by specifiing an offset.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3862
		A5BLOCK_INVALID,              ///< unknown/not-implemented type
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3863
	};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3864
	struct Action5Type {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3865
		Action5BlockType block_type;  ///< How is this Action5 type processed?
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3866
		SpriteID sprite_base;         ///< Load the sprites starting from this sprite.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3867
		uint16 min_sprites;           ///< If the Action5 contains less sprites, the whole block will be ignored.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3868
		uint16 max_sprites;           ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3869
		const char *name;             ///< Name for error messages.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3870
	};
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3871
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3872
	static const Action5Type action5_types[] = {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3873
		/* Note: min_sprites should not be changed. Therefore these constants are directly here and not in sprites.h */
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3874
		/* 0x00 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x00"             },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3875
		/* 0x01 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x01"             },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3876
		/* 0x02 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x02"             },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3877
		/* 0x03 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x03"             },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3878
		/* 0x04 */ { A5BLOCK_FIXED,        SPR_SIGNALS_BASE,            48, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,    "Signal graphics"       },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3879
		/* 0x05 */ { A5BLOCK_FIXED,        SPR_ELRAIL_BASE,             48, ELRAIL_SPRITE_COUNT,                         "Catenary graphics"     },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3880
		/* 0x06 */ { A5BLOCK_FIXED,        SPR_SLOPES_BASE,             74, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, "Foundation graphics"   },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3881
		/* 0x07 */ { A5BLOCK_INVALID,      0,                           75, 0,                                           "TTDP GUI graphics"     }, // Not used by OTTD.
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3882
		/* 0x08 */ { A5BLOCK_FIXED,        SPR_CANALS_BASE,             65, CANALS_SPRITE_COUNT,                         "Canal graphics"        },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3883
		/* 0x09 */ { A5BLOCK_FIXED,        SPR_ONEWAY_BASE,              6, ONEWAY_SPRITE_COUNT,                         "One way road graphics" },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3884
		/* 0x0A */ { A5BLOCK_FIXED,        SPR_2CCMAP_BASE,            256, TWOCCMAP_SPRITE_COUNT,                       "2CC colour maps"       },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3885
		/* 0x0B */ { A5BLOCK_FIXED,        SPR_TRAMWAY_BASE,           113, TRAMWAY_SPRITE_COUNT,                        "Tramway graphics"      },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3886
		/* 0x0C */ { A5BLOCK_INVALID,      0,                          133, 0,                                           "Snowy temperate tree"  }, // Not yet used by OTTD.
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3887
		/* 0x0D */ { A5BLOCK_FIXED,        SPR_SHORE_BASE,              16, SPR_SHORE_SPRITE_COUNT,                      "Shore graphics"        },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3888
		/* 0x0E */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "New Signals graphics"  }, // Not yet used by OTTD.
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3889
		/* 0x0F */ { A5BLOCK_FIXED,        SPR_TRACKS_FOR_SLOPES_BASE,  12, TRACKS_FOR_SLOPES_SPRITE_COUNT,              "Sloped rail track"     },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3890
		/* 0x10 */ { A5BLOCK_FIXED,        SPR_AIRPORTX_BASE,           15, AIRPORTX_SPRITE_COUNT,                       "Airport graphics"      },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3891
		/* 0x11 */ { A5BLOCK_FIXED,        SPR_ROADSTOP_BASE,            8, ROADSTOP_SPRITE_COUNT,                       "Road stop graphics"    },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3892
		/* 0x12 */ { A5BLOCK_FIXED,        SPR_AQUEDUCT_BASE,            8, AQUEDUCT_SPRITE_COUNT,                       "Aqueduct graphics"     },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3893
		/* 0x13 */ { A5BLOCK_FIXED,        SPR_AUTORAIL_BASE,           55, AUTORAIL_SPRITE_COUNT,                       "Autorail graphics"     },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3894
		/* 0x14 */ { A5BLOCK_ALLOW_OFFSET, SPR_FLAGS_BASE,               1, FLAGS_SPRITE_COUNT,                          "Flag graphics"         },
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  3895
		/* 0x15 */ { A5BLOCK_ALLOW_OFFSET, SPR_OPENTTD_BASE,             1, OPENTTD_SPRITE_COUNT,                        "OpenTTD GUI graphics"  },
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3896
	};
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3897
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  3898
	if (!check_length(len, 2, "GraphicsNew")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3899
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3900
	uint8 type = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3901
	uint16 num = grf_load_extended(&buf);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3902
	uint16 offset = HasBit(type, 7) ? grf_load_extended(&buf) : 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3903
	ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3904
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3905
	if ((type == 0x0D) && (num == 10) && _cur_grffile->is_ottdfile) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3906
		/* Special not-TTDP-compatible case used in openttd(d/w).grf
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3907
		 * Missing shore sprites and initialisation of SPR_SHORE_BASE */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3908
		grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from openttd(d/w).grf.");
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3909
		LoadNextSprite(SPR_SHORE_BASE +  0, _file_index, _nfo_line++); // SLOPE_STEEP_S
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3910
		LoadNextSprite(SPR_SHORE_BASE +  5, _file_index, _nfo_line++); // SLOPE_STEEP_W
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3911
		LoadNextSprite(SPR_SHORE_BASE +  7, _file_index, _nfo_line++); // SLOPE_WSE
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3912
		LoadNextSprite(SPR_SHORE_BASE + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3913
		LoadNextSprite(SPR_SHORE_BASE + 11, _file_index, _nfo_line++); // SLOPE_NWS
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3914
		LoadNextSprite(SPR_SHORE_BASE + 13, _file_index, _nfo_line++); // SLOPE_ENW
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3915
		LoadNextSprite(SPR_SHORE_BASE + 14, _file_index, _nfo_line++); // SLOPE_SEN
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3916
		LoadNextSprite(SPR_SHORE_BASE + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3917
		LoadNextSprite(SPR_SHORE_BASE + 16, _file_index, _nfo_line++); // SLOPE_EW
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3918
		LoadNextSprite(SPR_SHORE_BASE + 17, _file_index, _nfo_line++); // SLOPE_NS
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  3919
		if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ONLY_NEW;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3920
		return;
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
  3921
	}
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
  3922
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3923
	/* Supported type? */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3924
	if ((type >= lengthof(action5_types)) || (action5_types[type].block_type == A5BLOCK_INVALID)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3925
		grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3926
		_skip_sprites = num;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3927
		return;
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
  3928
	}
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
  3929
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3930
	const Action5Type *action5_type = &action5_types[type];
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3931
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3932
	/* Ignore offset if not allowed */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3933
	if ((action5_type->block_type != A5BLOCK_ALLOW_OFFSET) && (offset != 0)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3934
		grfmsg(1, "GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->name, type);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3935
		offset = 0;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3936
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3937
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3938
	/* Ignore action5 if too few sprites are specified. (for TTDP compatibility)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3939
	 * This does not make sense, if <offset> is allowed */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3940
	if ((action5_type->block_type == A5BLOCK_FIXED) && (num < action5_type->min_sprites)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3941
		grfmsg(1, "GraphicsNew: %s (type 0x%02X) count must be at least %d. Only %d were specified. Skipping.", action5_type->name, type, action5_type->min_sprites, num);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3942
		_skip_sprites = num;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3943
		return;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3944
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3945
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3946
	/* Load at most max_sprites sprites. Skip remaining sprites. (for compatibility with TTDP and future extentions) */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3947
	uint16 skip_num = SanitizeSpriteOffset(num, offset, action5_type->max_sprites, action5_type->name);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3948
	SpriteID replace = action5_type->sprite_base + offset;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3949
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3950
	/* Load <num> sprites starting from <replace>, then skip <skip_num> sprites. */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3951
	grfmsg(2, "GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X", offset, offset + num - 1, action5_type->name, type, replace);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3952
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
  3953
	for (; num > 0; num--) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3954
		_nfo_line++;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3955
		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index, _nfo_line);
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
  3956
	}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3957
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  3958
	if (type == 0x0D) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_5;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  3959
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3960
	_skip_sprites = skip_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3961
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3962
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3963
/* Action 0x05 (SKIP) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  3964
static void SkipAct5(byte *buf, size_t len)
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3965
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3966
	if (!check_length(len, 2, "SkipAct5")) return;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3967
	buf++;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3968
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3969
	/* Ignore type byte */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3970
	grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3971
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3972
	/* Skip the sprites of this action */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3973
	_skip_sprites = grf_load_extended(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3974
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3975
	grfmsg(3, "SkipAct5: Skipping %d sprites", _skip_sprites);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3976
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  3977
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3978
/**
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3979
 * Reads a variable common to VarAction2 and Action7/9/D.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3980
 *
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3981
 * Returns VarAction2 variable 'param' resp. Action7/9/D variable '0x80 + param'.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3982
 * If a variable is not accessible from all four actions, it is handled in the action specific functions.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3983
 *
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3984
 * @param param variable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first).
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3985
 * @param value returns the value of the variable.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3986
 * @return true iff the variable is known and the value is returned in 'value'.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3987
 */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3988
bool GetGlobalVariable(byte param, uint32 *value)
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3989
{
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3990
	switch (param) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3991
		case 0x00: // current date
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3992
			*value = max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3993
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3994
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3995
		case 0x01: // current year
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3996
			*value = Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3997
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3998
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3999
		case 0x02: // current month
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4000
			*value = _cur_month;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4001
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4002
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4003
		case 0x03: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4004
			*value = _settings_game.game_creation.landscape;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4005
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4006
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4007
		case 0x06: // road traffic side, bit 4 clear=left, set=right
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4008
			*value = _settings_game.vehicle.road_side << 4;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4009
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4010
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4011
		case 0x09: // date fraction
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4012
			*value = _date_fract;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4013
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4014
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4015
		case 0x0A: // animation counter
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4016
			*value = _tick_counter;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4017
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4018
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4019
		case 0x0B: { // TTDPatch version
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4020
			uint major    = 2;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4021
			uint minor    = 6;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4022
			uint revision = 1; // special case: 2.0.1 is 2.0.10
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4023
			uint build    = 1382;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4024
			*value = (major << 24) | (minor << 20) | (revision << 16) | build;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4025
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4026
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4027
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4028
		case 0x0D: // TTD Version, 00=DOS, 01=Windows
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4029
			*value = !_use_dos_palette;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4030
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4031
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4032
		case 0x0E: // Y-offset for train sprites
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4033
			*value = _traininfo_vehicle_pitch;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4034
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4035
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4036
		case 0x0F: // Rail track type cost factors
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4037
			*value = 0;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4038
			SB(*value, 0, 8, _railtype_cost_multiplier[0]); // normal rail
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4039
			if (_settings_game.vehicle.disable_elrails) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4040
				/* skip elrail multiplier - disabled */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4041
				SB(*value, 8, 8, _railtype_cost_multiplier[2]); // monorail
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4042
			} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4043
				SB(*value, 8, 8, _railtype_cost_multiplier[1]); // electified railway
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4044
				/* Skip monorail multiplier - no space in result */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4045
			}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4046
			SB(*value, 16, 8, _railtype_cost_multiplier[3]); // maglev
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4047
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4048
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4049
		case 0x11: // current rail tool type
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4050
			*value = 0;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4051
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4052
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4053
		case 0x12: // Game mode
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4054
			*value = _game_mode;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4055
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4056
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4057
		/* case 0x13: // Tile refresh offset to left    not implemented */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4058
		/* case 0x14: // Tile refresh offset to right   not implemented */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4059
		/* case 0x15: // Tile refresh offset upwards    not implemented */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4060
		/* case 0x16: // Tile refresh offset downwards  not implemented */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4061
		/* case 0x17: // temperate snow line            not implemented */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4062
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4063
		case 0x1A: // Always -1
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4064
			*value = UINT_MAX;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4065
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4066
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4067
		case 0x1B: // Display options
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4068
			*value = GB(_display_opt, 0, 6);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4069
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4070
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4071
		case 0x1D: // TTD Platform, 00=TTDPatch, 01=OpenTTD
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4072
			*value = 1;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4073
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4074
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4075
		case 0x1E: // Miscellaneous GRF features
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4076
			*value = _misc_grf_features;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4077
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4078
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4079
		/* case 0x1F: // locale dependent settings not implemented */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4080
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4081
		case 0x20: // snow line height
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4082
			*value = _settings_game.game_creation.landscape == LT_ARCTIC ? GetSnowLine() : 0xFF;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4083
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4084
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4085
		case 0x21: // OpenTTD version
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4086
			*value = _openttd_newgrf_version;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4087
			return true;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4088
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  4089
		case 0x22: // difficulty level
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4090
			*value = _settings_game.difficulty.diff_level;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4091
			return true;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4092
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4093
		case 0x23: // long format date
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4094
			*value = _date;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4095
			return true;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4096
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4097
		case 0x24: // long format year
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4098
			*value = _cur_year;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  4099
			return true;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  4100
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4101
		default: return false;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4102
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4103
}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4104
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4105
static uint32 GetParamVal(byte param, uint32 *cond_val)
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4106
{
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4107
	/* First handle variable common with VarAction2 */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4108
	uint32 value;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4109
	if (GetGlobalVariable(param - 0x80, &value)) return value;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4110
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4111
	/* Non-common variable */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4112
	switch (param) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4113
		case 0x84: { // GRF loading stage
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4114
			uint32 res = 0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4115
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4116
			if (_cur_stage > GLS_INIT) SetBit(res, 0);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4117
			if (_cur_stage == GLS_RESERVE) SetBit(res, 8);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4118
			if (_cur_stage == GLS_ACTIVATION) SetBit(res, 9);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4119
			return res;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4120
		}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4121
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4122
		case 0x85: // TTDPatch flags, only for bit tests
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4123
			if (cond_val == NULL) {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4124
				/* Supported in Action 0x07 and 0x09, not 0x0D */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4125
				return 0;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4126
			} else {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4127
				uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4128
				*cond_val %= 0x20;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4129
				return param_val;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4130
			}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4131
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4132
		case 0x88: // GRF ID check
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4133
			return 0;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4134
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4135
		/* case 0x99: Global ID offest not implemented */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4136
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4137
		default:
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4138
			/* GRF Parameter */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4139
			if (param < 0x80) return _cur_grffile->param[param];
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4140
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4141
			/* In-game variable. */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4142
			grfmsg(1, "Unsupported in-game variable 0x%02X", param);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  4143
			return UINT_MAX;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4144
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4145
}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4146
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4147
/* Action 0x06 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4148
static void CfgApply(byte *buf, size_t len)
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4149
{
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4150
	/* <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
  4151
	 *
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4152
	 * 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
  4153
	 *                 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
  4154
	 * 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
  4155
	 *                 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
  4156
	 *                 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
  4157
	 *                 were specified.
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4158
	 * 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
  4159
	 *                 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
  4160
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4161
	/* Preload the next sprite */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4162
	size_t pos = FioGetPos();
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4163
	uint16 num = FioReadWord();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4164
	uint8 type = FioReadByte();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4165
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4166
	/* 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
  4167
	if (type == 0xFF) {
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  4168
		_preload_sprite = MallocT<byte>(num);
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4169
		FioReadBlock(_preload_sprite, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4170
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4171
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4172
	/* 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
  4173
	FioSeekTo(pos, SEEK_SET);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4174
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4175
	if (type != 0xFF) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4176
		grfmsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)");
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4177
		return;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4178
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4179
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4180
	/* 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
  4181
	buf++;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4182
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4183
	for (;;) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4184
		uint i;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4185
		uint param_num;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4186
		uint param_size;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4187
		uint offset;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4188
		bool add_value;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4189
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4190
		/* 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
  4191
		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
  4192
		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
  4193
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4194
		/* 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
  4195
		 * 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
  4196
		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
  4197
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4198
		/* 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
  4199
		 * instead of replacing it. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4200
		add_value  = HasBit(param_size, 7);
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4201
		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
  4202
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4203
		/* 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
  4204
		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
  4205
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4206
		/* 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
  4207
		 * 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
  4208
		if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur_grffile->param_end) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4209
			grfmsg(2, "CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4));
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4210
			break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4211
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4212
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4213
		grfmsg(8, "CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset);
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4214
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4215
		bool carry = false;
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4216
		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
  4217
			uint32 value = GetParamVal(param_num + i / 4, NULL);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4218
			/* Reset carry flag for each iteration of the variable (only really
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4219
			 * matters if param_size is greater than 4) */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4220
			if (i == 0) carry = false;
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4221
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4222
			if (add_value) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4223
				uint new_value = _preload_sprite[offset + i] + GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4224
				_preload_sprite[offset + i] = GB(new_value, 0, 8);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4225
				/* Check if the addition overflowed */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4226
				carry = new_value >= 256;
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4227
			} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4228
				_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
  4229
			}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4230
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4231
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4232
}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  4233
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  4234
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  4235
/* Action 0x09 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4236
static void SkipIf(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4237
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4238
	/* <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
  4239
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4240
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4241
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4242
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4243
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4244
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4245
	/* TODO: More params. More condition types. */
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
  4246
	uint32 cond_val = 0;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4247
	uint32 mask = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  4248
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4249
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  4250
	if (!check_length(len, 6, "SkipIf")) return;
3714
402f02b01241 (svn r4657) - NewGRF: use grf_load_byte() in favour of array accesses
peter1138
parents: 3712
diff changeset
  4251
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4252
	uint8 param     = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4253
	uint8 paramsize = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4254
	uint8 condtype  = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4255
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
  4256
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  4257
		/* 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
  4258
		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
  4259
	}
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
  4260
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  4261
	switch (paramsize) {
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4262
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4263
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4264
		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
  4265
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  4266
	}
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
  4267
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4268
	if (param < 0x80 && _cur_grffile->param_end <= param) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4269
		grfmsg(7, "SkipIf: Param %d undefined, skipping test", param);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4270
		return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4271
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4272
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4273
	uint32 param_val = GetParamVal(param, &cond_val);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  4274
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4275
	grfmsg(7, "SkipIf: Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4276
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4277
	/*
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4278
	 * Parameter (variable in specs) 0x88 can only have GRF ID checking
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4279
	 * conditions, except conditions 0x0B and 0x0C (cargo availability)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4280
	 * as those ignore the parameter. So, when the condition type is
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4281
	 * either of those, the specific variable 0x88 code is skipped, so
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4282
	 * the "general" code for the cargo availability conditions kicks in.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4283
	 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4284
	if (param == 0x88 && condtype != 0x0B && condtype != 0x0C) {
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4285
		/* GRF ID checks */
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4286
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4287
		const GRFConfig *c = GetGRFConfig(cond_val);
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4288
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4289
		if (condtype != 10 && c == NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4290
			grfmsg(7, "SkipIf: GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val));
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4291
			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
  4292
		}
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
  4293
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4294
		switch (condtype) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4295
			/* Tests 0x06 to 0x0A are only for param 0x88, GRFID checks */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4296
			case 0x06: // Is GRFID active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4297
				result = c->status == GCS_ACTIVATED;
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4298
				break;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4299
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4300
			case 0x07: // Is GRFID non-active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4301
				result = c->status != GCS_ACTIVATED;
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4302
				break;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4303
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4304
			case 0x08: // GRFID is not but will be active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4305
				result = c->status == GCS_INITIALISED;
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4306
				break;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4307
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4308
			case 0x09: // GRFID is or will be active?
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4309
				result = c->status == GCS_ACTIVATED || c->status == GCS_INITIALISED;
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4310
				break;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4311
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4312
			case 0x0A: // GRFID is not nor will be active
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4313
				/* This is the only condtype that doesn't get ignored if the GRFID is not found */
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4314
				result = c == NULL || c->flags == GCS_DISABLED || c->status == GCS_NOT_FOUND;
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4315
				break;
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4316
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4317
			default: grfmsg(1, "SkipIf: Unsupported GRF condition type %02X. 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
  4318
		}
5703
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4319
	} else {
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4320
		/* Parameter or variable tests */
3f848403a814 (svn r7711) -Fix (r7354): NewGRF Action 7, GRF check condition 10 didn't ignore unknown GRF IDs. Also separate GRF ID conditions
peter1138
parents: 5681
diff changeset
  4321
		switch (condtype) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4322
			case 0x00: result = !!(param_val & (1 << cond_val));
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4323
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4324
			case 0x01: result = !(param_val & (1 << cond_val));
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4325
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4326
			case 0x02: result = (param_val & mask) == cond_val;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4327
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4328
			case 0x03: result = (param_val & mask) != cond_val;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4329
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4330
			case 0x04: result = (param_val & mask) < cond_val;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4331
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4332
			case 0x05: result = (param_val & mask) > cond_val;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4333
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4334
			case 0x0B: result = GetCargoIDByLabel(BSWAP32(cond_val)) == CT_INVALID;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4335
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4336
			case 0x0C: result = GetCargoIDByLabel(BSWAP32(cond_val)) != CT_INVALID;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4337
				break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4338
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4339
			default: grfmsg(1, "SkipIf: Unsupported condition type %02X. 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
  4340
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4341
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4342
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  4343
	if (!result) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4344
		grfmsg(2, "SkipIf: Not skipping sprites, test was false");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4345
		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
  4346
	}
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
  4347
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4348
	uint8 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
  4349
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
  4350
	/* 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
  4351
	 * 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
  4352
	 * 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
  4353
	 * label in the file is used. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4354
	GRFLabel *choice = NULL;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4355
	for (GRFLabel *label = _cur_grffile->label; label != NULL; label = label->next) {
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
  4356
		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
  4357
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
  4358
		/* 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
  4359
		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
  4360
		/* 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
  4361
		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
  4362
			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
  4363
			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
  4364
		}
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
  4365
	}
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
  4366
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
  4367
	if (choice != NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4368
		grfmsg(2, "SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line);
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  4369
		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
  4370
		_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
  4371
		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
  4372
	}
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
  4373
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4374
	grfmsg(2, "SkipIf: Skipping %d sprites, test was true", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4375
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4376
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4377
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4378
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4379
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4380
		_skip_sprites = -1;
6422
14794ebde68e (svn r8831) -Feature: If an action 7/9 leads to skipping the rest of the file, disable the
maedhros
parents: 6421
diff changeset
  4381
14794ebde68e (svn r8831) -Feature: If an action 7/9 leads to skipping the rest of the file, disable the
maedhros
parents: 6421
diff changeset
  4382
		/* If an action 8 hasn't been encountered yet, disable the grf. */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  4383
		if (_cur_grfconfig->status != GCS_ACTIVATED) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4384
			_cur_grfconfig->status = GCS_DISABLED;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4385
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4386
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4387
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4388
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4389
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  4390
/* Action 0x08 (GLS_FILESCAN) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4391
static void ScanInfo(byte *buf, size_t len)
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4392
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4393
	if (!check_length(len, 8, "Info")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4394
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4395
	grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4396
	uint32 grfid  = grf_load_dword(&buf);
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4397
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4398
	_cur_grfconfig->grfid = grfid;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4399
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
  4400
	/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4401
	if (GB(grfid, 24, 8) == 0xFF) SetBit(_cur_grfconfig->flags, GCF_SYSTEM);
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
  4402
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4403
	len -= 6;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4404
	const char *name = grf_load_string(&buf, len);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4405
	_cur_grfconfig->name = TranslateTTDPatchCodes(grfid, name);
6512
8625c30bd63d (svn r8964) -Codechange: use grf_load_string to read action 8 strings instead of trying to do the same manually.
rubidium
parents: 6474
diff changeset
  4406
8625c30bd63d (svn r8964) -Codechange: use grf_load_string to read action 8 strings instead of trying to do the same manually.
rubidium
parents: 6474
diff changeset
  4407
	len -= strlen(name) + 1;
8625c30bd63d (svn r8964) -Codechange: use grf_load_string to read action 8 strings instead of trying to do the same manually.
rubidium
parents: 6474
diff changeset
  4408
	if (len > 0) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4409
		const char *info = grf_load_string(&buf, len);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4410
		_cur_grfconfig->info = TranslateTTDPatchCodes(grfid, info);
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4411
	}
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
  4412
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
  4413
	/* 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
  4414
	_skip_sprites = -1;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4415
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4416
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  4417
/* Action 0x08 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4418
static void GRFInfo(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4419
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4420
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4421
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4422
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4423
	 * 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
  4424
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4425
	 * S info          string describing the set, and e.g. author and copyright */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4426
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4427
	if (!check_length(len, 8, "GRFInfo")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4428
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4429
	uint8 version    = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4430
	uint32 grfid     = grf_load_dword(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4431
	const char *name = grf_load_string(&buf, len - 6);
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
  4432
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
  4433
	_cur_grffile->grfid = grfid;
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  4434
	_cur_grffile->grf_version = version;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4435
	_cur_grfconfig->status = _cur_stage < GLS_RESERVE ? GCS_INITIALISED : GCS_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
  4436
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
  4437
	/* Do swap the GRFID for displaying purposes since people expect that */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4438
	DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4439
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4440
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  4441
/* Action 0x0A */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4442
static void SpriteReplace(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4443
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4444
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4445
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4446
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4447
	 * 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
  4448
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4449
	 * 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
  4450
	 * 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
  4451
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4452
	buf++; // skip action byte
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4453
	uint8 num_sets = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4454
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4455
	for (uint i = 0; i < num_sets; i++) {
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
  4456
		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
  4457
		uint16 first_sprite = grf_load_word(&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
  4458
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4459
		grfmsg(2, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d",
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  4460
			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
  4461
		);
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
  4462
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4463
		for (uint j = 0; j < num_sprites; j++) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  4464
			int load_index = first_sprite + j;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4465
			_nfo_line++;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  4466
			LoadNextSprite(load_index, _file_index, _nfo_line); // XXX
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  4467
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4468
			/* Shore sprites now located at different addresses.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4469
			 * So detect when the old ones get replaced. */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4470
			if (IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4471
				if (_loaded_newgrf_features.shore != SHORE_REPLACE_ACTION_5) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_A;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4472
			}
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
  4473
		}
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
  4474
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4475
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4476
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4477
/* Action 0x0A (SKIP) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4478
static void SkipActA(byte *buf, size_t len)
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4479
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4480
	buf++;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4481
	uint8 num_sets = grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4482
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4483
	for (uint i = 0; i < num_sets; i++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4484
		/* Skip the sprites this replaces */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4485
		_skip_sprites += grf_load_byte(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4486
		/* But ignore where they go */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4487
		grf_load_word(&buf);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4488
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4489
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4490
	grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4491
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4492
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4493
/* Action 0x0B */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4494
static void GRFLoadError(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4495
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4496
	/* <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
  4497
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4498
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4499
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4500
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4501
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4502
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4503
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4504
	 * 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
  4505
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4506
	 * 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
  4507
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4508
	 * V data          additional data for built-in (or custom) messages
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4509
	 * B parnum        parameter numbers to be shown in the message (maximum of 2) */
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4510
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4511
	static const StringID msgstr[] = {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4512
		STR_NEWGRF_ERROR_VERSION_NUMBER,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4513
		STR_NEWGRF_ERROR_DOS_OR_WINDOWS,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4514
		STR_NEWGRF_ERROR_UNSET_SWITCH,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4515
		STR_NEWGRF_ERROR_INVALID_PARAMETER,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4516
		STR_NEWGRF_ERROR_LOAD_BEFORE,
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4517
		STR_NEWGRF_ERROR_LOAD_AFTER,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4518
		STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4519
	};
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4520
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4521
	static const StringID sevstr[] = {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4522
		STR_NEWGRF_ERROR_MSG_INFO,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4523
		STR_NEWGRF_ERROR_MSG_WARNING,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4524
		STR_NEWGRF_ERROR_MSG_ERROR,
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4525
		STR_NEWGRF_ERROR_MSG_FATAL
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4526
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4527
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4528
	if (!check_length(len, 6, "GRFLoadError")) return;
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4529
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4530
	/* For now we can only show one message per newgrf file. */
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4531
	if (_cur_grfconfig->error != NULL) return;
6416
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  4532
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4533
	buf++; // Skip the action byte.
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4534
	byte severity   = grf_load_byte(&buf);
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4535
	byte lang       = grf_load_byte(&buf);
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4536
	byte message_id = grf_load_byte(&buf);
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4537
	len -= 4;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4538
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4539
	/* Skip the error if it isn't valid for the current language. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4540
	if (!CheckGrfLangID(lang, _cur_grffile->grf_version)) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4541
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4542
	/* Skip the error until the activation stage unless bit 7 of the severity
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4543
	 * is set. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4544
	if (!HasBit(severity, 7) && _cur_stage == GLS_INIT) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  4545
		grfmsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur_stage);
441
892cb9999501 (svn r650) Pasky fix #4. (Misc fixes to get USSet going)
miham
parents: 440
diff changeset
  4546
		return;
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  4547
	}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4548
	ClrBit(severity, 7);
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4549
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4550
	if (severity >= lengthof(sevstr)) {
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4551
		grfmsg(7, "GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity);
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4552
		severity = 2;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4553
	} else if (severity == 3) {
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4554
		/* This is a fatal error, so make sure the GRF is deactivated and no
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4555
		 * more of it gets loaded. */
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  4556
		_cur_grfconfig->status = GCS_DISABLED;
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4557
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4558
		_skip_sprites = -1;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4559
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4560
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4561
	if (message_id >= lengthof(msgstr) && message_id != 0xFF) {
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4562
		grfmsg(7, "GRFLoadError: Invalid message id.");
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4563
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4564
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4565
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4566
	if (len <= 1) {
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4567
		grfmsg(7, "GRFLoadError: No message data supplied.");
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4568
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4569
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4570
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4571
	GRFError *error = CallocT<GRFError>(1);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4572
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4573
	error->severity = sevstr[severity];
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4574
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4575
	if (message_id == 0xFF) {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4576
		/* This is a custom error message. */
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4577
		const char *message = grf_load_string(&buf, len);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4578
		len -= (strlen(message) + 1);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4579
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4580
		error->custom_message = TranslateTTDPatchCodes(_cur_grffile->grfid, message);
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4581
	} else {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4582
		error->message = msgstr[message_id];
6429
02c062eb2c74 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 6422
diff changeset
  4583
	}
02c062eb2c74 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 6422
diff changeset
  4584
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4585
	if (len > 0) {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4586
		const char *data = grf_load_string(&buf, len);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4587
		len -= (strlen(data) + 1);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4588
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4589
		error->data = TranslateTTDPatchCodes(_cur_grffile->grfid, data);
6465
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4590
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4591
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4592
	/* Only two parameter numbers can be used in the string. */
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4593
	uint i = 0;
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4594
	for (; i < 2 && len > 0; i++) {
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4595
		error->param_number[i] = grf_load_byte(&buf);
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4596
		len--;
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4597
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4598
	error->num_params = i;
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4599
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4600
	_cur_grfconfig->error = error;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4601
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4602
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4603
/* Action 0x0C */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4604
static void GRFComment(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4605
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4606
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4607
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4608
	 * 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
  4609
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
  4610
	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
  4611
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4612
	size_t text_len = len - 1;
6433
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4613
	const char *text = (const char*)(buf + 1);
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4614
	grfmsg(2, "GRFComment: %.*s", text_len, text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4615
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4616
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4617
/* Action 0x0D (GLS_SAFETYSCAN) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4618
static void SafeParamSet(byte *buf, size_t len)
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4619
{
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  4620
	if (!check_length(len, 5, "SafeParamSet")) return;
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4621
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4622
	uint8 target = grf_load_byte(&buf);
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4623
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4624
	/* Only writing GRF parameters is considered safe */
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4625
	if (target < 0x80) return;
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4626
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4627
	/* GRM could be unsafe, but as here it can only happen after other GRFs
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4628
	 * are loaded, it should be okay. If the GRF tried to use the slots it
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4629
	 * reserved, it would be marked unsafe anyway. GRM for (e.g. bridge)
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4630
	 * sprites  is considered safe. */
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4631
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4632
	SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5776
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4633
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4634
	/* Skip remainder of GRF */
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4635
	_skip_sprites = -1;
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4636
}
d80e79a2e71b (svn r7831) -Codechange: [NewGRF] Do not mark as unsafe those NewGRFs that set their own parameters (via action D) and/or change only bridge sprite table layouts (action 0, property D).
peter1138
parents: 5753
diff changeset
  4637
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4638
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4639
static uint32 GetPatchVariable(uint8 param)
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4640
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4641
	switch (param) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4642
		/* start year - 1920 */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4643
		case 0x0B: return max(_settings_game.game_creation.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4644
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4645
		/* freight trains weight factor */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4646
		case 0x0E: return _settings_game.vehicle.freight_trains;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4647
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4648
		/* empty wagon speed increase */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4649
		case 0x0F: return 0;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4650
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4651
		/* plane speed factor; our patch option is reversed from TTDPatch's,
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4652
		 * the following is good for 1x, 2x and 4x (most common?) and...
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4653
		 * well not really for 3x. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4654
		case 0x10:
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4655
			switch (_settings_game.vehicle.plane_speed) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4656
				default:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4657
				case 4: return 1;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4658
				case 3: return 2;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4659
				case 2: return 2;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4660
				case 1: return 4;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4661
			}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  4662
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4663
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4664
		/* 2CC colormap base sprite */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4665
		case 0x11: return SPR_2CCMAP_BASE;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4666
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4667
		/* map size: format = -MABXYSS
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4668
		 * M  : the type of map
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4669
		 *       bit 0 : set   : squared map. Bit 1 is now not relevant
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4670
		 *               clear : rectangle map. Bit 1 will indicate the bigger edge of the map
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4671
		 *       bit 1 : set   : Y is the bigger edge. Bit 0 is clear
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4672
		 *               clear : X is the bigger edge.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4673
		 * A  : minimum edge(log2) of the map
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4674
		 * B  : maximum edge(log2) of the map
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4675
		 * XY : edges(log2) of each side of the map.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4676
		 * SS : combination of both X and Y, thus giving the size(log2) of the map
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4677
		 */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4678
		case 0x13: {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4679
			byte map_bits = 0;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4680
			byte log_X = MapLogX() - 6; // substraction is required to make the minimal size (64) zero based
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4681
			byte log_Y = MapLogY() - 6;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4682
			byte max_edge = max(log_X, log_Y);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4683
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4684
			if (log_X == log_Y) { // we have a squared map, since both edges are identical
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4685
				SetBit(map_bits ,0);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4686
			} else {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4687
				if (max_edge == log_Y) SetBit(map_bits, 1); // edge Y been the biggest, mark it
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4688
			}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4689
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4690
			return (map_bits << 24) | (min(log_X, log_Y) << 20) | (max_edge << 16) |
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4691
				(log_X << 12) | (log_Y << 8) | (log_X + log_Y);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4692
		}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  4693
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4694
		default:
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4695
			grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4696
			return 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4697
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4698
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4699
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4700
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4701
static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, const char *type)
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4702
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4703
	uint start = 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4704
	uint size  = 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4705
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4706
	if (op == 6) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4707
		/* Return GRFID of set that reserved ID */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4708
		return grm[_cur_grffile->param[target]];
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4709
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4710
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4711
	/* With an operation of 2 or 3, we want to reserve a specific block of IDs */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4712
	if (op == 2 || op == 3) start = _cur_grffile->param[target];
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4713
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4714
	for (uint i = start; i < num_ids; i++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4715
		if (grm[i] == 0) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4716
			size++;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4717
		} else {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4718
			if (op == 2 || op == 3) break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4719
			start = i + 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4720
			size = 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4721
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4722
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4723
		if (size == count) break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4724
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4725
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4726
	if (size == count) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4727
		/* Got the slot... */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4728
		if (op == 0 || op == 3) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4729
			grfmsg(2, "ParamSet: GRM: Reserving %d %s at %d", count, type, start);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4730
			for (uint i = 0; i < count; i++) grm[start + i] = _cur_grffile->grfid;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4731
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4732
		return start;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4733
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4734
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4735
	/* Unable to allocate */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4736
	if (op != 4 && op != 5) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4737
		/* Deactivate GRF */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4738
		grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4739
		_cur_grfconfig->status = GCS_DISABLED;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4740
		_skip_sprites = -1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4741
		return UINT_MAX;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4742
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4743
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4744
	grfmsg(1, "ParamSet: GRM: Unable to allocate %d %s", count, type);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4745
	return UINT_MAX;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4746
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4747
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4748
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  4749
/* Action 0x0D */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4750
static void ParamSet(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4751
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4752
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4753
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4754
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4755
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4756
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4757
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4758
	 * 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
  4759
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4760
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4761
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4762
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4763
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4764
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4765
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4766
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4767
	 * 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
  4768
	 *         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
  4769
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4770
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4771
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4772
	 */
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
  4773
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  4774
	if (!check_length(len, 5, "ParamSet")) return;
418
67457dd7e5bc (svn r615) Fix the same bug in ParamSet action loading, pointer out by Bjarni too. (pasky)
bjarni
parents: 416
diff changeset
  4775
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4776
	uint8 target = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4777
	uint8 oper   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4778
	uint32 src1  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4779
	uint32 src2  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4780
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4781
	uint32 data = 0;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4782
	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
  4783
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
  4784
	/* 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
  4785
	 * 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
  4786
	 * 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
  4787
	 * - 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
  4788
	 * - 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
  4789
	 *   an earlier action D */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4790
	if (HasBit(oper, 7)) {
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4791
		if (target < 0x80 && target < _cur_grffile->param_end) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4792
			grfmsg(7, "ParamSet: 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
  4793
			return;
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4794
		}
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4795
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4796
		oper = GB(oper, 0, 7);
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
  4797
	}
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
  4798
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
  4799
	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
  4800
		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
  4801
			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
  4802
				/* Patch variables */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4803
				src1 = GetPatchVariable(src1);
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
  4804
			} 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
  4805
				/* GRF Resource Management */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4806
				uint8  op      = src1;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4807
				uint8  feature = GB(data, 8, 8);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4808
				uint16 count   = GB(data, 16, 16);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4809
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4810
				if (_cur_stage == GLS_RESERVE) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4811
					if (feature == 0x08) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4812
						/* General sprites */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4813
						if (op == 0) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4814
							/* Check if the allocated sprites will fit below the original sprite limit */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4815
							if (_cur_spriteid + count >= 16384) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4816
								grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4817
								_cur_grfconfig->status = GCS_DISABLED;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4818
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4819
								_skip_sprites = -1;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4820
								return;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4821
							}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4822
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4823
							/* Reserve space at the current sprite ID */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4824
							grfmsg(4, "ParamSet: GRM: Allocated %d sprites at %d", count, _cur_spriteid);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4825
							_grm_sprites[GRFLocation(_cur_grffile->grfid, _nfo_line)] = _cur_spriteid;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4826
							_cur_spriteid += count;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4827
						}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4828
					}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4829
					/* Ignore GRM result during reservation */
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4830
					src1 = 0;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4831
				} else if (_cur_stage == GLS_ACTIVATION) {
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4832
					switch (feature) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4833
						case 0x00: // Trains
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4834
						case 0x01: // Road Vehicles
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4835
						case 0x02: // Ships
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4836
						case 0x03: // Aircraft
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4837
							if (!_settings_game.vehicle.dynamic_engines) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4838
								src1 = PerformGRM(&_grm_engines[_engine_offsets[feature]], _engine_counts[feature], count, op, target, "vehicles");
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4839
								if (_skip_sprites == -1) return;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4840
							} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4841
								// GRM does not apply for dynamic engine allocation.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4842
								switch (op) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4843
									case 2:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4844
									case 3:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4845
										src1 = _cur_grffile->param[target];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4846
										break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4847
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4848
									default:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4849
										src1 = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4850
										break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4851
								}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4852
							}
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4853
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4854
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4855
						case 0x08: // General sprites
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4856
							switch (op) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4857
								case 0:
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4858
									/* Return space reserved during reservation stage */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4859
									src1 = _grm_sprites[GRFLocation(_cur_grffile->grfid, _nfo_line)];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4860
									grfmsg(4, "ParamSet: GRM: Using pre-allocated sprites at %d", src1);
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4861
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4862
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4863
								case 1:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4864
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4865
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4866
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4867
								default:
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4868
									grfmsg(1, "ParamSet: GRM: Unsupported operation %d for general sprites", op);
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4869
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4870
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4871
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4872
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4873
						case 0x0B: // Cargo
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4874
							/* There are two ranges: one for cargo IDs and one for cargo bitmasks */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4875
							src1 = PerformGRM(_grm_cargos, NUM_CARGO * 2, count, op, target, "cargos");
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4876
							if (_skip_sprites == -1) return;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4877
							break;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4878
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  4879
						default: grfmsg(1, "ParamSet: GRM: Unsupported feature 0x%X", feature); return;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4880
					}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4881
				} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4882
					/* Ignore GRM during initialization */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  4883
					src1 = 0;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4884
				}
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
  4885
			}
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
  4886
		} 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
  4887
			/* 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
  4888
			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
  4889
			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
  4890
				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
  4891
			} 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
  4892
				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
  4893
			}
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
  4894
		}
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
  4895
	} 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
  4896
		/* 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
  4897
		 * 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
  4898
		 * 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
  4899
		 * 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
  4900
		 * of 0 is used instead.  */
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4901
		src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4902
		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
  4903
	}
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
  4904
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
  4905
	/* 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
  4906
	 * 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
  4907
	 * 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
  4908
	 * 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
  4909
	 * 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
  4910
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4911
	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
  4912
	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
  4913
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4914
			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
  4915
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4916
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4917
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4918
			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
  4919
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4920
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4921
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4922
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4923
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4924
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
  4925
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4926
			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
  4927
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4928
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
  4929
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4930
			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
  4931
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4932
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
  4933
		case 0x05:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4934
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4935
				res = src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4936
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4937
				res = src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4938
			}
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
  4939
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4940
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
  4941
		case 0x06:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4942
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4943
				res = (int32)src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4944
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4945
				res = (int32)src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4946
			}
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
  4947
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4948
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4949
		case 0x07: // Bitwise AND
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4950
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4951
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4952
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4953
		case 0x08: // Bitwise OR
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4954
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4955
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4956
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4957
		case 0x09: // Unsigned division
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4958
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4959
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4960
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4961
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4962
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4963
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4964
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4965
		case 0x0A: // Signed divison
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4966
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4967
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4968
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4969
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4970
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4971
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4972
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4973
		case 0x0B: // Unsigned modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4974
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4975
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4976
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4977
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4978
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4979
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4980
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4981
		case 0x0C: // Signed modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4982
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4983
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4984
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4985
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4986
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4987
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4988
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4989
		default: grfmsg(0, "ParamSet: Unknown operation %d, skipping", oper); return;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4990
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4991
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4992
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4993
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4994
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4995
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4996
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4997
		case 0x8F: // Rail track type cost factors
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  4998
			_railtype_cost_multiplier[0] = GB(res, 0, 8);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  4999
			if (_settings_game.vehicle.disable_elrails) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5000
				_railtype_cost_multiplier[1] = GB(res, 0, 8);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5001
				_railtype_cost_multiplier[2] = GB(res, 8, 8);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5002
			} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5003
				_railtype_cost_multiplier[1] = GB(res, 8, 8);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5004
				_railtype_cost_multiplier[2] = GB(res, 16, 8);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5005
			}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5006
			_railtype_cost_multiplier[3] = GB(res, 16, 8);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5007
			break;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5008
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5009
		/* @todo implement */
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5010
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5011
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5012
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5013
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5014
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5015
		case 0x99: // Global ID offset
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5016
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5017
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5018
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5019
		case 0x9E: // Miscellaneous GRF features
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  5020
			_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
  5021
			/* Set train list engine width */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5022
			_traininfo_vehicle_width = HasGrfMiscBit(GMB_TRAIN_WIDTH_32_PIXELS) ? 32 : 29;
3814
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  5023
			break;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  5024
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5025
		case 0x9F: // locale-dependent settings
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5026
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5027
			break;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5028
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5029
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5030
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5031
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5032
				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
  5033
			} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5034
				grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5035
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  5036
			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
  5037
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5038
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5039
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5040
/* Action 0x0E (GLS_SAFETYSCAN) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5041
static void SafeGRFInhibit(byte *buf, size_t len)
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5042
{
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5043
	/* <0E> <num> <grfids...>
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5044
	 *
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5045
	 * B num           Number of GRFIDs that follow
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5046
	 * D grfids        GRFIDs of the files to deactivate */
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5047
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5048
	if (!check_length(len, 2, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5049
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5050
	uint8 num = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5051
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5052
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5053
	for (uint i = 0; i < num; i++) {
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5054
		uint32 grfid = grf_load_dword(&buf);
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5055
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5056
		/* GRF is unsafe it if tries to deactivate other GRFs */
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5057
		if (grfid != _cur_grfconfig->grfid) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5058
			SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5059
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5060
			/* Skip remainder of GRF */
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5061
			_skip_sprites = -1;
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5062
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5063
			return;
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5064
		}
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5065
	}
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5066
}
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5067
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  5068
/* Action 0x0E */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5069
static void GRFInhibit(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5070
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5071
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5072
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5073
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5074
	 * 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
  5075
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5076
	if (!check_length(len, 2, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5077
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5078
	uint8 num = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5079
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5080
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5081
	for (uint i = 0; i < num; i++) {
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
  5082
		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
  5083
		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
  5084
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
  5085
		/* Unset activation flag */
5557
dc2402eb851b (svn r7554) -Fix (r7496): In Action 0xE, don't deactivate the current GRF (to be ported to 0.5)
peter1138
parents: 5340
diff changeset
  5086
		if (file != NULL && file != _cur_grfconfig) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5087
			grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  5088
			file->status = GCS_DISABLED;
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
  5089
		}
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
  5090
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5091
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5092
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5093
/* Action 0x0F */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5094
static void FeatureTownName(byte *buf, size_t len)
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5095
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5096
	/* <0F> <id> <style-name> <num-parts> <parts>
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5097
	 *
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5098
	 * B id          ID of this definition in bottom 7 bits (final definition if bit 7 set)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5099
	 * V style-name  Name of the style (only for final definition)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5100
	 * B num-parts   Number of parts in this definition
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5101
	 * V parts       The parts */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5102
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5103
	if (!check_length(len, 1, "FeatureTownName: definition ID")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5104
	buf++; len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5105
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5106
	uint32 grfid = _cur_grffile->grfid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5107
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5108
	GRFTownName *townname = AddGRFTownName(grfid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5109
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5110
	byte id = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5111
	len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5112
	grfmsg(6, "FeatureTownName: definition 0x%02X", id & 0x7F);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5113
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5114
	if (HasBit(id, 7)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5115
		/* Final definition */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5116
		ClrBit(id, 7);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5117
		bool new_scheme = _cur_grffile->grf_version >= 7;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5118
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5119
		if (!check_length(len, 1, "FeatureTownName: lang_id")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5120
		byte lang = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5121
		len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5122
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5123
		byte nb_gen = townname->nb_gen;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5124
		do {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5125
			ClrBit(lang, 7);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5126
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5127
			if (!check_length(len, 1, "FeatureTownName: style name")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5128
			const char *name = grf_load_string(&buf, len);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5129
			len -= strlen(name) + 1;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5130
			grfmsg(6, "FeatureTownName: lang 0x%X -> '%s'", lang, TranslateTTDPatchCodes(grfid, name));
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5131
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5132
			townname->name[nb_gen] = AddGRFString(grfid, id, lang, new_scheme, name, STR_UNDEFINED);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5133
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5134
			if (!check_length(len, 1, "FeatureTownName: lang_id")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5135
			lang = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5136
			len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5137
		} while (lang != 0);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5138
		townname->id[nb_gen] = id;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5139
		townname->nb_gen++;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5140
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5141
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5142
	if (!check_length(len, 1, "FeatureTownName: number of parts")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5143
	byte nb = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5144
	len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5145
	grfmsg(6, "FeatureTownName: %d parts", nb, nb);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5146
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5147
	townname->nbparts[id] = nb;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5148
	townname->partlist[id] = CallocT<NamePartList>(nb);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5149
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5150
	for (int i = 0; i < nb; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5151
		if (!check_length(len, 3, "FeatureTownName: parts header")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5152
		byte nbtext =  grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5153
		townname->partlist[id][i].bitstart  = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5154
		townname->partlist[id][i].bitcount  = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5155
		townname->partlist[id][i].maxprob   = 0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5156
		townname->partlist[id][i].partcount = nbtext;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5157
		townname->partlist[id][i].parts     = CallocT<NamePart>(nbtext);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5158
		len -= 3;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5159
		grfmsg(6, "FeatureTownName: part %d contains %d texts and will use GB(seed, %d, %d)", i, nbtext, townname->partlist[id][i].bitstart, townname->partlist[id][i].bitcount);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5160
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5161
		for (int j = 0; j < nbtext; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5162
			if (!check_length(len, 2, "FeatureTownName: part")) return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5163
			byte prob = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5164
			len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5165
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5166
			if (HasBit(prob, 7)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5167
				byte ref_id = grf_load_byte(&buf);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5168
				len--;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5169
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5170
				if (townname->nbparts[ref_id] == 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5171
					grfmsg(0, "FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5172
					DelGRFTownName(grfid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5173
					_cur_grfconfig->status = GCS_DISABLED;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5174
					_skip_sprites = -1;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5175
					return;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5176
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5177
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5178
				grfmsg(6, "FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5179
				townname->partlist[id][i].parts[j].data.id = ref_id;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5180
			} else {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5181
				const char *text = grf_load_string(&buf, len);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5182
				len -= strlen(text) + 1;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5183
				townname->partlist[id][i].parts[j].data.text = TranslateTTDPatchCodes(grfid, text);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5184
				grfmsg(6, "FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[id][i].parts[j].data.text, prob);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5185
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5186
			townname->partlist[id][i].parts[j].prob = prob;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5187
			townname->partlist[id][i].maxprob += GB(prob, 0, 7);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5188
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5189
		grfmsg(6, "FeatureTownName: part %d, total probability %d", i, townname->partlist[id][i].maxprob);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5190
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5191
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5192
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  5193
/* Action 0x10 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5194
static void DefineGotoLabel(byte *buf, size_t len)
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
  5195
{
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
  5196
	/* <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
  5197
	 *
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
  5198
	 * 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
  5199
	 * 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
  5200
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  5201
	if (!check_length(len, 1, "DefineGotoLabel")) return;
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
  5202
	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
  5203
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5204
	GRFLabel *label = MallocT<GRFLabel>(1);
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
  5205
	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
  5206
	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
  5207
	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
  5208
	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
  5209
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
  5210
	/* 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
  5211
	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
  5212
		_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
  5213
	} 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
  5214
		/* 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
  5215
		GRFLabel *l;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  5216
		for (l = _cur_grffile->label; l->next != NULL; l = l->next) {}
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
  5217
		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
  5218
	}
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
  5219
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5220
	grfmsg(2, "DefineGotoLabel: GOTO target with label 0x%02X", label->label);
3561
29c95ab685c0 (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code.
Darkvater
parents: 3557
diff changeset
  5221
}
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
  5222
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5223
/* Action 0x11 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5224
static void GRFSound(byte *buf, size_t len)
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5225
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5226
	/* <11> <num>
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5227
	 *
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5228
	 * 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
  5229
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  5230
	if (!check_length(len, 1, "GRFSound")) return;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5231
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5232
	uint16 num = grf_load_word(&buf);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5233
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5234
	_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
  5235
	_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
  5236
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5237
	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
  5238
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5239
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5240
/* Action 0x11 (SKIP) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5241
static void SkipAct11(byte *buf, size_t len)
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5242
{
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5243
	/* <11> <num>
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5244
	 *
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5245
	 * W num      Number of sound files that follow */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5246
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5247
	if (!check_length(len, 1, "SkipAct11")) return;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5248
	buf++;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5249
	_skip_sprites = grf_load_word(&buf);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5250
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5251
	grfmsg(3, "SkipAct11: Skipping %d sprites", _skip_sprites);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5252
}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5253
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5254
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
  5255
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5256
	const GRFFile *file;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5257
	FileEntry *se = AllocateFileEntry();
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5258
	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
  5259
	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
  5260
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5261
	file = GetFileByGRFID(grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5262
	if (file == NULL || file->sound_offset == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5263
		grfmsg(1, "ImportGRFSound: Source file not available");
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5264
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5265
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5266
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5267
	if (file->sound_offset + sound >= GetNumSounds()) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5268
		grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5269
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5270
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5271
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5272
	grfmsg(2, "ImportGRFSound: Copying sound %d (%d) from file %X", sound, file->sound_offset + sound, grfid);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5273
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  5274
	*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
  5275
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5276
	/* 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
  5277
	se->volume   = 128;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5278
	se->priority = 0;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5279
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5280
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5281
/* 'Action 0xFE' */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5282
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
  5283
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5284
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5285
		grfmsg(2, "GRFImportBlock: Unexpected import block, skipping");
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5286
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5287
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5288
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5289
	buf++;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5290
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5291
	_grf_data_blocks--;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5292
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5293
	/* 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
  5294
	 * 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
  5295
	if (grf_load_byte(&buf) != _grf_data_type) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5296
		grfmsg(1, "GRFImportBlock: Import type mismatch");
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5297
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5298
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5299
	switch (_grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5300
		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
  5301
		default: NOT_REACHED(); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5302
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5303
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5304
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5305
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
  5306
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5307
	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
  5308
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5309
	/* 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
  5310
	 * so that the indices used elsewhere are still correct. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5311
	FileEntry *se = AllocateFileEntry();
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5312
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  5313
	if (grf_load_dword(&buf) != BSWAP32('RIFF')) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5314
		grfmsg(1, "LoadGRFSound: Missing RIFF header");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5315
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5316
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5317
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5318
	/* 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
  5319
	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
  5320
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  5321
	if (grf_load_dword(&buf) != BSWAP32('WAVE')) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5322
		grfmsg(1, "LoadGRFSound: Invalid RIFF type");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5323
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5324
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5325
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5326
	for (;;) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5327
		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
  5328
		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
  5329
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5330
		switch (tag) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5331
			case ' tmf': // 'fmt '
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5332
				/* 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
  5333
				if (grf_load_word(&buf) != 1) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5334
					grfmsg(1, "LoadGRFSound: Invalid audio format");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5335
					return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5336
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5337
				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
  5338
				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
  5339
				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
  5340
				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
  5341
				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
  5342
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5343
				/* 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
  5344
				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
  5345
				break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5346
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5347
			case 'atad': // 'data'
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  5348
				se->file_size   = size;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  5349
				se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  5350
				se->file_slot   = _file_index;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5351
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5352
				/* 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
  5353
				se->volume = 0x80;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5354
				se->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5355
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5356
				grfmsg(2, "LoadGRFSound: channels %u, sample rate %u, bits per sample %u, length %u", se->channels, se->rate, se->bits_per_sample, size);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5357
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5358
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5359
			default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5360
				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
  5361
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5362
		}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5363
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5364
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5365
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
  5366
/* Action 0x12 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5367
static void LoadFontGlyph(byte *buf, size_t len)
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
  5368
{
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
  5369
	/* <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
  5370
	 *
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
  5371
	 * 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
  5372
	 * 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
  5373
	 * 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
  5374
	 * 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
  5375
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
  5376
	buf++; len--;
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  5377
	if (!check_length(len, 1, "LoadFontGlyph")) return;
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
  5378
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5379
	uint8 num_def = grf_load_byte(&buf);
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
  5380
5841
b36d6b560aaa (svn r8041) -Regression (r7564): [NewGRF] check_length should skip further processing if a length is too short, so give the function a return value
peter1138
parents: 5838
diff changeset
  5381
	if (!check_length(len, 1 + num_def * 4, "LoadFontGlyph")) return;
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
  5382
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5383
	for (uint i = 0; i < num_def; i++) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  5384
		FontSize size    = (FontSize)grf_load_byte(&buf);
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
  5385
		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
  5386
		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
  5387
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5388
		grfmsg(7, "LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5061
diff changeset
  5389
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5390
		for (uint c = 0; c < num_char; c++) {
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
  5391
			SetUnicodeGlyph(size, base_char + c, _cur_spriteid);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5392
			_nfo_line++;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5393
			LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line);
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
  5394
		}
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
  5395
	}
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
  5396
}
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
  5397
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5398
/* Action 0x12 (SKIP) */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5399
static void SkipAct12(byte *buf, size_t len)
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5400
{
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5401
	/* <12> <num_def> <font_size> <num_char> <base_char>
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5402
	 *
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5403
	 * B num_def      Number of definitions
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5404
	 * B font_size    Size of font (0 = normal, 1 = small, 2 = large)
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5405
	 * B num_char     Number of consecutive glyphs
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5406
	 * W base_char    First character index */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5407
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5408
	buf++; len--;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5409
	if (!check_length(len, 1, "SkipAct12")) return;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5410
	uint8 num_def = grf_load_byte(&buf);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5411
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5412
	if (!check_length(len, 1 + num_def * 4, "SkipAct12")) return;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5413
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5414
	for (uint i = 0; i < num_def; i++) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5415
		/* Ignore 'size' byte */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5416
		grf_load_byte(&buf);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5417
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5418
		/* Sum up number of characters */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5419
		_skip_sprites += grf_load_byte(&buf);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5420
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5421
		/* Ignore 'base_char' word */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5422
		grf_load_word(&buf);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5423
	}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5424
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5425
	grfmsg(3, "SkipAct12: Skipping %d sprites", _skip_sprites);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5426
}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5427
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5428
/* Action 0x13 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5429
static void TranslateGRFStrings(byte *buf, size_t len)
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5430
{
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5431
	/* <13> <grfid> <num-ent> <offset> <text...>
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5432
	 *
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5433
	 * 4*B grfid     The GRFID of the file whose texts are to be translated
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5434
	 * B   num-ent   Number of strings
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5435
	 * W   offset    First text ID
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5436
	 * S   text...   Zero-terminated strings */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5437
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5438
	buf++; len--;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5439
	if (!check_length(len, 7, "TranslateGRFString")) return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5440
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5441
	uint32 grfid = grf_load_dword(&buf);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5442
	const GRFConfig *c = GetGRFConfig(grfid);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5443
	if (c == NULL || (c->status != GCS_INITIALISED && c->status != GCS_ACTIVATED)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5444
		grfmsg(7, "TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13", BSWAP32(grfid));
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5445
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5446
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5447
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5448
	if (c->status == GCS_INITIALISED) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5449
		/* If the file is not active but will be activated later, give an error
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5450
		 * and disable this file. */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5451
		GRFError *error = CallocT<GRFError>(1);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5452
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5453
		char tmp[256];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5454
		GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5455
		error->data = strdup(tmp);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5456
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5457
		error->message  = STR_NEWGRF_ERROR_LOAD_AFTER;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5458
		error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5459
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5460
		if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5461
		_cur_grfconfig->error = error;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5462
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5463
		_cur_grfconfig->status = GCS_DISABLED;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5464
		_skip_sprites = -1;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5465
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5466
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5467
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5468
	byte num_strings = grf_load_byte(&buf);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5469
	uint16 first_id  = grf_load_word(&buf);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5470
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5471
	if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD3FF) || (first_id >= 0xDC00 && first_id + num_strings <= 0xDCFF))) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5472
		grfmsg(7, "TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings);
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5473
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5474
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5475
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5476
	len -= 7;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5477
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5478
	for (uint i = 0; i < num_strings && len > 0; i++) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5479
		const char *string   = grf_load_string(&buf, len);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5480
		size_t string_length = strlen(string) + 1;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5481
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5482
		len -= (int)string_length;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5483
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5484
		if (string_length == 1) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5485
			grfmsg(7, "TranslateGRFString: Ignoring empty string.");
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5486
			continue;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5487
		}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5488
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5489
		/* Since no language id is supplied this string has to be added as a
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5490
		 * generic string, thus the language id of 0x7F. For this to work
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5491
		 * new_scheme has to be true as well. A language id of 0x7F will be
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5492
		 * overridden by a non-generic id, so this will not change anything if
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5493
		 * a string has been provided specifically for this language. */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5494
		AddGRFString(grfid, first_id + i, 0x7F, true, string, STR_UNDEFINED);
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5495
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5496
}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5497
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5498
/* 'Action 0xFF' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5499
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
  5500
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5501
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5502
		grfmsg(2, "GRFDataBlock: unexpected data block, skipping");
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5503
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5504
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5505
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5506
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5507
	uint8 name_len = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5508
	const char *name = (const char *)buf;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5509
	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
  5510
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5511
	grfmsg(2, "GRFDataBlock: block name '%s'...", name);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5512
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5513
	_grf_data_blocks--;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5514
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5515
	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
  5516
		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
  5517
		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
  5518
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5519
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5520
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
  5521
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
  5522
/* Used during safety scan on unsafe actions */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5523
static void GRFUnsafe(byte *buf, size_t len)
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
  5524
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5525
	SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
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
  5526
5753
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5527
	/* Skip remainder of GRF */
788f8d55eb54 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5727
diff changeset
  5528
	_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
  5529
}
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
  5530
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
  5531
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5532
static void InitializeGRFSpecial()
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
  5533
{
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5534
	_ttdpatch_flags[0] =  ((_settings_game.station.always_small_airport ? 1 : 0) << 0x0C)  // keepsmallairport
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5535
	                   |                                                 (1 << 0x0D)  // newairports
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5536
	                   |                                                 (1 << 0x0E)  // largestations
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5537
	                   |      ((_settings_game.construction.longbridges ? 1 : 0) << 0x0F)  // longbridges
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5538
	                   |                                                 (0 << 0x10)  // loadtime
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5539
	                   |                                                 (1 << 0x12)  // presignals
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5540
	                   |                                                 (1 << 0x13)  // extpresignals
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5541
	                   | ((_settings_game.vehicle.never_expire_vehicles ? 1 : 0) << 0x16)  // enginespersist
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5542
	                   |                                                 (1 << 0x1B)  // multihead
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5543
	                   |                                                 (1 << 0x1D)  // lowmemory
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5544
	                   |                                                 (1 << 0x1E); // generalfixes
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5545
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5546
	_ttdpatch_flags[1] =   ((_settings_game.economy.station_noise_level ? 1 : 0) << 0x07)  // moreairports - based on units of noise
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5547
	                   |        ((_settings_game.vehicle.mammoth_trains ? 1 : 0) << 0x08)  // mammothtrains
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5548
	                   |                                                 (1 << 0x09)  // trainrefit
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5549
	                   |                                                 (0 << 0x0B)  // subsidiaries
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5550
	                   |         ((_settings_game.order.gradual_loading ? 1 : 0) << 0x0C)  // gradualloading
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5551
	                   |                                                 (1 << 0x12)  // unifiedmaglevmode - set bit 0 mode. Not revelant to OTTD
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5552
	                   |                                                 (1 << 0x13)  // unifiedmaglevmode - set bit 1 mode
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5553
	                   |                                                 (1 << 0x14)  // bridgespeedlimits
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5554
	                   |                                                 (1 << 0x16)  // eternalgame
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5555
	                   |                                                 (1 << 0x17)  // newtrains
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5556
	                   |                                                 (1 << 0x18)  // newrvs
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5557
	                   |                                                 (1 << 0x19)  // newships
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5558
	                   |                                                 (1 << 0x1A)  // newplanes
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5559
	                   |      ((_settings_game.construction.signal_side ? 1 : 0) << 0x1B)  // signalsontrafficside
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5560
	                   |       ((_settings_game.vehicle.disable_elrails ? 0 : 1) << 0x1C); // electrifiedrailway
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5561
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5562
	_ttdpatch_flags[2] =                                                 (1 << 0x01)  // loadallgraphics - obsolote
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5563
	                   |                                                 (1 << 0x03)  // semaphores
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5564
	                   |                                                 (0 << 0x0B)  // enhancedgui
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5565
	                   |                                                 (0 << 0x0C)  // newagerating
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5566
	                   |  ((_settings_game.construction.build_on_slopes ? 1 : 0) << 0x0D)  // buildonslopes
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5567
	                   |                                                 (1 << 0x0E)  // fullloadany
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5568
	                   |                                                 (1 << 0x0F)  // planespeed
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5569
	                   |                                                 (0 << 0x10)  // moreindustriesperclimate - obsolete
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5570
	                   |                                                 (0 << 0x11)  // moretoylandfeatures
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5571
	                   |                                                 (1 << 0x12)  // newstations
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5572
	                   |                                                 (1 << 0x13)  // tracktypecostdiff
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5573
	                   |                                                 (1 << 0x14)  // manualconvert
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5574
	                   |  ((_settings_game.construction.build_on_slopes ? 1 : 0) << 0x15)  // buildoncoasts
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5575
	                   |                                                 (1 << 0x16)  // canals
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5576
	                   |                                                 (1 << 0x17)  // newstartyear
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5577
	                   |    ((_settings_game.vehicle.freight_trains > 1 ? 1 : 0) << 0x18)  // freighttrains
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5578
	                   |                                                 (1 << 0x19)  // newhouses
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5579
	                   |                                                 (1 << 0x1A)  // newbridges
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5580
	                   |                                                 (1 << 0x1B)  // newtownnames
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5581
	                   |                                                 (1 << 0x1C)  // moreanimation
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5582
	                   |    ((_settings_game.vehicle.wagon_speed_limits ? 1 : 0) << 0x1D)  // wagonspeedlimits
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5583
	                   |                                                 (1 << 0x1E)  // newshistory
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5584
	                   |                                                 (0 << 0x1F); // custombridgeheads
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5585
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5586
	_ttdpatch_flags[3] =                                                 (0 << 0x00)  // newcargodistribution
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5587
	                   |                                                 (1 << 0x01)  // windowsnap
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5588
	                   |                                                 (0 << 0x02)  // townbuildnoroad
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5589
	                   |                                                 (0 << 0x03)  // pathbasedsignalling. To enable if ever pbs is back
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5590
	                   |                                                 (0 << 0x04)  // aichoosechance
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5591
	                   |                                                 (1 << 0x05)  // resolutionwidth
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5592
	                   |                                                 (1 << 0x06)  // resolutionheight
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5593
	                   |                                                 (1 << 0x07)  // newindustries
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5594
	                   |           ((_settings_game.order.improved_load ? 1 : 0) << 0x08)  // fifoloading
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5595
	                   |                                                 (0 << 0x09)  // townroadbranchprob
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5596
	                   |                                                 (0 << 0x0A)  // tempsnowline
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5597
	                   |                                                 (1 << 0x0B)  // newcargo
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5598
	                   |                                                 (1 << 0x0C)  // enhancemultiplayer
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5599
	                   |                                                 (1 << 0x0D)  // onewayroads
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5600
	                   |   ((_settings_game.station.nonuniform_stations ? 1 : 0) << 0x0E)  // irregularstations
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5601
	                   |                                                 (1 << 0x0F)  // statistics
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5602
	                   |                                                 (1 << 0x10)  // newsounds
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5603
	                   |                                                 (1 << 0x11)  // autoreplace
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5604
	                   |                                                 (1 << 0x12)  // autoslope
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5605
	                   |                                                 (0 << 0x13)  // followvehicle
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5606
	                   |                                                 (1 << 0x14)  // trams
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5607
	                   |                                                 (0 << 0x15)  // enhancetunnels
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5608
	                   |                                                 (1 << 0x16)  // shortrvs
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5609
	                   |                                                 (1 << 0x17)  // articulatedrvs
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5610
	                   |       ((_settings_game.vehicle.dynamic_engines ? 1 : 0) << 0x18)  // dynamic engines
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  5611
	                   |                                                 (1 << 0x1E); // variablerunningcosts
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
  5612
}
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
  5613
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5614
static void ResetCustomStations()
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5615
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5616
	for (GRFFile *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
  5617
		if (file->stations == NULL) continue;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5618
		for (uint i = 0; i < MAX_STATIONS; 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
  5619
			if (file->stations[i] == NULL) continue;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5620
			StationSpec *statspec = file->stations[i];
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5621
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5622
			/* 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
  5623
			if (!statspec->copied_renderdata) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5624
				for (uint t = 0; t < statspec->tiles; t++) {
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5625
					free((void*)statspec->renderdata[t].seq);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5626
				}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5627
				free(statspec->renderdata);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5628
			}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5629
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5630
			/* Release platforms and layouts */
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5631
			if (!statspec->copied_layouts) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5632
				for (uint l = 0; l < statspec->lengths; l++) {
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5633
					for (uint p = 0; p < statspec->platforms[l]; p++) {
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5634
						free(statspec->layouts[l][p]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5635
					}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5636
					free(statspec->layouts[l]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5637
				}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5638
				free(statspec->layouts);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5639
				free(statspec->platforms);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5640
			}
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
  5641
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
  5642
			/* 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
  5643
			free(statspec);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5644
		}
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
  5645
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
  5646
		/* 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
  5647
		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
  5648
		file->stations = NULL;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5649
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5650
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5651
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5652
static void ResetCustomHouses()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5653
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5654
	GRFFile *file;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5655
	uint i;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5656
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5657
	for (file = _first_grffile; file != NULL; file = file->next) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5658
		if (file->housespec == NULL) continue;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5659
		for (i = 0; i < HOUSE_MAX; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5660
			free(file->housespec[i]);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5661
		}
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5662
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5663
		free(file->housespec);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5664
		file->housespec = NULL;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5665
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5666
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5667
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5668
static void ResetCustomIndustries()
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5669
{
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5670
	GRFFile *file;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5671
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5672
	for (file = _first_grffile; file != NULL; file = file->next) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5673
		uint i;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5674
		/* We are verifiying both tiles and industries specs loaded from the grf file
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5675
		 * First, let's deal with industryspec */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5676
		if (file->industryspec != NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5677
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5678
			for (i = 0; i < NUM_INDUSTRYTYPES; i++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5679
				IndustrySpec *ind = file->industryspec[i];
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5680
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5681
				if (ind != NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5682
					/* We need to remove the sounds array */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5683
					if (HasBit(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5684
						free((void*)ind->random_sounds);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5685
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5686
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5687
					/* We need to remove the tiles layouts */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5688
					if (HasBit(ind->cleanup_flag, CLEAN_TILELSAYOUT) && ind->table != NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5689
						for (int j = 0; j < ind->num_table; j++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5690
							/* remove the individual layouts */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5691
							if (ind->table[j] != NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5692
								free((IndustryTileTable*)ind->table[j]);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5693
							}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5694
						}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5695
						/* remove the layouts pointers */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5696
						free((IndustryTileTable**)ind->table);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5697
						ind->table = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5698
					}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5699
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5700
					free(ind);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5701
					ind = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5702
				}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5703
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5704
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5705
			free(file->industryspec);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5706
			file->industryspec = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5707
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5708
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5709
		if (file->indtspec != NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5710
			for (i = 0; i < NUM_INDUSTRYTILES; i++) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5711
				if (file->indtspec[i] != NULL) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5712
					free(file->indtspec[i]);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5713
					file->indtspec[i] = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5714
				}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5715
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5716
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5717
			free(file->indtspec);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5718
			file->indtspec = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5719
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5720
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5721
}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5722
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5723
static void ResetNewGRF()
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5724
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5725
	GRFFile *next;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5726
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5727
	for (GRFFile *f = _first_grffile; f != NULL; f = next) {
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5728
		next = f->next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5729
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5730
		free(f->filename);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5731
		free(f->cargo_list);
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5732
		free(f);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5733
	}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5734
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5735
	_first_grffile = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5736
	_cur_grffile   = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5737
}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5738
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5739
static void ResetNewGRFErrors()
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5740
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5741
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5742
		if (!HasBit(c->flags, GCF_COPY) && c->error != NULL) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5743
			free(c->error->custom_message);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5744
			free(c->error->data);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5745
			free(c->error);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5746
			c->error = NULL;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5747
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5748
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5749
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5750
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5751
/**
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
  5752
 * 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
  5753
 * 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
  5754
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5755
static void ResetNewGRFData()
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
  5756
{
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  5757
	CleanUpStrings();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5758
	CleanUpGRFTownNames();
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  5759
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5760
	/* Copy/reset original engine info data */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  5761
	SetupEngines();
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
  5762
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5763
	/* Copy/reset original bridge info data */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5764
	ResetBridges();
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5765
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5766
	/* Allocate temporary refit/cargo class data */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5767
	_gted = CallocT<GRFTempEngineData>(GetEnginePoolSize());
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5768
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5769
	/* Reset GRM reservations */
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  5770
	memset(&_grm_engines, 0, sizeof(_grm_engines));
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5771
	memset(&_grm_cargos, 0, sizeof(_grm_cargos));
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  5772
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5773
	/* Reset generic feature callback lists */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5774
	ResetGenericCallbacks();
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  5775
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5776
	/* Reset price base data */
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  5777
	ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5778
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5779
	/* Reset the curencies array */
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5780
	ResetCurrencies();
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5781
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5782
	/* Reset the house array */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5783
	ResetCustomHouses();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5784
	ResetHouses();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5785
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5786
	/* Reset the industries structures*/
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5787
	ResetCustomIndustries();
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5788
	ResetIndustries();
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5789
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5790
	/* Reset station classes */
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5791
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5792
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  5793
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  5794
	/* Reset FSMports classes */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  5795
	ResetFSMportsClasses();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  5796
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  5797
	/* Reset canal sprite groups and flags */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  5798
	memset(_water_feature, 0, sizeof(_water_feature));
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5799
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  5800
	/* Reset the snowline table. */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  5801
	ClearSnowLine();
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  5802
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5803
	/* Reset NewGRF files */
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5804
	ResetNewGRF();
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5805
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5806
	/* Reset NewGRF errors. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5807
	ResetNewGRFErrors();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5808
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6416
diff changeset
  5809
	/* Set up the default cargo types */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  5810
	SetupCargoForClimate(_settings_game.game_creation.landscape);
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6416
diff changeset
  5811
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
  5812
	/* 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
  5813
	_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
  5814
	_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
  5815
	_traininfo_vehicle_width = 29;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  5816
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5817
	/* Reset track cost multipliers. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5818
	memcpy(&_railtype_cost_multiplier, &_default_railtype_cost_multiplier, sizeof(_default_railtype_cost_multiplier));
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5819
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5820
	_loaded_newgrf_features.has_2CC           = false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5821
	_loaded_newgrf_features.has_newhouses     = false;
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  5822
	_loaded_newgrf_features.has_newindustries = false;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  5823
	_loaded_newgrf_features.shore             = SHORE_REPLACE_NONE;
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
  5824
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5825
	/* Clear all GRF overrides */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5826
	_grf_id_overrides.clear();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5827
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5828
	InitializeSoundPool();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5829
	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
  5830
}
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
  5831
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
  5832
/** Reset all NewGRFData that was used only while processing data */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5833
static void ClearTemporaryNewGRFData()
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
  5834
{
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
  5835
	/* Clear the GOTO labels used for GRF processing */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5836
	for (GRFLabel *l = _cur_grffile->label; l != NULL;) {
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
  5837
		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
  5838
		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
  5839
		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
  5840
	}
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
  5841
	_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
  5842
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5843
	/* 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
  5844
	free(_cur_grffile->spritegroups);
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5845
	_cur_grffile->spritegroups = NULL;
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5846
	_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
  5847
}
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
  5848
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5849
static void BuildCargoTranslationMap()
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5850
{
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5851
	memset(_cur_grffile->cargo_map, 0xFF, sizeof(_cur_grffile->cargo_map));
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5852
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5853
	for (CargoID c = 0; c < NUM_CARGO; c++) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5854
		const CargoSpec *cs = GetCargo(c);
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5855
		if (!cs->IsValid()) continue;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5856
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5857
		if (_cur_grffile->cargo_max == 0) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5858
			/* Default translation table, so just a straight mapping to bitnum */
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5859
			_cur_grffile->cargo_map[c] = cs->bitnum;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5860
		} else {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5861
			/* Check the translation table for this cargo's label */
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5862
			for (uint i = 0; i < _cur_grffile->cargo_max; i++) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5863
				if (cs->label == _cur_grffile->cargo_list[i]) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5864
					_cur_grffile->cargo_map[c] = i;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5865
					break;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5866
				}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5867
			}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5868
		}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5869
	}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5870
}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5871
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
  5872
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
  5873
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5874
	GRFFile *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
  5875
	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
  5876
		/* 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
  5877
		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
  5878
		_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
  5879
		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
  5880
	}
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
  5881
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  5882
	newfile = CallocT<GRFFile>(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
  5883
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5884
	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
  5885
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  5886
	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
  5887
	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
  5888
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
  5889
	/* 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
  5890
	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
  5891
	newfile->param_end = config->num_params;
5681
7b237b4958d6 (svn r7636) -Cleanup: Remove unused window classes (sorry WC-mess) and use sizeof(array) instead
Darkvater
parents: 5664
diff changeset
  5892
	memcpy(newfile->param, config->param, sizeof(newfile->param));
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
  5893
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
  5894
	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
  5895
		_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
  5896
		_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
  5897
	} 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
  5898
		_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
  5899
		_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
  5900
	}
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
  5901
}
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
  5902
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5903
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5904
/** List of what cargo labels are refittable for the given the vehicle-type.
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5905
 * Only currently active labels are applied. */
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5906
static const CargoLabel _default_refitmasks_rail[] = {
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5907
	'PASS', 'COAL', 'MAIL', 'LVST', 'GOOD', 'GRAI', 'WHEA', 'MAIZ', 'WOOD',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5908
	'IORE', 'STEL', 'VALU', 'GOLD', 'DIAM', 'PAPR', 'FOOD', 'FRUT', 'CORE',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5909
	'WATR', 'SUGR', 'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5910
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5911
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5912
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5913
static const CargoLabel _default_refitmasks_road[] = {
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5914
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5915
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5916
static const CargoLabel _default_refitmasks_ships[] = {
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5917
	'COAL', 'MAIL', 'LVST', 'GOOD', 'GRAI', 'WHEA', 'MAIZ', 'WOOD', 'IORE',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5918
	'STEL', 'VALU', 'GOLD', 'DIAM', 'PAPR', 'FOOD', 'FRUT', 'CORE', 'WATR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5919
	'RUBR', 'SUGR', 'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5920
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5921
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5922
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5923
static const CargoLabel _default_refitmasks_aircraft[] = {
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5924
	'PASS', 'MAIL', 'GOOD', 'VALU', 'GOLD', 'DIAM', 'FOOD', 'FRUT', 'SUGR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5925
	'TOYS', 'BATT', 'SWET', 'TOFF', 'COLA', 'CTCD', 'BUBL', 'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5926
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5927
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5928
static const CargoLabel *_default_refitmasks[] = {
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5929
	_default_refitmasks_rail,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5930
	_default_refitmasks_road,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5931
	_default_refitmasks_ships,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5932
	_default_refitmasks_aircraft,
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5933
};
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5934
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5935
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5936
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5937
 * 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
  5938
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5939
static void CalculateRefitMasks()
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5940
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5941
	Engine *e;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5942
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5943
	FOR_ALL_ENGINES(e) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5944
		EngineID engine = e->index;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5945
		EngineInfo *ei = &e->info;
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5946
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5947
		uint32 not_mask = 0;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5948
		uint32 xor_mask = 0;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5949
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  5950
		if (ei->refit_mask != 0) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5951
			const GRFFile *file = e->grffile;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5952
			if (file != NULL && file->cargo_max != 0) {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5953
				/* Apply cargo translation table to the refit mask */
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5954
				uint num_cargo = min(32, file->cargo_max);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5955
				for (uint i = 0; i < num_cargo; i++) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  5956
					if (!HasBit(ei->refit_mask, i)) continue;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5957
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5958
					CargoID c = GetCargoIDByLabel(file->cargo_list[i]);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5959
					if (c == CT_INVALID) continue;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5960
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5961
					SetBit(xor_mask, c);
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5962
				}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5963
			} else {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5964
				/* No cargo table, so use the cargo bitnum values */
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5965
				for (CargoID c = 0; c < NUM_CARGO; c++) {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5966
					const CargoSpec *cs = GetCargo(c);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5967
					if (!cs->IsValid()) continue;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5968
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  5969
					if (HasBit(ei->refit_mask, cs->bitnum)) SetBit(xor_mask, c);
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5970
				}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5971
			}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5972
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5973
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5974
		if (_gted[engine].cargo_allowed != 0) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5975
			/* Build up the list of cargo types from the set cargo classes. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5976
			for (CargoID i = 0; i < NUM_CARGO; i++) {
6439
99a5807852b1 (svn r8849) -Codechange: Replace hardcoded global/climate cargo mapping tables with dynamically generated data. Change associated code to use new functions.
peter1138
parents: 6433
diff changeset
  5977
				const CargoSpec *cs = GetCargo(i);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5978
				if (_gted[engine].cargo_allowed    & cs->classes) SetBit(mask,     i);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5979
				if (_gted[engine].cargo_disallowed & cs->classes) SetBit(not_mask, i);
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5980
			}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5981
		} else if (xor_mask == 0) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5982
			/* Don't apply default refit mask to wagons or engines with no capacity */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5983
			if (e->type != VEH_TRAIN || (e->u.rail.capacity != 0 && e->u.rail.railveh_type != RAILVEH_WAGON)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  5984
				const CargoLabel *cl = _default_refitmasks[e->type];
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5985
				for (uint i = 0;; i++) {
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5986
					if (cl[i] == 0) break;
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5987
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5988
					CargoID cargo = GetCargoIDByLabel(cl[i]);
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5989
					if (cargo == CT_INVALID) continue;
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5990
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  5991
					SetBit(xor_mask, cargo);
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5992
				}
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5993
			}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5994
		}
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  5995
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  5996
		ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) & _cargo_mask;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  5997
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  5998
		/* Check if this engine's cargo type is valid. If not, set to the first refittable
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  5999
		 * cargo type. Apparently cargo_type isn't a common property... */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6000
		switch (e->type) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6001
			default: NOT_REACHED();
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6002
			case VEH_AIRCRAFT: break;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  6003
			case VEH_TRAIN: {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6004
				RailVehicleInfo *rvi = &e->u.rail;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6005
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6006
				if (rvi->cargo_type == CT_INVALID) ei->climates = 0x80;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6007
				break;
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6008
			}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  6009
			case VEH_ROAD: {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6010
				RoadVehicleInfo *rvi = &e->u.road;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6011
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6012
				if (rvi->cargo_type == CT_INVALID) ei->climates = 0x80;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6013
				break;
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6014
			}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  6015
			case VEH_SHIP: {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6016
				ShipVehicleInfo *svi = &e->u.ship;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6017
				if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6018
				if (svi->cargo_type == CT_INVALID) ei->climates = 0x80;
6468
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6019
				break;
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6020
			}
29a9bd549d0b (svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
peter1138
parents: 6465
diff changeset
  6021
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  6022
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  6023
}
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
  6024
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6025
/** Add all new houses to the house array. House properties can be set at any
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6026
 * time in the GRF file, so we can only add a house spec to the house array
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6027
 * after the file has finished loading. We also need to check the dates, due to
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6028
 * the TTDPatch behaviour described below that we need to emulate. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6029
static void FinaliseHouseArray()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6030
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6031
	/* If there are no houses with start dates before 1930, then all houses
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6032
	 * with start dates of 1930 have them reset to 0. This is in order to be
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6033
	 * compatible with TTDPatch, where if no houses have start dates before
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6034
	 * 1930 and the date is before 1930, the game pretends that this is 1930.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6035
	 * If there have been any houses defined with start dates before 1930 then
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6036
	 * the dates are left alone.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6037
	 * On the other hand, why 1930? Just 'fix' the houses with the lowest
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6038
	 * minimum introduction date to 0.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6039
	 */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  6040
	Year min_year = MAX_YEAR;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6041
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6042
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6043
		if (file->housespec == NULL) continue;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6044
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6045
		for (int i = 0; i < HOUSE_MAX; i++) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6046
			HouseSpec *hs = file->housespec[i];
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6047
			if (hs != NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6048
				_house_mngr.SetEntitySpec(hs);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  6049
				if (hs->min_year < min_year) min_year = hs->min_year;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6050
			}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6051
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6052
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6053
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  6054
	if (min_year != 0) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6055
		for (int i = 0; i < HOUSE_MAX; i++) {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6056
			HouseSpec *hs = GetHouseSpecs(i);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6057
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  6058
			if (hs->enabled && hs->min_year == min_year) hs->min_year = 0;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6059
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6060
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6061
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6062
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6063
/** Add all new industries to the industry array. Industry properties can be set at any
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6064
 * time in the GRF file, so we can only add a industry spec to the industry array
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6065
 * after the file has finished loading. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6066
static void FinaliseIndustriesArray()
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6067
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6068
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6069
		if (file->industryspec != NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6070
			for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6071
				IndustrySpec *indsp = file->industryspec[i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6072
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6073
				if (indsp != NULL && indsp->enabled) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6074
					StringID strid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6075
					/* process the conversion of text at the end, so to be sure everything will be fine
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6076
					 * and available.  Check if it does not return undefind marker, which is a very good sign of a
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6077
					 * substitute industry who has not changed the string been examined, thus using it as such */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6078
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6079
					if (strid != STR_UNDEFINED) indsp->name = strid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6080
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6081
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6082
					if (strid != STR_UNDEFINED) indsp->closure_text = strid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6083
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6084
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6085
					if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6086
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6087
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6088
					if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6089
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6090
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6091
					if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6092
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6093
					if (indsp->station_name != STR_NULL) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6094
						/* STR_NULL (0) can be set by grf.  It has a meaning regarding assignation of the
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6095
						 * station's name. Don't wont to loose the value, therefor, do not process. */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6096
						strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->station_name);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6097
						if (strid != STR_UNDEFINED) indsp->station_name = strid;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6098
					}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6099
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6100
					_industry_mngr.SetEntitySpec(indsp);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6101
					_loaded_newgrf_features.has_newindustries = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6102
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6103
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6104
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6105
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6106
		if (file->indtspec != NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6107
			for (int i = 0; i < NUM_INDUSTRYTILES; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6108
				IndustryTileSpec *indtsp = file->indtspec[i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6109
				if (indtsp != NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6110
					_industile_mngr.SetEntitySpec(indtsp);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6111
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6112
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6113
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6114
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6115
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6116
	for (uint j = 0; j < NUM_INDUSTRYTYPES; j++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6117
		IndustrySpec *indsp = &_industry_specs[j];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6118
		if (indsp->enabled && indsp->grf_prop.grffile != NULL) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6119
			for (uint i = 0; i < 3; i++) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6120
				indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6121
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6122
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6123
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6124
}
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6125
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6126
/** Each cargo string needs to be mapped from TTDPatch to OpenTTD string IDs.
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6127
 * This is done after loading so that strings from Action 4 will be mapped
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6128
 * properly. */
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6129
static void MapNewCargoStrings()
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6130
{
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6131
	for (CargoID c = 0; c < NUM_CARGO; c++) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6132
		CargoSpec *cs = &_cargo[c];
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6133
		/* Don't map if the cargo is unavailable or not from NewGRF */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6134
		if (cs->grfid == 0) continue;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6135
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6136
}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6137
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6138
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6139
/* 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
  6140
 * 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
  6141
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6142
/* 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
  6143
 * 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
  6144
 * 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
  6145
static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6146
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  6147
	/* 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
  6148
	 * 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
  6149
	 * 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
  6150
	 * "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
  6151
	 * 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
  6152
	 * 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
  6153
	 * 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
  6154
	 * 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
  6155
	 * --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
  6156
	/* 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
  6157
	 * 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
  6158
	 * 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
  6159
	static const SpecialSpriteHandler handlers[][GLS_END] = {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6160
		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       NULL,           ReserveChangeInfo, FeatureChangeInfo, },
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6161
		/* 0x01 */ { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6162
		/* 0x02 */ { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6163
		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6164
		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6165
		/* 0x05 */ { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },
6699
ff3ea89c64e4 (svn r9436) -Fix (r9411): don't deactivate GRF in an action 7/9 during reservation (and loading of cargo data), and action 6 should be run also
peter1138
parents: 6691
diff changeset
  6166
		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6167
		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6168
		/* 0x08 */ { ScanInfo, NULL,      NULL,            GRFInfo,        GRFInfo,           GRFInfo, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6169
		/* 0x09 */ { NULL,     NULL,      NULL,            SkipIf,         SkipIf,            SkipIf, },
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6170
		/* 0x0A */ { SkipActA, SkipActA,  SkipActA,        SkipActA,       SkipActA,          SpriteReplace, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6171
		/* 0x0B */ { NULL,     NULL,      NULL,            GRFLoadError,   GRFLoadError,      GRFLoadError, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6172
		/* 0x0C */ { NULL,     NULL,      NULL,            GRFComment,     NULL,              GRFComment, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6173
		/* 0x0D */ { NULL,     SafeParamSet, NULL,         ParamSet,       ParamSet,          ParamSet, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6174
		/* 0x0E */ { NULL,     SafeGRFInhibit, NULL,       GRFInhibit,     GRFInhibit,        GRFInhibit, },
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6175
		/* 0x0F */ { NULL,     GRFUnsafe, NULL,            FeatureTownName, NULL,             NULL, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6176
		/* 0x10 */ { NULL,     NULL,      DefineGotoLabel, NULL,           NULL,              NULL, },
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6177
		/* 0x11 */ { SkipAct11,GRFUnsafe, SkipAct11,       SkipAct11,      SkipAct11,         GRFSound, },
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6178
		/* 0x12 */ { SkipAct12, SkipAct12, SkipAct12,      SkipAct12,      SkipAct12,         LoadFontGlyph, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6179
		/* 0x13 */ { NULL,     NULL,      NULL,            NULL,           NULL,              TranslateGRFStrings, },
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
  6180
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  6181
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6182
	byte* buf;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  6183
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6184
	if (_preload_sprite == NULL) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6185
		/* 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
  6186
		 * pseudo sprite content. */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5844
diff changeset
  6187
		buf = MallocT<byte>(num);
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6188
		FioReadBlock(buf, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6189
	} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6190
		/* 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
  6191
		buf = _preload_sprite;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6192
		_preload_sprite = NULL;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  6193
		grfmsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data");
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6194
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6195
		/* 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
  6196
		FioSeekTo(num, SEEK_CUR);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6197
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  6198
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  6199
	byte action = buf[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
  6200
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  6201
	if (action == 0xFF) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6202
		grfmsg(7, "DecodeSpecialSprite: Handling data block in stage %d", stage);
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  6203
		GRFDataBlock(buf, num);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  6204
	} else if (action == 0xFE) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6205
		grfmsg(7, "DecodeSpecialSprite: Handling import block in stage %d", stage);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  6206
		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
  6207
	} else if (action >= lengthof(handlers)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6208
		grfmsg(7, "DecodeSpecialSprite: 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
  6209
	} else if (handlers[action][stage] == NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6210
		grfmsg(7, "DecodeSpecialSprite: 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
  6211
	} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6212
		grfmsg(7, "DecodeSpecialSprite: 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
  6213
		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
  6214
	}
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
  6215
	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
  6216
}
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
  6217
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
  6218
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  6219
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
  6220
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6221
	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
  6222
	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
  6223
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
  6224
	/* 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
  6225
	 * 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
  6226
	 * 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
  6227
	 * 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
  6228
	 * 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
  6229
	 *
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
  6230
	 * 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
  6231
	 * 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
  6232
	 * 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
  6233
	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
  6234
		_cur_grffile = GetFileByFilename(filename);
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  6235
		if (_cur_grffile == NULL) usererror("File '%s' lost in cache.\n", filename);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6236
		if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6237
		if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6238
		_cur_grffile->is_ottdfile = config->IsOpenTTDBaseGRF();
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6239
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6240
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6241
	if (file_index > LAST_GRF_SLOT) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6242
		DEBUG(grf, 0, "'%s' is not loaded as the maximum number of GRFs has been reached", filename);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6243
		config->status = GCS_DISABLED;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6244
		config->error  = CallocT<GRFError>(1);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6245
		config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6246
		config->error->message  = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6247
		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
  6248
	}
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
  6249
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
  6250
	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
  6251
	_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
  6252
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  6253
	_cur_grfconfig = config;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  6254
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6255
	DEBUG(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  6256
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
  6257
	/* 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
  6258
	 * 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
  6259
	 * 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
  6260
	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
  6261
		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
  6262
	} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6263
		DEBUG(grf, 7, "LoadNewGRFFile: Custom .grf has invalid format");
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  6264
		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
  6265
	}
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
  6266
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
  6267
	_skip_sprites = 0; // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  6268
	_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
  6269
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
  6270
	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
  6271
		byte type = FioReadByte();
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  6272
		_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
  6273
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
  6274
		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
  6275
			if (_skip_sprites == 0) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2935
diff changeset
  6276
				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
  6277
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
  6278
				/* 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
  6279
				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
  6280
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
  6281
				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
  6282
			} 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
  6283
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  6284
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  6285
		} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6286
			if (_skip_sprites == 0) grfmsg(7, "LoadNewGRFFile: Skipping unexpected sprite");
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  6287
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
  6288
			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
  6289
			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
  6290
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
  6291
			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
  6292
				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
  6293
			} 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
  6294
				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
  6295
					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
  6296
					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
  6297
						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
  6298
						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
  6299
					} 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
  6300
						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
  6301
						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
  6302
						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
  6303
					}
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
  6304
				}
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
  6305
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  6306
		}
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
  6307
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
  6308
		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
  6309
	}
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
  6310
}
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
  6311
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6312
/**
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6313
 * Relocates the old shore sprites at new positions.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6314
 *
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6315
 * 1. If shore sprites are neither loaded by Action5 nor ActionA, the extra sprites from openttd(w/d).grf are used. (SHORE_REPLACE_ONLY_NEW)
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6316
 * 2. If a newgrf replaces some shore sprites by ActionA. The (maybe also replaced) grass tiles are used for corner shores. (SHORE_REPLACE_ACTION_A)
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6317
 * 3. If a newgrf replaces shore sprites by Action5 any shore replacement by ActionA has no effect. (SHORE_REPLACE_ACTION_5)
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6318
 */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6319
static void ActivateOldShore()
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6320
{
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6321
	/* Use default graphics, if no shore sprites were loaded.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6322
	 * Should not happen, as openttd(w/d).grf includes some. */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6323
	if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_A;
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6324
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6325
	if (_loaded_newgrf_features.shore != SHORE_REPLACE_ACTION_5) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6326
		DupSprite(SPR_ORIGINALSHORE_START +  1, SPR_SHORE_BASE +  1); // SLOPE_W
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6327
		DupSprite(SPR_ORIGINALSHORE_START +  2, SPR_SHORE_BASE +  2); // SLOPE_S
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6328
		DupSprite(SPR_ORIGINALSHORE_START +  6, SPR_SHORE_BASE +  3); // SLOPE_SW
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6329
		DupSprite(SPR_ORIGINALSHORE_START     , SPR_SHORE_BASE +  4); // SLOPE_E
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6330
		DupSprite(SPR_ORIGINALSHORE_START +  4, SPR_SHORE_BASE +  6); // SLOPE_SE
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6331
		DupSprite(SPR_ORIGINALSHORE_START +  3, SPR_SHORE_BASE +  8); // SLOPE_N
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6332
		DupSprite(SPR_ORIGINALSHORE_START +  7, SPR_SHORE_BASE +  9); // SLOPE_NW
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6333
		DupSprite(SPR_ORIGINALSHORE_START +  5, SPR_SHORE_BASE + 12); // SLOPE_NE
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6334
	}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6335
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6336
	if (_loaded_newgrf_features.shore == SHORE_REPLACE_ACTION_A) {
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6337
		DupSprite(SPR_FLAT_GRASS_TILE + 16, SPR_SHORE_BASE +  0); // SLOPE_STEEP_S
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6338
		DupSprite(SPR_FLAT_GRASS_TILE + 17, SPR_SHORE_BASE +  5); // SLOPE_STEEP_W
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6339
		DupSprite(SPR_FLAT_GRASS_TILE +  7, SPR_SHORE_BASE +  7); // SLOPE_WSE
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6340
		DupSprite(SPR_FLAT_GRASS_TILE + 15, SPR_SHORE_BASE + 10); // SLOPE_STEEP_N
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6341
		DupSprite(SPR_FLAT_GRASS_TILE + 11, SPR_SHORE_BASE + 11); // SLOPE_NWS
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6342
		DupSprite(SPR_FLAT_GRASS_TILE + 13, SPR_SHORE_BASE + 13); // SLOPE_ENW
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6343
		DupSprite(SPR_FLAT_GRASS_TILE + 14, SPR_SHORE_BASE + 14); // SLOPE_SEN
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6344
		DupSprite(SPR_FLAT_GRASS_TILE + 18, SPR_SHORE_BASE + 15); // SLOPE_STEEP_E
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6345
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6346
		/* XXX - SLOPE_EW, SLOPE_NS are currently not used.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6347
		 *       If they would be used somewhen, then these grass tiles will most like not look as needed */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6348
		DupSprite(SPR_FLAT_GRASS_TILE +  5, SPR_SHORE_BASE + 16); // SLOPE_EW
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6349
		DupSprite(SPR_FLAT_GRASS_TILE + 10, SPR_SHORE_BASE + 17); // SLOPE_NS
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6350
	}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6351
}
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6352
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  6353
void InitDepotWindowBlockSizes();
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
  6354
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6355
extern void InitGRFTownGeneratorNames();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6356
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6357
static void AfterLoadGRFs()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6358
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  6359
	for (StringIDToGRFIDMapping::iterator it = _string_to_grf_mapping.begin(); it != _string_to_grf_mapping.end(); it++) {
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  6360
		*((*it).first) = MapGRFStringID((*it).second, *((*it).first));
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  6361
	}
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  6362
	_string_to_grf_mapping.clear();
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10192
diff changeset
  6363
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6364
	/* Update the bitmasks for the vehicle lists */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6365
	Player *p;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6366
	FOR_ALL_PLAYERS(p) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6367
		p->avail_railtypes = GetPlayerRailtypes(p->index);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6368
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6369
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6370
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6371
	/* Pre-calculate all refit masks after loading GRF files. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6372
	CalculateRefitMasks();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6373
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6374
	/* Set the block size in the depot windows based on vehicle sprite sizes */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6375
	InitDepotWindowBlockSizes();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6376
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6377
	/* Add all new houses to the house array. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6378
	FinaliseHouseArray();
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6379
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6380
	/* Add all new industries to the industry array. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6381
	FinaliseIndustriesArray();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6382
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6383
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6384
	BuildIndustriesLegend();
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6385
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6386
	/* Map cargo strings. This is a separate step because cargos are
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6387
	 * loaded before strings... */
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  6388
	MapNewCargoStrings();
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6389
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6390
	/* Update the townname generators list */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6391
	InitGRFTownGeneratorNames();
6854
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
  6392
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6393
	/* Run all queued vehicle list order changes */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6394
	CommitRailVehListOrderChanges();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6395
6854
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
  6396
	/* Update references for oil rigs and dummy airport */
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
  6397
	AirportFTAClass::oil_rig = GetCustomFSMportsSpecByGrf(0x4450414F, 3)->portFSM;
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
  6398
	AirportFTAClass::dummy   = GetCustomFSMportsSpecByGrf(0x4450414F, 4)->portFSM;
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6399
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6400
	/* Load old shore sprites in new position, if they were replaced by ActionA */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  6401
	ActivateOldShore();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6402
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6403
	/* Deallocate temporary loading data */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6404
	free(_gted);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6405
	_grm_sprites.clear();
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6406
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6407
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
  6408
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
  6409
{
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  6410
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6411
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
  6412
	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
  6413
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6414
	/*
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6415
	 * Reset the status of all files, so we can 'retry' to load them.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6416
	 * This is needed when one for example rearranges the NewGRFs in-game
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6417
	 * and a previously disabled NewGRF becomes useable. If it would not
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6418
	 * be reset, the NewGRF would remain disabled even though it should
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6419
	 * have been enabled.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6420
	 */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6421
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6422
		if (c->status != GCS_NOT_FOUND) c->status = GCS_UNKNOWN;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6423
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  6424
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6425
	_cur_spriteid = load_index;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10305
diff changeset
  6426
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
  6427
	/* 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
  6428
	 * 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
  6429
	 * and load information from it. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6430
	for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  6431
		/* Set activated grfs back to will-be-activated between reservation- and activation-stage.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  6432
		 * This ensures that action7/9 conditions 0x06 - 0x0A work correctly. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  6433
		for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  6434
			if (c->status == GCS_ACTIVATED) c->status = GCS_INITIALISED;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  6435
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  6436
2400
0b51bc385750 (svn r2926) -Fix: Use the same file slots in both initialisation stages when loading a patch grf
tron
parents: 2346
diff changeset
  6437
		uint slot = file_index;
2342
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  6438
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
  6439
		_cur_stage = stage;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  6440
		for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
6555
c27c9d5b459f (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6519
diff changeset
  6441
			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6442
			if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue;
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  6443
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  6444
			/* @todo usererror() */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  6445
			if (!FioCheckFileExists(c->filename)) usererror("NewGRF file is missing '%s'", c->filename);
3628
bd4a6601e5a2 (svn r4527) - Feature [NewGRF]: Add support for specifying parameters to GRF files. Usage: "mygrf = 1". You can pass up to 128 parameters, each one seperated by a comma or a space-character. Big thanks to peter1138 for the inspiration and examples.
Darkvater
parents: 3620
diff changeset
  6446
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
  6447
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6448
			LoadNewGRFFile(c, slot++, stage);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  6449
			if (stage == GLS_RESERVE) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6450
				SetBit(c->flags, GCF_RESERVED);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6451
			} else if (stage == GLS_ACTIVATION) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6452
				ClrBit(c->flags, GCF_RESERVED);
5727
0fd7e97094e2 (svn r7760) -Codechange: Debug messages for newgrf showed the starting sprite, not the current sprite index. Also only output the debug message during activation, when sprites are loaded.
peter1138
parents: 5726
diff changeset
  6453
				ClearTemporaryNewGRFData();
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  6454
				BuildCargoTranslationMap();
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6455
				DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur_spriteid);
5727
0fd7e97094e2 (svn r7760) -Codechange: Debug messages for newgrf showed the starting sprite, not the current sprite index. Also only output the debug message during activation, when sprites are loaded.
peter1138
parents: 5726
diff changeset
  6456
			}
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
  6457
		}
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
  6458
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  6459
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6460
	/* Call any functions that should be run after GRFs have been loaded. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6461
	AfterLoadGRFs();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6462
}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6463
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6464
bool HasGrfMiscBit(GrfMiscBit bit)
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6465
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  6466
	return HasBit(_misc_grf_features, bit);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6702
diff changeset
  6467
}