src/newgrf.cpp
author rubidium
Sun, 06 Jul 2008 11:08:40 +0000
changeset 11120 373bc4028ce2
parent 11117 cb9c1d913f92
permissions -rw-r--r--
(svn r13678) -Fix (r13677): electric trains from pre elrail savegames would get stopped on load.
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
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10416
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"
9282
2bb9703aeb39 (svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents: 9281
diff changeset
    12
#include "engine_func.h"
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
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"
9283
624272490f5a (svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents: 9282
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"
7029
209e4b2e1180 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 7025
diff changeset
    31
#include "industry.h"
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
    32
#include "newgrf_canal.h"
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 7119
diff changeset
    33
#include "newgrf_commons.h"
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
    34
#include "newgrf_townname.h"
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
    35
#include "newgrf_industries.h"
8268
a83cbd95f3d3 (svn r11321) -Codechange: add support to load different graphics for halftile slopes using a NewGRF. Patch by frosch.
rubidium
parents: 8253
diff changeset
    36
#include "gfxinit.h"
10402
b168fbb99f7c (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 10390
diff changeset
    37
#include "rev.h"
8301
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
    38
#include "fios.h"
8599
b609cdeeff3f (svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents: 8585
diff changeset
    39
#include "rail.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8600
diff changeset
    40
#include "strings_func.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    41
#include "gfx_func.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8627
diff changeset
    42
#include "date_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8636
diff changeset
    43
#include "vehicle_func.h"
8653
a83f7a536919 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8646
diff changeset
    44
#include "sound_func.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8694
diff changeset
    45
#include "string_func.h"
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8731
diff changeset
    46
#include "road_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8739
diff changeset
    47
#include "player_base.h"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8760
diff changeset
    48
#include "settings_type.h"
11020
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
    49
#include "network/network.h"
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
    50
#include "map_func.h"
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
    51
#include <map>
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
    52
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    53
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    54
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    55
#include "table/town_land.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    56
#include "table/build_industry.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    57
#include "table/landscape_sprite.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
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
7265
74148c363f9d (svn r10005) -Codechange: Merge two flags (2cc and newhouses) indicating some newgrf features have been loaded, and introduce the newindustry one.
belugas
parents: 7261
diff changeset
    89
/* Indicates which are the newgrf features currently loaded ingame */
7410
358b83972e29 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 7404
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
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
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,
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
   104
};
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
10298
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   106
/* Temporary data used when loading only */
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   107
struct GRFTempEngineData {
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   108
	uint16 cargo_allowed;
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   109
	uint16 cargo_disallowed;
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   110
};
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   111
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
   112
static GRFTempEngineData *_gted;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   114
/* Contains the GRF ID of the owner of a vehicle if it has been reserved.
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   115
 * GRM for vehicles is only used if dynamic engine allocation is disabled,
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   116
 * so 256 is the number of original engines. */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   117
static uint32 _grm_engines[256];
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
   118
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
   119
/* Contains the GRF ID of the owner of a cargo if it has been reserved */
9171
4cb9af6a3f61 (svn r12341) -Fix (r11224) [FS#1827]: GRM buffer for cargos was incorrect size.
peter1138
parents: 9164
diff changeset
   120
static uint32 _grm_cargos[NUM_CARGO * 2];
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
   121
10431
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
   122
struct GRFLocation {
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   123
	uint32 grfid;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   124
	uint32 nfoline;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   125
10431
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
   126
	GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { }
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
   127
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
   128
	bool operator<(const GRFLocation &other) const
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   129
	{
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   130
		return this->grfid < other.grfid || (this->grfid == other.grfid && this->nfoline < other.nfoline);
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   131
	}
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   132
};
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   133
10431
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
   134
static std::map<GRFLocation, SpriteID> _grm_sprites;
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
   135
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   136
/** 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
   137
 * 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
   138
 * 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
   139
 * 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
   140
 * 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
   141
 * 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
   142
 * @param severity debugging severity level, see debug.h
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6975
diff changeset
   143
 * @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
   144
void CDECL grfmsg(int severity, const char *str, ...)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
{
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 51
diff changeset
   146
	char buf[1024];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	va_start(va, str);
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   150
	vsnprintf(buf, sizeof(buf), str, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	va_end(va);
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   152
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   153
	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
   154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
   156
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
   157
{
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
   158
	if (real >= wanted) return true;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   159
	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
   160
	return false;
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
   161
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   162
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 490
diff changeset
   163
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
   164
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	return *(*buf)++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
}
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
static uint16 grf_load_word(byte **buf)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
{
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
   170
	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
   171
	return val | (grf_load_byte(buf) << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   174
static uint16 grf_load_extended(byte** buf)
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   175
{
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   176
	uint16 val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   177
	val = grf_load_byte(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   178
	if (val == 0xFF) val = grf_load_word(buf);
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   179
	return val;
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   180
}
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
   181
2324
117bd73a0731 (svn r2850) [newgrf] Patch from peter1139
miham
parents: 2204
diff changeset
   182
static uint32 grf_load_dword(byte **buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
{
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
   184
	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
   185
	return val | (grf_load_word(buf) << 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
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
   188
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
   189
{
d7ed0a867b49 (svn 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
	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
   191
		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
   192
		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
   193
		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
   194
		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
   195
			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
   196
			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
   197
	}
d7ed0a867b49 (svn 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
}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
   199
6416
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   200
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
   201
{
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   202
	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
   203
	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
   204
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   205
	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
   206
		/* 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
   207
		(*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
   208
		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
   209
	} else {
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   210
		/* 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
   211
		string_length++;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   212
	}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   213
	*buf += string_length;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   214
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   215
	return string;
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   216
}
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
   217
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   218
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
   219
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   220
	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
   221
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   222
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   223
		if (file->grfid == grfid) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   224
	}
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
   225
	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
   226
}
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
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   228
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
   229
{
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   230
	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
   231
1477
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   232
	for (file = _first_grffile; file != NULL; file = file->next) {
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   233
		if (strcmp(file->filename, filename) == 0) break;
2174a73b11c9 (svn r1981) Typedef some structs and enums
tron
parents: 1439
diff changeset
   234
	}
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
   235
	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
   236
}
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
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   238
/** Reset all NewGRFData that was used only while processing data */
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   239
static void ClearTemporaryNewGRFData()
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   240
{
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   241
	/* Clear the GOTO labels used for GRF processing */
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   242
	for (GRFLabel *l = _cur_grffile->label; l != NULL;) {
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   243
		GRFLabel *l2 = l->next;
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   244
		free(l);
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   245
		l = l2;
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   246
	}
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   247
	_cur_grffile->label = NULL;
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   248
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   249
	/* Clear the list of spritegroups */
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   250
	free(_cur_grffile->spritegroups);
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   251
	_cur_grffile->spritegroups = NULL;
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   252
	_cur_grffile->spritegroups_count = 0;
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   253
}
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
   254
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
   255
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
   256
typedef std::map<StringID *, uint32> StringIDToGRFIDMapping;
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
   257
StringIDToGRFIDMapping _string_to_grf_mapping;
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
   258
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   259
/** 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
   260
 * while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6975
diff changeset
   261
 * @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
   262
 * @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
   263
 * @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
   264
 */
8111
23e6be5756bb (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 8101
diff changeset
   265
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
   266
{
8375
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   267
	/* StringID table for TextIDs 0x4E->0x6D */
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   268
	static StringID units_volume[] = {
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   269
		STR_NOTHING,    STR_PASSENGERS, STR_TONS,       STR_BAGS,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   270
		STR_LITERS,     STR_ITEMS,      STR_CRATES,     STR_TONS,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   271
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   272
		STR_TONS,       STR_TONS,       STR_TONS,       STR_BAGS,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   273
		STR_TONS,       STR_TONS,       STR_BAGS,       STR_LITERS,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   274
		STR_TONS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   275
		STR_BAGS,       STR_LITERS,     STR_TONS,       STR_NOTHING,
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   276
		STR_TONS,       STR_NOTHING,    STR_LITERS,     STR_NOTHING
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   277
	};
9151
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   278
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   279
	/* 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
   280
	 * 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
   281
	 * 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
   282
	 * grfid in which they are declared */
9151
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   283
	switch (GB(str, 8, 8)) {
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   284
		case 0xD0: case 0xD1: case 0xD2: case 0xD3:
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   285
		case 0xDC:
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   286
			return GetGRFStringID(grfid, str);
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   287
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   288
		case 0xD4: case 0xD5: case 0xD6: case 0xD7:
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   289
			/* Strings embedded via 0x81 have 0x400 added to them (no real
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   290
			 * explanation why...) */
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   291
			return GetGRFStringID(grfid, str - 0x400);
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   292
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   293
		default: break;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   294
	}
9151
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
   295
8098
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   296
#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
   297
	/* We have some changes in our cargo strings, resulting in some missing. */
8098
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   298
	TEXID_TO_STRINGID(0x000E, 0x002D, STR_000E);
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   299
	TEXID_TO_STRINGID(0x002E, 0x004D, STR_002E);
8375
4f557c447806 (svn r11429) -Fix (r11129): some TextID to StringID 'translations' didn't follow our format
glx
parents: 8369
diff changeset
   300
	if (str >= 0x004E && str <= 0x006D) str = units_volume[str - 0x004E];
8098
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   301
	TEXID_TO_STRINGID(0x006E, 0x008D, STR_QUANTITY_NOTHING);
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   302
	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
   303
8646
cdf6b29351d0 (svn r11712) -Fix (r9315): Add more house string id ranges to MapGRFStringID so NewGRFs use the proper string ids.
maedhros
parents: 8640
diff changeset
   304
	/* Map building names according to our lang file changes. There are several
cdf6b29351d0 (svn r11712) -Fix (r9315): Add more house string id ranges to MapGRFStringID so NewGRFs use the proper string ids.
maedhros
parents: 8640
diff changeset
   305
	 * ranges of house ids, all of which need to be remapped to allow newgrfs
cdf6b29351d0 (svn r11712) -Fix (r9315): Add more house string id ranges to MapGRFStringID so NewGRFs use the proper string ids.
maedhros
parents: 8640
diff changeset
   306
	 * to use original house names. */
8098
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   307
	TEXID_TO_STRINGID(0x200F, 0x201F, STR_200F_TALL_OFFICE_BLOCK);
8646
cdf6b29351d0 (svn r11712) -Fix (r9315): Add more house string id ranges to MapGRFStringID so NewGRFs use the proper string ids.
maedhros
parents: 8640
diff changeset
   308
	TEXID_TO_STRINGID(0x2036, 0x2041, STR_2036_COTTAGES);
cdf6b29351d0 (svn r11712) -Fix (r9315): Add more house string id ranges to MapGRFStringID so NewGRFs use the proper string ids.
maedhros
parents: 8640
diff changeset
   309
	TEXID_TO_STRINGID(0x2059, 0x205C, STR_2059_IGLOO);
8098
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   310
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   311
	/* Same thing for industries, since the introduction of 4 new strings above STR_482A_PRODUCTION_LAST_MONTH */
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   312
	TEXID_TO_STRINGID(0x482A, 0x483B, STR_482A_PRODUCTION_LAST_MONTH);
e6088f363c48 (svn r11129) -Fix: update some TextID to StringID 'translations' to reflect changes in language files
glx
parents: 8066
diff changeset
   313
#undef TEXTID_TO_STRINGID
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   314
8101
fd60816a6c13 (svn r11132) -Fix: NewGRFs seem to assume that STR_NULL is an empty string or so.
rubidium
parents: 8098
diff changeset
   315
	if (str == STR_NULL) return STR_EMPTY;
fd60816a6c13 (svn r11132) -Fix: NewGRFs seem to assume that STR_NULL is an empty string or so.
rubidium
parents: 8098
diff changeset
   316
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   317
	return str;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   318
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   319
6701
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   320
static uint8 MapDOSColour(uint8 colour)
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   321
{
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   322
	if (_use_dos_palette) return colour;
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   323
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   324
	if (colour < 10) {
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   325
		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
   326
		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
   327
	}
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   328
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   329
	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
   330
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   331
	return colour;
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   332
}
d4c3cb84e494 (svn r9438) -Codechange: Map cargo colours from DOS to Windows if necessary.
peter1138
parents: 6699
diff changeset
   333
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   334
static std::map<uint32, uint32> _grf_id_overrides;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   335
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   336
static void SetNewGRFOverride(uint32 source_grfid, uint32 target_grfid)
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   337
{
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   338
	_grf_id_overrides[source_grfid] = target_grfid;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   339
	grfmsg(5, "SetNewGRFOverride: Added override of 0x%X to 0x%X", BSWAP32(source_grfid), BSWAP32(target_grfid));
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   340
}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   341
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   342
static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 internal_id)
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   343
{
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   344
	/* Hack for add-on GRFs that need to modify another GRF's engines. This lets
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   345
	 * them use the same engine slots. */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   346
	const GRFFile *grf_match = NULL;
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
   347
	if (_settings_game.vehicle.dynamic_engines) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   348
		uint32 override = _grf_id_overrides[file->grfid];
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   349
		if (override != 0) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   350
			grf_match = GetFileByGRFID(override);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   351
			if (grf_match == NULL) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   352
				grfmsg(5, "Tried mapping from GRFID %x to %x but target is not loaded", BSWAP32(file->grfid), BSWAP32(override));
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   353
			} else {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   354
				grfmsg(5, "Mapping from GRFID %x to %x", BSWAP32(file->grfid), BSWAP32(override));
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   355
			}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   356
		}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   357
	}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   358
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   359
	/* Check if this vehicle is already defined... */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   360
	Engine *e = NULL;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   361
	FOR_ALL_ENGINES(e) {
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
   362
		if (_settings_game.vehicle.dynamic_engines && e->grffile != NULL && e->grffile != file && e->grffile != grf_match) continue;
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   363
		if (e->type != type) continue;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   364
		if (e->internal_id != internal_id) continue;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   365
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   366
		if (e->grffile == NULL) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   367
			e->grffile = file;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   368
			grfmsg(5, "Replaced engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   369
		}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   370
		return e;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   371
	}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   372
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   373
	uint engine_pool_size = GetEnginePoolSize();
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   374
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   375
	/* ... it's not, so create a new one based off an existing engine */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   376
	e = new Engine(type, internal_id);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   377
	e->grffile = file;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   378
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   379
	if (engine_pool_size != GetEnginePoolSize()) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   380
		/* Resize temporary engine data ... */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   381
		_gted = ReallocT(_gted, GetEnginePoolSize());
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   383
		/* and blank the new block. */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   384
		size_t len = (GetEnginePoolSize() - engine_pool_size) * sizeof(*_gted);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   385
		memset(_gted + engine_pool_size, 0, len);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   386
	}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   387
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   388
	grfmsg(5, "Created new engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   389
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   390
	return e;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   391
}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   392
10390
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   393
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   394
{
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   395
	extern uint32 GetNewGRFOverride(uint32 grfid);
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   396
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   397
	const GRFFile *grf_match = NULL;
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
   398
	if (_settings_game.vehicle.dynamic_engines) {
10390
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   399
		uint32 override = _grf_id_overrides[file->grfid];
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   400
		if (override != 0) grf_match = GetFileByGRFID(override);
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   401
	}
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   402
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   403
	const Engine *e = NULL;
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   404
	FOR_ALL_ENGINES(e) {
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
   405
		if (_settings_game.vehicle.dynamic_engines && e->grffile != file && (grf_match == NULL || e->grffile != grf_match)) continue;
10390
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   406
		if (e->type != type) continue;
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   407
		if (e->internal_id != internal_id) continue;
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   408
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   409
		return e->index;
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   410
	}
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   411
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   412
	return INVALID_ENGINE;
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   413
}
8978442f5705 (svn r12932) -Fix [FS#1970]: Articulated engines ignored GRF engine overrides.
peter1138
parents: 10382
diff changeset
   414
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   415
/** Map the colour modifiers of TTDPatch to those that Open is using.
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   416
 * @param grf_sprite pointer to the structure been modified
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   417
 */
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   418
static void MapSpriteMappingRecolour(PalSpriteID *grf_sprite)
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   419
{
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   420
	if (HasBit(grf_sprite->pal, 14)) {
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   421
		ClrBit(grf_sprite->pal, 14);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   422
		SetBit(grf_sprite->sprite, SPRITE_MODIFIER_OPAQUE);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   423
	}
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   424
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   425
	if (HasBit(grf_sprite->sprite, 14)) {
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   426
		ClrBit(grf_sprite->sprite, 14);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   427
		SetBit(grf_sprite->sprite, PALETTE_MODIFIER_TRANSPARENT);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   428
	}
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   429
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   430
	if (HasBit(grf_sprite->sprite, 15)) {
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   431
		ClrBit(grf_sprite->sprite, 15);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   432
		SetBit(grf_sprite->sprite, PALETTE_MODIFIER_COLOR);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   433
	}
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
   434
}
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
   435
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   436
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
   437
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   438
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
   439
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
	byte *buf = *bufp;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   441
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   443
	for (int i = 0; i < numinfo; i++) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   444
		Engine *e = GetNewEngine(_cur_grffile, VEH_TRAIN, engine + i);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   445
		EngineInfo *ei = &e->info;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   446
		RailVehicleInfo *rvi = &e->u.rail;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   447
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   448
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   449
			case 0x05: { // Track type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
				uint8 tracktype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
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
   452
				switch (tracktype) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   453
					case 0: rvi->railtype = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   454
					case 1: rvi->railtype = RAILTYPE_MONO; break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   455
					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
   456
					default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   457
						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
   458
						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
   459
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   460
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   461
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   462
			case 0x08: // AI passenger service
8945
8cb92ac1b2fb (svn r12019) -Codechange: Add support for passenger engine designation for AI-use, NewGRF property 0x08 for trains.
peter1138
parents: 8927
diff changeset
   463
				/* Tells the AI that this engine is designed for
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
   464
				 * passenger services and shouldn't be used for freight. */
8945
8cb92ac1b2fb (svn r12019) -Codechange: Add support for passenger engine designation for AI-use, NewGRF property 0x08 for trains.
peter1138
parents: 8927
diff changeset
   465
				rvi->ai_passenger_only = grf_load_byte(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   466
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   467
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   468
			case 0x09: { // Speed (1 unit is 1 kmh)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
				uint16 speed = grf_load_word(&buf);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   470
				if (speed == 0xFFFF) speed = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   472
				rvi->max_speed = speed;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   473
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   474
10530
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   475
			case 0x0B: // Power
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   476
				rvi->power = grf_load_word(&buf);
10837
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   477
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   478
				/* Set engine / wagon state based on power */
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   479
				if (rvi->power != 0) {
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   480
					if (rvi->railveh_type == RAILVEH_WAGON) {
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   481
						rvi->railveh_type = RAILVEH_SINGLEHEAD;
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   482
					}
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   483
				} else {
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   484
					rvi->railveh_type = RAILVEH_WAGON;
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
   485
				}
10530
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   486
				break;
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   487
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   488
			case 0x0D: // Running cost factor
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   489
				rvi->running_cost = grf_load_byte(&buf);
d5b0caeac2d7 (svn r13074) -Fix: For multiheaded engines, halve power and running cost when used instead of when loading, to allow callback values to work properly.
peter1138
parents: 10465
diff changeset
   490
				break;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   491
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   492
			case 0x0E: { // Running cost base
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
				uint32 base = grf_load_dword(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
9122
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   495
				/* These magic numbers are used in GRFs to specify the base cost:
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   496
				 * http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   497
				 */
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   498
				if (base == 0) {
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   499
					rvi->running_cost_class = 0xFF;
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   500
				} else if (base < 0x4B34 || base > 0x4C54 || (base - 0x4B34) % 6 != 0) {
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   501
					grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base);
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   502
				} else {
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   503
					/* Convert the magic number to an index into the price data */
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   504
					rvi->running_cost_class = (base - 0x4B34) / 6;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   506
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   507
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   508
			case 0x12: { // Sprite ID
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
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
   511
				/* 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
   512
				 * 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
   513
				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
   514
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   515
				rvi->image_index = spriteid;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   516
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   517
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   518
			case 0x13: { // Dual-headed
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
				uint8 dual = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
   521
				if (dual != 0) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   522
					rvi->railveh_type = RAILVEH_MULTIHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
				} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   524
					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
   525
						RAILVEH_WAGON : RAILVEH_SINGLEHEAD;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   527
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   528
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   529
			case 0x14: // Cargo capacity
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   530
				rvi->capacity = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   531
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   532
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   533
			case 0x15: { // Cargo type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
				uint8 ctype = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   536
				if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   537
					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
   538
				} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   539
					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
   540
					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
   541
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   542
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   543
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   544
			case 0x16: // Weight
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   545
				SB(rvi->weight, 0, 8, grf_load_byte(&buf));
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   546
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   547
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   548
			case 0x17: // Cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   549
				rvi->base_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   550
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   551
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   552
			case 0x18: // AI rank
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   553
				rvi->ai_rank = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   554
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   555
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   556
			case 0x19: { // Engine traction type
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   557
				/* What do the individual numbers mean?
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   558
				 * 0x00 .. 0x07: Steam
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   559
				 * 0x08 .. 0x27: Diesel
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   560
				 * 0x28 .. 0x31: Electric
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   561
				 * 0x32 .. 0x37: Monorail
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   562
				 * 0x38 .. 0x41: Maglev
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   563
				 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
				uint8 traction = grf_load_byte(&buf);
7077
a76fe9c65fcb (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 7075
diff changeset
   565
				EngineClass engclass;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   567
				if (traction <= 0x07) {
7077
a76fe9c65fcb (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 7075
diff changeset
   568
					engclass = EC_STEAM;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   569
				} else if (traction <= 0x27) {
7077
a76fe9c65fcb (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 7075
diff changeset
   570
					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
   571
				} else if (traction <= 0x31) {
7077
a76fe9c65fcb (svn r9795) -Codechange: enumify the EngineClass.
rubidium
parents: 7075
diff changeset
   572
					engclass = EC_ELECTRIC;
7081
279d45234afe (svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium
parents: 7079
diff changeset
   573
				} else if (traction <= 0x37) {
279d45234afe (svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium
parents: 7079
diff changeset
   574
					engclass = EC_MONORAIL;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   575
				} else if (traction <= 0x41) {
7081
279d45234afe (svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium
parents: 7079
diff changeset
   576
					engclass = EC_MAGLEV;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   577
				} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
					break;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   579
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   580
				if (rvi->railtype == RAILTYPE_RAIL     && engclass >= EC_ELECTRIC) rvi->railtype = RAILTYPE_ELECTRIC;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   581
				if (rvi->railtype == RAILTYPE_ELECTRIC && engclass  < EC_ELECTRIC) rvi->railtype = RAILTYPE_RAIL;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   582
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   583
				rvi->engclass = engclass;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   584
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   585
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   586
			case 0x1A: // Alter purchase list sort order
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   587
				AlterRailVehListOrder(e->index, grf_load_byte(&buf));
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   588
				break;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   589
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   590
			case 0x1B: // Powered wagons power bonus
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   591
				rvi->pow_wag_power = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   592
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   593
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   594
			case 0x1C: // Refit cost
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   595
				ei->refit_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   596
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   597
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   598
			case 0x1D: // Refit cargo
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   599
				ei->refit_mask = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   600
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   601
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   602
			case 0x1E: // Callback
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   603
				ei->callbackmask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   604
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   605
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   606
			case 0x1F: // Tractive effort coefficient
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   607
				rvi->tractive_effort = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   608
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   609
8287
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   610
			case 0x20: // Air drag
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   611
				/** @todo Air drag for trains. */
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   612
				grf_load_byte(&buf);
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   613
				ret = true;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   614
				break;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   615
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   616
			case 0x21: // Shorter vehicle
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   617
				rvi->shorten_factor = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   618
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   619
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   620
			case 0x22: // Visual effect
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
   621
				/** @see note in engine.h about rvi->visual_effect */
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   622
				rvi->visual_effect = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   623
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   624
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   625
			case 0x23: // Powered wagons weight bonus
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   626
				rvi->pow_wag_weight = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   627
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   628
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   629
			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
   630
				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
   631
2545
d1965652e523 (svn r3074) -NewGrf: Fix stupid typo in weight setting.
peter1138
parents: 2542
diff changeset
   632
				if (weight > 4) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
   633
					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
   634
				} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   635
					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
   636
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   637
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   638
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   639
			case 0x25: // User-defined bit mask to set when checking veh. var. 42
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   640
				rvi->user_def_data = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   641
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   642
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   643
			case 0x26: // Retire vehicle early
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   644
				ei->retire_early = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   645
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   646
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   647
			case 0x27: // Miscellaneous flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   648
				ei->misc_flags = grf_load_byte(&buf);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   649
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   650
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   651
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   652
			case 0x28: // Cargo classes allowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   653
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   654
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   656
			case 0x29: // Cargo classes disallowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   657
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   658
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   659
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   660
			case 0x2A: // Long format introduction date (days since year 0)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   661
				ei->base_intro = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   662
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   663
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   664
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   665
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   666
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   667
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
	}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   669
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   674
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
   675
{
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   676
	byte *buf = *bufp;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   677
	bool ret = false;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   678
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   679
	for (int i = 0; i < numinfo; i++) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   680
		Engine *e = GetNewEngine(_cur_grffile, VEH_ROAD, engine + i);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   681
		EngineInfo *ei = &e->info;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   682
		RoadVehicleInfo *rvi = &e->u.road;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   683
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   684
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   685
			case 0x08: // Speed (1 unit is 0.5 kmh)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   686
				rvi->max_speed = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   687
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   688
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   689
			case 0x09: // Running cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   690
				rvi->running_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   691
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   692
9122
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   693
			case 0x0A: { // Running cost base
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   694
				uint32 base= grf_load_dword(&buf);
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   695
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   696
				/* These magic numbers are used in GRFs to specify the base cost:
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   697
				 * http://wiki.ttdpatch.net/tiki-index.php?page=BaseCosts
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   698
				 */
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   699
				if (base == 0) {
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   700
					rvi->running_cost_class = 0xFF;
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   701
				} else if (base < 0x4B34 || base > 0x4C54 || (base - 0x4B34) % 6 != 0) {
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   702
					grfmsg(1, "RailVehicleChangeInfo: Unsupported running cost base 0x%04X, ignoring", base);
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   703
				} else {
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   704
					/* Convert the magic number to an index into the price data */
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   705
					rvi->running_cost_class = (base - 0x4B34) / 6;
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   706
				}
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   707
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   708
				break;
bc3651767850 (svn r12209) -Fix: [NewGRF] Support using any base price for rail and road vehicles' running cost, and show running cost of wagons if they have it.
peter1138
parents: 9118
diff changeset
   709
			}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   710
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   711
			case 0x0E: { // Sprite ID
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   712
				uint8 spriteid = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   713
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   714
				/* 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
   715
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   716
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   717
				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
   718
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   719
				rvi->image_index = spriteid;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   720
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   721
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   722
			case 0x0F: // Cargo capacity
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   723
				rvi->capacity = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   724
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   725
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   726
			case 0x10: { // Cargo type
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   727
				uint8 cargo = grf_load_byte(&buf);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   728
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   729
				if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   730
					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
   731
				} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   732
					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
   733
					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
   734
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   735
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   736
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   737
			case 0x11: // Cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   738
				rvi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   739
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   740
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   741
			case 0x12: // SFX
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   742
				rvi->sfx = (SoundFx)grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   743
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   744
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   745
			case 0x13: // Power in 10hp
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   746
			case 0x14: // Weight in 1/4 tons
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   747
			case 0x15: // Speed in mph*0.8
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
   748
				/** @todo Support for road vehicles realistic power
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   749
				 * computations (called rvpower in TTDPatch) is just
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   750
				 * missing in OTTD yet. --pasky */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   751
				grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   752
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   753
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   754
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   755
			case 0x16: // Cargos available for refitting
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   756
				ei->refit_mask = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   757
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   758
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   759
			case 0x17: // Callback mask
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   760
				ei->callbackmask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   761
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   762
8287
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   763
			case 0x18: // Tractive effort
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   764
			case 0x19: // Air drag
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   765
				/** @todo Tractive effort and air drag for road vehicles. */
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   766
				grf_load_byte(&buf);
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   767
				ret = true;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   768
				break;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   769
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   770
			case 0x1A: // Refit cost
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   771
				ei->refit_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   772
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   773
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   774
			case 0x1B: // Retire vehicle early
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   775
				ei->retire_early = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   776
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   777
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   778
			case 0x1C: // Miscellaneous flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   779
				ei->misc_flags = grf_load_byte(&buf);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   780
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   781
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   782
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   783
			case 0x1D: // Cargo classes allowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   784
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   785
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   786
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   787
			case 0x1E: // Cargo classes disallowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   788
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   789
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   790
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   791
			case 0x1F: // Long format introduction date (days since year 0)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   792
				ei->base_intro = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   793
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   794
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   795
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   796
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   797
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   798
		}
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   799
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   800
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   801
	*bufp = buf;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   802
	return ret;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   803
}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
   804
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   805
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
   806
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	byte *buf = *bufp;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
   808
	bool ret = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   810
	for (int i = 0; i < numinfo; i++) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   811
		Engine *e = GetNewEngine(_cur_grffile, VEH_SHIP, engine + i);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   812
		EngineInfo *ei = &e->info;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   813
		ShipVehicleInfo *svi = &e->u.ship;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   814
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   815
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   816
			case 0x08: { // Sprite ID
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
				uint8 spriteid = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   819
				/* 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
   820
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   821
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   822
				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
   823
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   824
				svi->image_index = spriteid;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   825
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   826
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   827
			case 0x09: // Refittable
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   828
				svi->refittable = (grf_load_byte(&buf) != 0);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   829
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   830
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   831
			case 0x0A: // Cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   832
				svi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   833
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   834
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   835
			case 0x0B: // Speed (1 unit is 0.5 kmh)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   836
				svi->max_speed = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   837
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   838
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   839
			case 0x0C: { // Cargo type
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
				uint8 cargo = grf_load_byte(&buf);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   842
				if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   843
					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
   844
				} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   845
					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
   846
					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
   847
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   848
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   849
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   850
			case 0x0D: // Cargo capacity
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   851
				svi->capacity = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   852
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   853
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   854
			case 0x0F: // Running cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   855
				svi->running_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   856
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   857
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   858
			case 0x10: // SFX
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   859
				svi->sfx = (SoundFx)grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   860
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   861
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   862
			case 0x11: // Cargos available for refitting
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   863
				ei->refit_mask = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   864
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   865
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   866
			case 0x12: // Callback mask
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   867
				ei->callbackmask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   868
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   869
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   870
			case 0x13: // Refit cost
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   871
				ei->refit_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   872
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   873
8287
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   874
			case 0x14: // Ocean speed fraction
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   875
			case 0x15: // Canal speed fraction
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   876
				/** @todo Speed fractions for ships on oceans and canals */
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   877
				grf_load_byte(&buf);
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   878
				ret = true;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   879
				break;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
   880
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   881
			case 0x16: // Retire vehicle early
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   882
				ei->retire_early = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   883
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   884
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   885
			case 0x17: // Miscellaneous flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   886
				ei->misc_flags = grf_load_byte(&buf);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   887
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   888
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   889
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   890
			case 0x18: // Cargo classes allowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   891
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   892
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   893
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   894
			case 0x19: // Cargo classes disallowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   895
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   896
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   897
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   898
			case 0x1A: // Long format introduction date (days since year 0)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   899
				ei->base_intro = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   900
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   901
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   902
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   903
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   904
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   905
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	*bufp = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	return ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
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
   912
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
   913
{
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
   914
	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
   915
	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
   916
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   917
	for (int i = 0; i < numinfo; i++) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   918
		Engine *e = GetNewEngine(_cur_grffile, VEH_AIRCRAFT, engine + i);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   919
		EngineInfo *ei = &e->info;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   920
		AircraftVehicleInfo *avi = &e->u.air;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   921
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   922
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   923
			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
   924
				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
   925
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
   926
				/* 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
   927
				if (spriteid == 0xFF) spriteid = 0xFD;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   928
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
   929
				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
   930
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   931
				avi->image_index = spriteid;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   932
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   933
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   934
			case 0x09: // Helicopter
4926
f67f27fb122f (svn r6906) - Fix [FS#370]: Clear 'large plane' flag if 'helicopter' flag is set. (mart3p)
peter1138
parents: 4918
diff changeset
   935
				if (grf_load_byte(&buf) == 0) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   936
					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
   937
				} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   938
					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
   939
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   940
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   941
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   942
			case 0x0A: // Large
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   943
				SB(avi->subtype, 1, 1, (grf_load_byte(&buf) != 0 ? 1 : 0)); // AIR_FAST
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   944
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   945
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   946
			case 0x0B: // Cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   947
				avi->base_cost = grf_load_byte(&buf); // ?? is it base_cost?
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   948
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   949
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   950
			case 0x0C: // Speed (1 unit is 8 mph, we translate to 1 unit is 1 km/h)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   951
				avi->max_speed = (grf_load_byte(&buf) * 129) / 10;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   952
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   953
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   954
			case 0x0D: // Acceleration
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   955
				avi->acceleration = (grf_load_byte(&buf) * 129) / 10;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   956
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   957
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   958
			case 0x0E: // Running cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   959
				avi->running_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   960
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   961
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   962
			case 0x0F: // Passenger capacity
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   963
				avi->passenger_capacity = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   964
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   965
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   966
			case 0x11: // Mail capacity
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   967
				avi->mail_capacity = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   968
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   969
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   970
			case 0x12: // SFX
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   971
				avi->sfx = (SoundFx)grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   972
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   973
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   974
			case 0x13: // Cargos available for refitting
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   975
				ei->refit_mask = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   976
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   977
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   978
			case 0x14: // Callback mask
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   979
				ei->callbackmask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   980
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   981
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   982
			case 0x15: // Refit cost
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   983
				ei->refit_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   984
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   985
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   986
			case 0x16: // Retire vehicle early
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   987
				ei->retire_early = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   988
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   989
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   990
			case 0x17: // Miscellaneous flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   991
				ei->misc_flags = grf_load_byte(&buf);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   992
				_loaded_newgrf_features.has_2CC |= HasBit(ei->misc_flags, EF_USES_2CC);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   993
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   994
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   995
			case 0x18: // Cargo classes allowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
   996
				_gted[e->index].cargo_allowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   997
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   998
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
   999
			case 0x19: // Cargo classes disallowed
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1000
				_gted[e->index].cargo_disallowed = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1001
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1002
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1003
			case 0x1A: // Long format introduction date (days since year 0)
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1004
				ei->base_intro = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1005
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1006
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1007
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1008
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1009
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1010
		}
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
  1011
	}
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
  1012
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
  1013
	*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
  1014
	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
  1015
}
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
  1016
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1017
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
  1018
{
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1019
	byte *buf = *bufp;
3505
e9a3a6b79561 (svn r4356) - NewGRF: Load more newstation properties.
peter1138
parents: 3504
diff changeset
  1020
	bool ret = false;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1021
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
  1022
	if (stid + numinfo > MAX_STATIONS) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1023
		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
  1024
		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
  1025
	}
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
  1026
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
  1027
	/* 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
  1028
	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
  1029
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1030
	for (int i = 0; i < numinfo; i++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1031
		StationSpec *statspec = _cur_grffile->stations[stid + i];
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1032
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1033
		/* Check that the station we are modifying is defined. */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1034
		if (statspec == NULL && prop != 0x08) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1035
			grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1036
			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
  1037
		}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1038
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1039
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1040
			case 0x08: { // Class ID
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1041
				StationSpec **spec = &_cur_grffile->stations[stid + i];
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1042
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
  1043
				/* Property 0x08 is special; it is where the station is allocated */
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1044
				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
  1045
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
  1046
				/* 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
  1047
				uint32 classid = grf_load_dword(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1048
				(*spec)->sclass = AllocateStationClass(BSWAP32(classid));
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1049
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1050
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1051
			case 0x09: // Define sprite layout
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1052
				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
  1053
				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
  1054
				statspec->copied_renderdata = false;
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1055
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1056
				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
  1057
					DrawTileSprites *dts = &statspec->renderdata[t];
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
  1058
					uint seq_count = 0;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1059
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
  1060
					dts->seq = NULL;
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1061
					dts->ground.sprite = grf_load_word(&buf);
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1062
					dts->ground.pal = grf_load_word(&buf);
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1063
					if (dts->ground.sprite == 0) continue;
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1064
					if (HasBit(dts->ground.pal, 15)) {
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1065
						ClrBit(dts->ground.pal, 15);
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  1066
						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
  1067
					}
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  1068
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  1069
					MapSpriteMappingRecolour(&dts->ground);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  1070
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1071
					while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1072
						DrawTileSeqStruct *dtss;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1073
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  1074
						/* 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
  1075
						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
  1076
						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
  1077
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1078
						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
  1079
						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
  1080
						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
  1081
						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
  1082
						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
  1083
						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
  1084
						dtss->size_z = grf_load_byte(&buf);
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  1085
						dtss->image.sprite = grf_load_word(&buf);
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  1086
						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
  1087
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  1088
						/* Remap flags as ours collide */
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  1089
						if (HasBit(dtss->image.pal, 15)) {
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  1090
							ClrBit(dtss->image.pal, 15);
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  1091
							SetBit(dtss->image.sprite, SPRITE_MODIFIER_USE_OFFSET);
8654
83dc418497a9 (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8653
diff changeset
  1092
						}
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  1093
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  1094
						MapSpriteMappingRecolour(&dtss->image);
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1095
					}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1096
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1097
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1098
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1099
			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
  1100
				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
  1101
				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
  1102
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1103
				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
  1104
				statspec->renderdata = srcstatspec->renderdata;
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  1105
				statspec->copied_renderdata = true;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1106
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1107
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1108
			case 0x0B: // Callback mask
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1109
				statspec->callbackmask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1110
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1111
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1112
			case 0x0C: // Disallowed number of platforms
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1113
				statspec->disallowed_platforms = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1114
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1115
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1116
			case 0x0D: // Disallowed platform lengths
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1117
				statspec->disallowed_lengths = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1118
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1119
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1120
			case 0x0E: // Define custom layout
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1121
				statspec->copied_layouts = false;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1122
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1123
				while (buf < *bufp + len) {
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1124
					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
  1125
					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
  1126
					StationLayout layout;
3570
f9749bae861e (svn r4452) - NewGRF: switch to unsigned ints for array indices.
peter1138
parents: 3566
diff changeset
  1127
					uint l, p;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1128
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1129
					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
  1130
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1131
					//debug("l %d > %d ?", length, stat->lengths);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1132
					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
  1133
						statspec->platforms = ReallocT(statspec->platforms, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1134
						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
  1135
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
  1136
						statspec->layouts = ReallocT(statspec->layouts, length);
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1137
						memset(statspec->layouts + statspec->lengths, 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1138
						       (length - statspec->lengths) * sizeof(*statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1139
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1140
						statspec->lengths = length;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1141
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1142
					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
  1143
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1144
					//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
  1145
					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
  1146
						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
  1147
						/* 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
  1148
						memset(statspec->layouts[l] + statspec->platforms[l], 0,
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1149
						       (number - statspec->platforms[l]) * sizeof(**statspec->layouts));
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1150
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1151
						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
  1152
					}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1153
542
2f35c4770b06 (svn r939) -Fix: Fixed compiler errors
truelight
parents: 536
diff changeset
  1154
					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
  1155
					layout = MallocT<byte>(length * number);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1156
					for (l = 0; l < length; l++) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1157
						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
  1158
							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
  1159
						}
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  1160
					}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1161
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1162
					l--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 448
diff changeset
  1163
					p--;
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1164
					free(statspec->layouts[l][p]);
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3672
diff changeset
  1165
					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
  1166
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1167
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1168
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1169
			case 0x0F: { // Copy custom layout
5060
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1170
				byte srcid = grf_load_byte(&buf);
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1171
				const StationSpec *srcstatspec = _cur_grffile->stations[srcid];
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1172
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1173
				statspec->lengths   = srcstatspec->lengths;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1174
				statspec->platforms = srcstatspec->platforms;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1175
				statspec->layouts   = srcstatspec->layouts;
2d577061b0ec (svn r7113) -Codechange: [NewStations] Add support for copying custom station layouts
peter1138
parents: 5037
diff changeset
  1176
				statspec->copied_layouts = true;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1177
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1178
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1179
			case 0x10: // Little/lots cargo threshold
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1180
				statspec->cargo_threshold = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1181
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1182
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1183
			case 0x11: // Pylon placement
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1184
				statspec->pylons = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1185
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1186
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1187
			case 0x12: // Cargo types for random triggers
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1188
				statspec->cargo_triggers = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1189
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1190
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1191
			case 0x13: // General flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1192
				statspec->flags = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1193
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1194
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1195
			case 0x14: // Overhead wire placement
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1196
				statspec->wires = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1197
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1198
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1199
			case 0x15: // Blocked tiles
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1200
				statspec->blocked = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1201
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1202
10266
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1203
			case 0x16: // Animation info
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1204
				statspec->anim_frames = grf_load_byte(&buf);
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1205
				statspec->anim_status = grf_load_byte(&buf);
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1206
				break;
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1207
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1208
			case 0x17: // Animation speed
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1209
				statspec->anim_speed = grf_load_byte(&buf);
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1210
				break;
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1211
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1212
			case 0x18: // Animation triggers
435142fa43dc (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 10229
diff changeset
  1213
				statspec->anim_triggers = grf_load_word(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1214
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1215
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1216
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1217
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1218
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1219
		}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1220
	}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1221
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1222
	*bufp = buf;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1223
	return ret;
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1224
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1225
8868
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1226
static bool CanalChangeInfo(uint id, int numinfo, int prop, byte **bufp, int len)
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1227
{
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1228
	byte *buf = *bufp;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1229
	bool ret = false;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1230
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1231
	if (id + numinfo > CF_END) {
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1232
		grfmsg(1, "CanalChangeInfo: Canal feature %u is invalid, max %u, ignoreing", id + numinfo, CF_END);
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1233
		return false;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1234
	}
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1235
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1236
	for (int i = 0; i < numinfo; i++) {
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1237
		WaterFeature *wf = &_water_feature[id + i];
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1238
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1239
		switch (prop) {
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1240
			case 0x08:
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1241
				wf->callbackmask = grf_load_byte(&buf);
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1242
				break;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1243
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1244
			case 0x09:
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1245
				wf->flags = grf_load_byte(&buf);
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1246
				break;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1247
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1248
			default:
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1249
				ret = true;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1250
				break;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1251
		}
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1252
	}
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1253
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1254
	*bufp = buf;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1255
	return ret;
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1256
}
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  1257
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
  1258
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
  1259
{
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
  1260
	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
  1261
	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
  1262
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1263
	if (brid + numinfo > MAX_BRIDGES) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1264
		grfmsg(1, "BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo, MAX_BRIDGES);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1265
		return false;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1266
	}
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1267
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1268
	for (int i = 0; i < numinfo; i++) {
9031
e260304797e6 (svn r12111) -Codechange: Rename Bridge to BridgeSpec, out of consistensy with other Specs in used.
belugas
parents: 8990
diff changeset
  1269
		BridgeSpec *bridge = &_bridge[brid + i];
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1270
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1271
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1272
			case 0x08: // Year of availability
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1273
				bridge->avail_year = ORIGINAL_BASE_YEAR + grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1274
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1275
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1276
			case 0x09: // Minimum length
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1277
				bridge->min_length = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1278
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1279
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1280
			case 0x0A: // Maximum length
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1281
				bridge->max_length = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1282
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1283
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1284
			case 0x0B: // Cost factor
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1285
				bridge->price = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1286
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1287
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1288
			case 0x0C: // Maximum speed
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1289
				bridge->speed = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1290
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1291
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1292
			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
  1293
				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
  1294
				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
  1295
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
  1296
				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
  1297
					/* 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
  1298
					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
  1299
				}
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
  1300
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
  1301
				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
  1302
					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
  1303
						grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid);
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1304
						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
  1305
						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
  1306
					}
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
  1307
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
  1308
					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
  1309
						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
  1310
					}
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
  1311
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  1312
					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
  1313
						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
  1314
						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
  1315
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5868
diff changeset
  1316
						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
  1317
						bridge->sprite_table[tableid][sprite].pal    = pal;
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  1318
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  1319
						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
  1320
					}
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
  1321
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1322
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1323
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1324
			case 0x0E: // Flags; bit 0 - disable far pillars
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1325
				bridge->flags = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1326
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1327
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1328
			case 0x0F: // Long format year of availability (year since year 0)
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8398
diff changeset
  1329
				bridge->avail_year = Clamp(grf_load_dword(&buf), MIN_YEAR, MAX_YEAR);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1330
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1331
8990
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1332
			case 0x10: { // purchase string
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1333
				StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1334
				if (newone != STR_UNDEFINED) bridge->material = newone;
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1335
				} break;
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1336
9036
d3b132a4b97a (svn r12118) -Codechange: Put the two descriptions of bridges in an array instead of two single variables, following the transport type it represents
belugas
parents: 9031
diff changeset
  1337
			case 0x11: // description of bridge with rails or roads
d3b132a4b97a (svn r12118) -Codechange: Put the two descriptions of bridges in an array instead of two single variables, following the transport type it represents
belugas
parents: 9031
diff changeset
  1338
			case 0x12: {
8990
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1339
				StringID newone = GetGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
9036
d3b132a4b97a (svn r12118) -Codechange: Put the two descriptions of bridges in an array instead of two single variables, following the transport type it represents
belugas
parents: 9031
diff changeset
  1340
				if (newone != STR_UNDEFINED) bridge->transport_name[prop - 0x11] = newone;
8990
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1341
				} break;
dcaad4072e7b (svn r12069) -Feature[newGRF]: Specify the purchase, rail and road description of a bridge.
belugas
parents: 8985
diff changeset
  1342
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1343
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1344
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1345
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1346
		}
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
  1347
	}
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
  1348
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
  1349
	*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
  1350
	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
  1351
}
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  1352
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1353
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
  1354
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1355
	byte *buf = *bufp;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1356
	bool ret = false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1357
7657
1b1d190f0272 (svn r10435) -Fix (r9315): numinfo starts from 1, not 0, so make it possible to define a house with a local id of 255.
maedhros
parents: 7656
diff changeset
  1358
	if (hid + numinfo > HOUSE_MAX) {
1b1d190f0272 (svn r10435) -Fix (r9315): numinfo starts from 1, not 0, so make it possible to define a house with a local id of 255.
maedhros
parents: 7656
diff changeset
  1359
		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
  1360
		return false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1361
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1362
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1363
	/* 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
  1364
	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
  1365
		_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
  1366
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1367
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1368
	for (int i = 0; i < numinfo; i++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1369
		HouseSpec *housespec = _cur_grffile->housespec[hid + i];
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1370
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1371
		if (prop != 0x08 && housespec == NULL) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1372
			grfmsg(2, "TownHouseChangeInfo: Attempt to modify undefined house %u. Ignoring.", hid + i);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1373
			continue;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1374
		}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1375
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1376
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1377
			case 0x08: { // Substitute building type, and definition of a new house
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1378
				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
  1379
				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
  1380
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1381
				if (subs_id == 0xFF) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1382
					/* 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
  1383
					 * 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
  1384
					_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
  1385
					continue;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1386
				} 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
  1387
					/* 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
  1388
					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
  1389
					return false;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1390
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1391
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1392
				/* Allocate space for this house. */
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1393
				if (*house == NULL) *house = CallocT<HouseSpec>(1);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1394
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1395
				housespec = *house;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1396
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1397
				memcpy(housespec, &_house_specs[subs_id], sizeof(_house_specs[subs_id]));
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1398
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1399
				housespec->enabled = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1400
				housespec->local_id = hid + i;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1401
				housespec->substitute_id = subs_id;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1402
				housespec->grffile = _cur_grffile;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1403
				housespec->random_colour[0] = 0x04;  // those 4 random colours are the base colour
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1404
				housespec->random_colour[1] = 0x08;  // for all new houses
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1405
				housespec->random_colour[2] = 0x0C;  // they stand for red, blue, orange and green
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1406
				housespec->random_colour[3] = 0x06;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1407
7927
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1408
				/* Make sure that the third cargo type is valid in this
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1409
				 * climate. This can cause problems when copying the properties
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1410
				 * of a house that accepts food, where the new house is valid
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1411
				 * in the temperate climate. */
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1412
				if (!GetCargo(housespec->accepts_cargo[2])->IsValid()) {
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1413
					housespec->cargo_acceptance[2] = 0;
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1414
				}
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1415
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1416
				/**
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1417
				 * New houses do not (currently) expect to have a default start
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1418
				 * date before 1930, as this breaks the build date stuff.
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1419
				 * @see FinaliseHouseArray() for more details.
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1420
				 */
10817
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  1421
				if (housespec->min_year < 1930) housespec->min_year = 1930;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1422
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1423
				_loaded_newgrf_features.has_newhouses = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1424
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1425
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1426
			case 0x09: // Building flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1427
				housespec->building_flags = (BuildingFlags)grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1428
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1429
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1430
			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
  1431
				uint16 years = grf_load_word(&buf);
10817
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  1432
				housespec->min_year = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8);
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  1433
				housespec->max_year = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1434
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1435
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1436
			case 0x0B: // Population
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1437
				housespec->population = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1438
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1439
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1440
			case 0x0C: // Mail generation multiplier
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1441
				housespec->mail_generation = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1442
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1443
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1444
			case 0x0D: // Passenger acceptance
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1445
			case 0x0E: // Mail acceptance
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1446
				housespec->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1447
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1448
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1449
			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
  1450
				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
  1451
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
  1452
				/* 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
  1453
				 * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  1454
				CargoID cid = (goods >= 0) ? ((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) :
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  1455
						((_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
  1456
7927
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1457
				/* Make sure the cargo type is valid in this climate. */
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1458
				if (!GetCargo(cid)->IsValid()) goods = 0;
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1459
21746ebe2ddb (svn r10836) -Fix [FS#1014]: Make sure the third cargo type accepted by houses is valid in
maedhros
parents: 7783
diff changeset
  1460
				housespec->accepts_cargo[2] = cid;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1461
				housespec->cargo_acceptance[2] = abs(goods); // but we do need positive value here
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1462
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1463
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1464
			case 0x10: // Local authority rating decrease on removal
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1465
				housespec->remove_rating_decrease = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1466
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1467
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1468
			case 0x11: // Removal cost multiplier
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1469
				housespec->removal_cost = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1470
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1471
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1472
			case 0x12: // Building name ID
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1473
				housespec->building_name = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1474
				_string_to_grf_mapping[&housespec->building_name] = _cur_grffile->grfid;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1475
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1476
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1477
			case 0x13: // Building availability mask
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1478
				housespec->building_availability = (HouseZones)grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1479
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1480
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1481
			case 0x14: // House callback flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1482
				housespec->callback_mask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1483
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1484
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1485
			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
  1486
				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
  1487
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1488
				/* 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
  1489
				if (override >= NEW_HOUSE_OFFSET) {
7656
bd97032a569a (svn r10434) -Fix (r9315): When setting multiple house overrides in one Action 0, don't override them all with the first ID.
maedhros
parents: 7655
diff changeset
  1490
					grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid + i);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1491
					continue;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1492
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1493
8369
4decac386a96 (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 8327
diff changeset
  1494
				_house_mngr.Add(hid + i, _cur_grffile->grfid, override);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1495
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1496
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1497
			case 0x16: // Periodic refresh multiplier
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1498
				housespec->processing_time = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1499
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1500
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1501
			case 0x17: // Four random colours to use
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1502
				for (uint j = 0; j < 4; j++) housespec->random_colour[j] = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1503
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1504
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1505
			case 0x18: // Relative probability of appearing
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1506
				housespec->probability = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1507
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1508
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1509
			case 0x19: // Extra flags
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1510
				housespec->extra_flags = (HouseExtraFlags)grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1511
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1512
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1513
			case 0x1A: // Animation frames
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1514
				housespec->animation_frames = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1515
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1516
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1517
			case 0x1B: // Animation speed
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8398
diff changeset
  1518
				housespec->animation_speed = Clamp(grf_load_byte(&buf), 2, 16);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1519
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1520
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1521
			case 0x1C: // Class of the building type
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1522
				housespec->class_id = AllocateHouseClassID(grf_load_byte(&buf), _cur_grffile->grfid);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1523
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1524
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1525
			case 0x1D: // Callback flags 2
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1526
				housespec->callback_mask |= (grf_load_byte(&buf) << 8);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1527
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1528
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1529
			case 0x1E: { // Accepted cargo types
6957
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1530
				uint32 cargotypes = grf_load_dword(&buf);
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1531
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1532
				/* Check if the cargo types should not be changed */
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1533
				if (cargotypes == 0xFFFFFFFF) break;
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1534
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1535
				for (uint j = 0; j < 3; j++) {
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1536
					/* Get the cargo number from the 'list' */
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1537
					uint8 cargo_part = GB(cargotypes, 8 * j, 8);
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1538
					CargoID cargo = GetCargoTranslation(cargo_part, _cur_grffile);
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1539
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1540
					if (cargo == CT_INVALID) {
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1541
						/* Disable acceptance of invalid cargo type */
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1542
						housespec->cargo_acceptance[j] = 0;
6957
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1543
					} else {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1544
						housespec->accepts_cargo[j] = cargo;
6957
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1545
					}
55b90cc74f67 (svn r9621) -Codechange: implement newgrf house property 1E (cargo types)
peter1138
parents: 6947
diff changeset
  1546
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1547
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1548
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1549
			case 0x1F: // Minimum life span
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1550
				housespec->minimum_life = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1551
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1552
8287
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
  1553
			case 0x20: { // @todo Cargo acceptance watch list
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
  1554
				byte count = grf_load_byte(&buf);
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
  1555
				for (byte j = 0; j < count; j++) grf_load_byte(&buf);
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
  1556
				ret = true;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
  1557
			} break;
5e43bdaf2d8b (svn r11341) -Codechange: add missing callback ID enums, add stub for house property 20 and reorder unimplemented action 0 properties
glx
parents: 8276
diff changeset
  1558
10886
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1559
			case 0x21: // long introduction year
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1560
				housespec->min_year = grf_load_word(&buf);
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1561
				break;
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1562
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1563
			case 0x22: // long maximum year
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1564
				housespec->max_year = grf_load_word(&buf);
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1565
				break;
5fff9f00e677 (svn r13437) -Feature[newGRF]: Add long format introduction and maximum construction year for house.
belugas
parents: 10839
diff changeset
  1566
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1567
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1568
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1569
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1570
		}
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1571
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1572
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1573
	*bufp = buf;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1574
	return ret;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1575
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  1576
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1577
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
  1578
{
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1579
	byte *buf = *bufp;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1580
	bool ret = false;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1581
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1582
	for (int i = 0; i < numinfo; i++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1583
		switch (prop) {
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1584
			case 0x08: { // Cost base factor
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1585
				byte factor = grf_load_byte(&buf);
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1586
				uint price = gvid + i;
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1587
2508
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1588
				if (price < NUM_PRICES) {
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1589
					SetPriceBaseMultiplier(price, factor);
c1a1af1920ce (svn r3034) -NewGRF: Improve error checking of setting price bases.
peter1138
parents: 2506
diff changeset
  1590
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1591
					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
  1592
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1593
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1594
8974
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  1595
			case 0x09: // Cargo translation table
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  1596
				/* This is loaded during the reservation stage, so just skip it here. */
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  1597
				/* Each entry is 4 bytes. */
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  1598
				buf += 4;
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  1599
				break;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1600
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1601
			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
  1602
				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
  1603
				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
  1604
4504
3d20af4bd525 (svn r6289) -Fix(r6108) : case 0x48 (generic text) should not have been set over newstations.
belugas
parents: 4434
diff changeset
  1605
				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
  1606
					_currency_specs[curidx].name = newone;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1607
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1608
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1609
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1610
			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
  1611
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1612
				uint32 rate = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1613
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1614
				if (curidx < NUM_CURRENCY) {
4602
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1615
					/* 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
  1616
					 * 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
  1617
					 * to be compatible */
36e779efee9a (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4504
diff changeset
  1618
					_currency_specs[curidx].rate = rate / 1000;
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1619
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1620
					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
  1621
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1622
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1623
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1624
			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
  1625
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1626
				uint16 options = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1627
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1628
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1629
					_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
  1630
					/* 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
  1631
					 * 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
  1632
					_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
  1633
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1634
					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
  1635
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1636
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1637
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1638
			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
  1639
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1640
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1641
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1642
				if (curidx < NUM_CURRENCY) {
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1643
					memcpy(_currency_specs[curidx].prefix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1644
					_currency_specs[curidx].prefix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1645
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1646
					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
  1647
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1648
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1649
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1650
			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
  1651
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1652
				uint32 tempfix = grf_load_dword(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1653
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1654
				if (curidx < NUM_CURRENCY) {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
  1655
					memcpy(&_currency_specs[curidx].suffix, &tempfix, 4);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1656
					_currency_specs[curidx].suffix[4] = 0;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1657
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1658
					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
  1659
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1660
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1661
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1662
			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
  1663
				uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1664
				Year year_euro = grf_load_word(&buf);
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1665
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1666
				if (curidx < NUM_CURRENCY) {
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1667
					_currency_specs[curidx].to_euro = year_euro;
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  1668
				} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  1669
					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
  1670
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1671
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1672
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1673
			case 0x10: // Snow line height table
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1674
				if (numinfo > 1 || IsSnowLineSet()) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1675
					grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1676
				} else if (len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1677
					grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (%d)", len);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1678
				} else {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1679
					byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1680
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1681
					for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1682
						for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1683
							table[i][j] = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1684
						}
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  1685
					}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1686
					SetSnowLine(table);
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  1687
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1688
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1689
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1690
			case 0x11: // GRF match for engine allocation
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1691
				/* This is loaded during the reservation stage, so just skip it here. */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1692
				/* Each entry is 8 bytes. */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1693
				buf += 8;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1694
				break;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  1695
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1696
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1697
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1698
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1699
		}
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1700
	}
3504
546b53897c01 (svn r4355) - NewGRF: Minor clean up; use the correct return type and remove extraneous brackets.
peter1138
parents: 3501
diff changeset
  1701
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1702
	*bufp = buf;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1703
	return ret;
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1704
}
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  1705
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1706
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
  1707
{
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1708
	byte *buf = *bufp;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1709
	bool ret = false;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1710
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1711
	if (cid + numinfo > NUM_CARGO) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1712
		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
  1713
		return false;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1714
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1715
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1716
	for (int i = 0; i < numinfo; i++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1717
		CargoSpec *cs = &_cargo[cid + i];
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1718
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1719
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1720
			case 0x08: /* Bit number of cargo */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1721
				cs->bitnum = grf_load_byte(&buf);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1722
				if (cs->IsValid()) {
8214
854acef589c8 (svn r11253) -Fix (r9411): industries can still use cargo they define, even if these cargo are disabled by a grf loaded later
glx
parents: 8213
diff changeset
  1723
					cs->grfid = _cur_grffile->grfid;
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1724
					SetBit(_cargo_mask, cid + i);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1725
				} else {
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  1726
					ClrBit(_cargo_mask, cid + i);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1727
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1728
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1729
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1730
			case 0x09: /* String ID for cargo type name */
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1731
				cs->name = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1732
				_string_to_grf_mapping[&cs->name] = _cur_grffile->grfid;
7772
82b58fd5897c (svn r10606) -Fix (r8826): plural and single cargo names were mixed up.
peter1138
parents: 7736
diff changeset
  1733
				break;
82b58fd5897c (svn r10606) -Fix (r8826): plural and single cargo names were mixed up.
peter1138
parents: 7736
diff changeset
  1734
82b58fd5897c (svn r10606) -Fix (r8826): plural and single cargo names were mixed up.
peter1138
parents: 7736
diff changeset
  1735
			case 0x0A: /* String for 1 unit of cargo */
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1736
				cs->name_single = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1737
				_string_to_grf_mapping[&cs->name_single] = _cur_grffile->grfid;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1738
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1739
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1740
			case 0x0B:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1741
				/* String for units of cargo. This is different in OpenTTD to TTDPatch
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1742
				 * (e.g. 10 tonnes of coal) */
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1743
				cs->units_volume = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1744
				_string_to_grf_mapping[&cs->units_volume] = _cur_grffile->grfid;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1745
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1746
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1747
			case 0x0C: /* String for quantity of cargo (e.g. 10 tonnes of coal) */
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1748
				cs->quantifier = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1749
				_string_to_grf_mapping[&cs->quantifier] = _cur_grffile->grfid;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1750
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1751
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1752
			case 0x0D: /* String for two letter cargo abbreviation */
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1753
				cs->abbrev = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  1754
				_string_to_grf_mapping[&cs->abbrev] = _cur_grffile->grfid;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1755
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1756
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1757
			case 0x0E: /* Sprite ID for cargo icon */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1758
				cs->sprite = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1759
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1760
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1761
			case 0x0F: /* Weight of one unit of cargo */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1762
				cs->weight = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1763
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1764
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1765
			case 0x10: /* Used for payment calculation */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1766
				cs->transit_days[0] = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1767
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1768
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1769
			case 0x11: /* Used for payment calculation */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1770
				cs->transit_days[1] = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1771
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1772
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1773
			case 0x12: /* Base cargo price */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1774
				cs->initial_payment = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1775
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1776
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1777
			case 0x13: /* Colour for station rating bars */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1778
				cs->rating_colour = MapDOSColour(grf_load_byte(&buf));
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1779
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1780
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1781
			case 0x14: /* Colour for cargo graph */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1782
				cs->legend_colour = MapDOSColour(grf_load_byte(&buf));
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1783
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1784
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1785
			case 0x15: /* Freight status */
7658
742319a52186 (svn r10436) -Cleanup: Doxygenise some comments, update others, and make a few statements more consistent with everything else.
maedhros
parents: 7657
diff changeset
  1786
				cs->is_freight = (grf_load_byte(&buf) != 0);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1787
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1788
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1789
			case 0x16: /* Cargo classes */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1790
				cs->classes = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1791
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1792
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1793
			case 0x17: /* Cargo label */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1794
				cs->label = grf_load_dword(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1795
				cs->label = BSWAP32(cs->label);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1796
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1797
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1798
			case 0x18: { /* Town growth substitute type */
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1799
				uint8 substitute_type = grf_load_byte(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1800
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1801
				switch (substitute_type) {
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1802
					case 0x00: cs->town_effect = TE_PASSENGERS; break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1803
					case 0x02: cs->town_effect = TE_MAIL; break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1804
					case 0x05: cs->town_effect = TE_GOODS; break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1805
					case 0x09: cs->town_effect = TE_WATER; break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1806
					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
  1807
					default:
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1808
						grfmsg(1, "CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1809
					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
  1810
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1811
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1812
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1813
			case 0x19: /* Town growth coefficient */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1814
				cs->multipliertowngrowth = grf_load_word(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1815
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1816
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1817
			case 0x1A: /* Bitmask of callbacks to use */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1818
				cs->callback_mask = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1819
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1820
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1821
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1822
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1823
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1824
		}
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1825
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1826
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1827
	*bufp = buf;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1828
	return ret;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1829
}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1830
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  1831
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1832
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
  1833
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1834
	byte *buf = *bufp;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1835
	bool ret = false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1836
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1837
	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
  1838
		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
  1839
		return false;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1840
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1841
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1842
	for (int i = 0; i < numinfo; i++) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1843
		uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1844
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1845
		if (sound >= GetNumSounds()) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1846
			grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1847
			continue;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1848
		}
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1849
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1850
		switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1851
			case 0x08: // Relative volume
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1852
				GetSound(sound)->volume = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1853
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1854
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1855
			case 0x09: // Priority
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1856
				GetSound(sound)->priority = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1857
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1858
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1859
			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
  1860
				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
  1861
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1862
				if (orig_sound >= GetNumSounds()) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1863
					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
  1864
				} else {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1865
					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
  1866
					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
  1867
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1868
					/* 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
  1869
					*oldfe = *newfe;
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1870
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1871
			} break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1872
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1873
			default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1874
				ret = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1875
				break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  1876
		}
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1877
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1878
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1879
	*bufp = buf;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1880
	return ret;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1881
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  1882
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1883
static bool IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, byte **bufp, int len)
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1884
{
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1885
	byte *buf = *bufp;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1886
	bool ret = false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1887
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1888
	if (indtid + numinfo > NUM_INDUSTRYTILES) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1889
		grfmsg(1, "IndustryTilesChangeInfo: Too many industry tiles loaded (%u), max (%u). Ignoring.", indtid + numinfo, NUM_INDUSTRYTILES);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1890
		return false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1891
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1892
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1893
	/* Allocate industry tile specs if they haven't been allocated already. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1894
	if (_cur_grffile->indtspec == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1895
		_cur_grffile->indtspec = CallocT<IndustryTileSpec*>(NUM_INDUSTRYTILES);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1896
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1897
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1898
	for (int i = 0; i < numinfo; i++) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1899
		IndustryTileSpec *tsp = _cur_grffile->indtspec[indtid + i];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1900
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1901
		if (prop != 0x08 && tsp == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1902
			grfmsg(2, "IndustryTilesChangeInfo: Attempt to modify undefined industry tile %u. Ignoring.", indtid + i);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1903
			continue;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1904
		}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1905
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1906
		switch (prop) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1907
			case 0x08: { // Substitute industry tile type
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1908
				IndustryTileSpec **tilespec = &_cur_grffile->indtspec[indtid + i];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1909
				byte subs_id = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1910
7955
7a2abd093498 (svn r10955) -Fix: The substitute prop (0x08) of industry tiles does not behave as prop 0x08 of industry. Therefore, do not disable the old industry with value of 0xFF. Not a bug fix, just a spec compliance correction...
belugas
parents: 7927
diff changeset
  1911
				if (subs_id >= NEW_INDUSTRYTILEOFFSET) {
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1912
					/* The substitute id must be one of the original industry tile. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1913
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1914
					return false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1915
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1916
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1917
				/* Allocate space for this industry. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1918
				if (*tilespec == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1919
					int tempid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1920
					*tilespec = CallocT<IndustryTileSpec>(1);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1921
					tsp = *tilespec;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1922
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1923
					memcpy(tsp, &_industry_tile_specs[subs_id], sizeof(_industry_tile_specs[subs_id]));
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1924
					tsp->enabled = true;
8600
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1925
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1926
					/* A copied tile should not have the animation infos copied too.
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1927
					 * The anim_state should be left untouched, though
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1928
					 * It is up to the author to animate them himself */
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1929
					tsp->anim_production = INDUSTRYTILE_NOANIM;
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1930
					tsp->anim_next = INDUSTRYTILE_NOANIM;
bb089962319d (svn r11665) -Fix: Animation informations should not be copied from original industry tile spec, while doing an action 00, industry tile, prop 08.
belugas
parents: 8599
diff changeset
  1931
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1932
					tsp->grf_prop.local_id = indtid + i;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1933
					tsp->grf_prop.subst_id = subs_id;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1934
					tsp->grf_prop.grffile = _cur_grffile;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1935
					tempid = _industile_mngr.AddEntityID(indtid + i, _cur_grffile->grfid, subs_id); // pre-reserve the tile slot
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1936
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1937
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1938
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1939
			case 0x09: { // Industry tile override
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1940
				byte ovrid = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1941
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1942
				/* The industry being overridden must be an original industry. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1943
				if (ovrid >= NEW_INDUSTRYTILEOFFSET) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1944
					grfmsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1945
					return false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1946
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1947
8369
4decac386a96 (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 8327
diff changeset
  1948
				_industile_mngr.Add(indtid + i, _cur_grffile->grfid, ovrid);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1949
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1950
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1951
			case 0x0A: // Tile acceptance
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1952
			case 0x0B:
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1953
			case 0x0C: {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1954
				uint16 acctp = grf_load_word(&buf);
8484
962c66e1cd50 (svn r11544) -Fix [FS#1501]: revert r11453 as it translated cargo when it should not
glx
parents: 8474
diff changeset
  1955
				tsp->accepts_cargo[prop - 0x0A] = GetCargoTranslation(GB(acctp, 0, 8), _cur_grffile);
8127
0cbf1d4a5f6d (svn r11162) -Fix: Acceptance is not a cargo, but rather a level of... acceptance :) So don't need to get cargo name out of it (glx)
belugas
parents: 8126
diff changeset
  1956
				tsp->acceptance[prop - 0x0A] = GB(acctp, 8, 8);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1957
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1958
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1959
			case 0x0D: // Land shape flags
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1960
				tsp->slopes_refused = (Slope)grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1961
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1962
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1963
			case 0x0E: // Callback flags
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1964
				tsp->callback_flags = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1965
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1966
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1967
			case 0x0F: // Animation information
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7713
diff changeset
  1968
				tsp->animation_info = grf_load_word(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1969
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1970
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1971
			case 0x10: // Animation speed
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7713
diff changeset
  1972
				tsp->animation_speed = grf_load_byte(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1973
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1974
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1975
			case 0x11: // Triggers for callback 25
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7713
diff changeset
  1976
				tsp->animation_triggers = grf_load_byte(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1977
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1978
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1979
			case 0x12: // Special flags
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7713
diff changeset
  1980
				tsp->animation_special_flags = grf_load_byte(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1981
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1982
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1983
			default:
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1984
				ret = true;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1985
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1986
		}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1987
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1988
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1989
	*bufp = buf;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1990
	return ret;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1991
}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1992
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1993
static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1994
{
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1995
	byte *buf = *bufp;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1996
	bool ret = false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1997
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1998
	if (indid + numinfo > NUM_INDUSTRYTYPES) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  1999
		grfmsg(1, "IndustriesChangeInfo: Too many industries loaded (%u), max (%u). Ignoring.", indid + numinfo, NUM_INDUSTRYTYPES);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2000
		return false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2001
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2002
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2003
	grfmsg(1, "IndustriesChangeInfo: newid %u", indid);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2004
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2005
	/* Allocate industry specs if they haven't been allocated already. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2006
	if (_cur_grffile->industryspec == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2007
		_cur_grffile->industryspec = CallocT<IndustrySpec*>(NUM_INDUSTRYTYPES);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2008
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2009
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2010
	for (int i = 0; i < numinfo; i++) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2011
		IndustrySpec *indsp = _cur_grffile->industryspec[indid + i];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2012
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2013
		if (prop != 0x08 && indsp == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2014
			grfmsg(2, "IndustriesChangeInfo: Attempt to modify undefined industry %u. Ignoring.", indid + i);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2015
			continue;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2016
		}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2017
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2018
		switch (prop) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2019
			case 0x08: { // Substitute industry type
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2020
				IndustrySpec **indspec = &_cur_grffile->industryspec[indid + i];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2021
				byte subs_id = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2022
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2023
				if (subs_id == 0xFF) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2024
					/* Instead of defining a new industry, a substitute industry id
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2025
					 * of 0xFF disables the old industry with the current id. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2026
					_industry_specs[indid + i].enabled = false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2027
					continue;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2028
				} else if (subs_id >= NEW_INDUSTRYOFFSET) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2029
					/* The substitute id must be one of the original industry. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2030
					grfmsg(2, "_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2031
					return false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2032
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2033
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2034
				/* Allocate space for this industry.
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2035
				 * Only need to do it once. If ever it is called again, it should not
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2036
				 * do anything */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2037
				if (*indspec == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2038
					*indspec = CallocT<IndustrySpec>(1);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2039
					indsp = *indspec;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2040
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2041
					memcpy(indsp, &_origin_industry_specs[subs_id], sizeof(_industry_specs[subs_id]));
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2042
					indsp->enabled = true;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2043
					indsp->grf_prop.local_id = indid + i;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2044
					indsp->grf_prop.subst_id = subs_id;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2045
					indsp->grf_prop.grffile = _cur_grffile;
8212
4a6936f108a3 (svn r11251) -Fix[FS#1318]: Newindustries must not rely on the old check placement functions. It is the the job of callbacks. Therefor, upon substitution, disable the said check.
belugas
parents: 8201
diff changeset
  2046
					/* If the grf industry needs to check its surounding upon creation, it should
4a6936f108a3 (svn r11251) -Fix[FS#1318]: Newindustries must not rely on the old check placement functions. It is the the job of callbacks. Therefor, upon substitution, disable the said check.
belugas
parents: 8201
diff changeset
  2047
					 * rely on callbacks, not on the original placement functions */
4a6936f108a3 (svn r11251) -Fix[FS#1318]: Newindustries must not rely on the old check placement functions. It is the the job of callbacks. Therefor, upon substitution, disable the said check.
belugas
parents: 8201
diff changeset
  2048
					indsp->check_proc = CHECK_NOTHING;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2049
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2050
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2051
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2052
			case 0x09: { // Industry type override
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2053
				byte ovrid = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2054
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2055
				/* The industry being overridden must be an original industry. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2056
				if (ovrid >= NEW_INDUSTRYOFFSET) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2057
					grfmsg(2, "IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2058
					return false;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2059
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2060
				indsp->grf_prop.override = ovrid;
8369
4decac386a96 (svn r11423) -Codechange: store grfid when adding an override
glx
parents: 8327
diff changeset
  2061
				_industry_mngr.Add(indid + i, _cur_grffile->grfid, ovrid);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2062
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2063
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2064
			case 0x0A: { // Set industry layout(s)
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2065
				indsp->num_table = grf_load_byte(&buf); // Number of layaouts
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2066
				uint32 defsize = grf_load_dword(&buf);  // Total size of the definition
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2067
				IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2068
				IndustryTileTable *itt = CallocT<IndustryTileTable>(defsize); // Temporary array to read the tile layouts from the GRF
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2069
				int size;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2070
				IndustryTileTable *copy_from;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2071
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2072
				for (byte j = 0; j < indsp->num_table; j++) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2073
					for (int k = 0;; k++) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2074
						itt[k].ti.x = grf_load_byte(&buf); // Offsets from northermost tile
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2075
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2076
						if (itt[k].ti.x == 0xFE && k == 0) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2077
							/* This means we have to borrow the layout from an old industry */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2078
							IndustryType type = grf_load_byte(&buf);  //industry holding required layout
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2079
							byte laynbr = grf_load_byte(&buf);        //layout number to borrow
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2080
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2081
							copy_from = (IndustryTileTable*)_origin_industry_specs[type].table[laynbr];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2082
							for (size = 1;; size++) {
8242
5178a27b2275 (svn r11283) -Fix(r11282): a typo. Don't ask.
belugas
parents: 8241
diff changeset
  2083
								if (copy_from[size - 1].ti.x == -0x80 && copy_from[size - 1].ti.y == 0) break;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2084
							}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2085
							break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2086
						}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2087
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2088
						itt[k].ti.y = grf_load_byte(&buf); // Or table definition finalisation
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2089
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2090
						if (itt[k].ti.x == 0 && itt[k].ti.y == 0x80) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2091
							/*  Not the same terminator.  The one we are using is rather
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2092
							 x= -80, y = x .  So, adjust it. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2093
							itt[k].ti.x = -0x80;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2094
							itt[k].ti.y =  0;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2095
							itt[k].gfx  =  0;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2096
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2097
							size = k + 1;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2098
							copy_from = itt;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2099
							break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2100
						}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2101
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2102
						itt[k].gfx = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2103
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2104
						if (itt[k].gfx == 0xFE) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2105
							/* Use a new tile from this GRF */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2106
							int local_tile_id = grf_load_word(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2107
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2108
							/* Read the ID from the _industile_mngr. */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2109
							int tempid = _industile_mngr.GetID(local_tile_id, _cur_grffile->grfid);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2110
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2111
							if (tempid == INVALID_INDUSTRYTILE) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2112
								grfmsg(2, "IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2113
							} else {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2114
								/* Declared as been valid, can be used */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2115
								itt[k].gfx = tempid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2116
								size = k + 1;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2117
								copy_from = itt;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2118
							}
8126
ff006fa6d1ab (svn r11161) -Fix: Allow to transform coordinates in negative ones when gfx of 0xFF allows it
belugas
parents: 8116
diff changeset
  2119
						} else if (itt[k].gfx == 0xFF) {
ff006fa6d1ab (svn r11161) -Fix: Allow to transform coordinates in negative ones when gfx of 0xFF allows it
belugas
parents: 8116
diff changeset
  2120
							itt[k].ti.x = (int8)GB(itt[k].ti.x, 0, 8);
ff006fa6d1ab (svn r11161) -Fix: Allow to transform coordinates in negative ones when gfx of 0xFF allows it
belugas
parents: 8116
diff changeset
  2121
							itt[k].ti.y = (int8)GB(itt[k].ti.y, 0, 8);
8129
7d673f9710c2 (svn r11164) -Fix(r11161): a rogue space roaming in the night... removed
belugas
parents: 8127
diff changeset
  2122
						}
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2123
					}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2124
					tile_table[j] = CallocT<IndustryTileTable>(size);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2125
					memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2126
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2127
				/* Install final layout construction in the industry spec */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2128
				indsp->table = tile_table;
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2129
				SetBit(indsp->cleanup_flag, 1);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2130
				free(itt);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2131
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2132
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2133
			case 0x0B: // Industry production flags
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2134
				indsp->life_type = (IndustryLifeType)grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2135
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2136
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2137
			case 0x0C: // Industry closure message
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2138
				indsp->closure_text = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2139
				_string_to_grf_mapping[&indsp->closure_text] = _cur_grffile->grfid;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2140
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2141
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2142
			case 0x0D: // Production increase message
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2143
				indsp->production_up_text = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2144
				_string_to_grf_mapping[&indsp->production_up_text] = _cur_grffile->grfid;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2145
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2146
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2147
			case 0x0E: // Production decrease message
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2148
				indsp->production_down_text = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2149
				_string_to_grf_mapping[&indsp->production_down_text] = _cur_grffile->grfid;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2150
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2151
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2152
			case 0x0F: // Fund cost multiplier
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2153
				indsp->cost_multiplier = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2154
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2155
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2156
			case 0x10: // Production cargo types
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2157
				for (byte j = 0; j < 2; j++) {
8484
962c66e1cd50 (svn r11544) -Fix [FS#1501]: revert r11453 as it translated cargo when it should not
glx
parents: 8474
diff changeset
  2158
					indsp->produced_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2159
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2160
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2161
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2162
			case 0x11: // Acceptance cargo types
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2163
				for (byte j = 0; j < 3; j++) {
8484
962c66e1cd50 (svn r11544) -Fix [FS#1501]: revert r11453 as it translated cargo when it should not
glx
parents: 8474
diff changeset
  2164
					indsp->accepts_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2165
				}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2166
				grf_load_byte(&buf); // Unnused, eat it up
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2167
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2168
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2169
			case 0x12: // Production multipliers
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2170
			case 0x13:
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2171
				indsp->production_rate[prop - 0x12] = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2172
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2173
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2174
			case 0x14: // Minimal amount of cargo distributed
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2175
				indsp->minimal_cargo = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2176
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2177
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2178
			case 0x15: { // Random sound effects
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2179
				indsp->number_of_sounds = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2180
				uint8 *sounds = MallocT<uint8>(indsp->number_of_sounds);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2181
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2182
				for (uint8 j = 0; j < indsp->number_of_sounds; j++) sounds[j] = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2183
				indsp->random_sounds = sounds;
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2184
				SetBit(indsp->cleanup_flag, 0);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2185
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2186
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2187
			case 0x16: // Conflicting industry types
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2188
				for (byte j = 0; j < 3; j++) indsp->conflicting[j] = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2189
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2190
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2191
			case 0x17: // Probability in random game
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  2192
				indsp->appear_creation[_settings_game.game_creation.landscape] = grf_load_byte(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2193
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2194
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2195
			case 0x18: // Probability during gameplay
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  2196
				indsp->appear_ingame[_settings_game.game_creation.landscape] = grf_load_byte(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2197
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2198
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2199
			case 0x19: // Map color
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2200
				indsp->map_colour = MapDOSColour(grf_load_byte(&buf));
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2201
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2202
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2203
			case 0x1A: // Special industry flags to define special behavior
8253
07efd7789987 (svn r11302) -Fix (r9520): typo
glx
parents: 8242
diff changeset
  2204
				indsp->behaviour = (IndustryBehaviour)grf_load_dword(&buf);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2205
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2206
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2207
			case 0x1B: // New industry text ID
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2208
				indsp->new_industry_text = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2209
				_string_to_grf_mapping[&indsp->new_industry_text] = _cur_grffile->grfid;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2210
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2211
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2212
			case 0x1C: // Input cargo multipliers for the three input cargo types
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2213
			case 0x1D:
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2214
			case 0x1E: {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2215
					uint32 multiples = grf_load_dword(&buf);
10229
fba3f9fa44d7 (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 10219
diff changeset
  2216
					indsp->input_cargo_multiplier[prop - 0x1C][0] = GB(multiples, 0, 15);
fba3f9fa44d7 (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 10219
diff changeset
  2217
					indsp->input_cargo_multiplier[prop - 0x1C][1] = GB(multiples, 15, 15);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2218
				} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2219
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2220
			case 0x1F: // Industry name
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2221
				indsp->name = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2222
				_string_to_grf_mapping[&indsp->name] = _cur_grffile->grfid;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2223
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2224
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2225
			case 0x20: // Prospecting success chance
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2226
				indsp->prospecting_chance = grf_load_dword(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2227
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2228
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2229
			case 0x21:   // Callback flags
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2230
			case 0x22: { // Callback additional flags
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2231
				byte aflag = grf_load_byte(&buf);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2232
				SB(indsp->callback_flags, (prop - 0x21) * 8, 8, aflag);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2233
			} break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2234
8474
358b35762f02 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 8450
diff changeset
  2235
			case 0x23: // removal cost multiplier
358b35762f02 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 8450
diff changeset
  2236
				indsp->removal_cost_multiplier = grf_load_dword(&buf);
358b35762f02 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 8450
diff changeset
  2237
				break;
358b35762f02 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 8450
diff changeset
  2238
8966
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  2239
			case 0x24: // name for nearby station
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2240
				indsp->station_name = grf_load_word(&buf);
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  2241
				_string_to_grf_mapping[&indsp->station_name] = _cur_grffile->grfid;
8966
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  2242
				break;
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  2243
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2244
			default:
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2245
				ret = true;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2246
				break;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2247
		}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2248
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2249
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2250
	*bufp = buf;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2251
	return ret;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2252
}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2253
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2254
/* Action 0x00 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  2255
static void FeatureChangeInfo(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
	byte *bufend = buf + len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2259
	/* <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
  2260
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2261
	 * 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
  2262
	 *                 4 for defining new train station sets
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2263
	 * 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
  2264
	 * B num-info      how many vehicles/stations to change
8388
d11398135687 (svn r11443) -Fix: [NewGRF] Action 0 <id> is an extended byte
glx
parents: 8378
diff changeset
  2265
	 * 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
  2266
	 *                 greater than one, this one and the following
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2267
	 *                 vehicles/stations will be changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2268
	 * 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
  2269
	 * 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
  2270
	/* TODO: Bridges, town houses. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2271
2438
eaef2b29fa3d (svn r2964) Fix: newgrf: Include missing grf feature canal.
peter1138
parents: 2421
diff changeset
  2272
	static const VCI_Handler handler[] = {
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2273
		/* GSF_TRAIN */        RailVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2274
		/* GSF_ROAD */         RoadVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2275
		/* GSF_SHIP */         ShipVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2276
		/* GSF_AIRCRAFT */     AircraftVehicleChangeInfo,
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2277
		/* GSF_STATION */      StationChangeInfo,
8868
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  2278
		/* GSF_CANAL */        CanalChangeInfo,
3825
c4c69a0ca625 (svn r4838) Newgrf : Add empty base for newcargos
belugas
parents: 3821
diff changeset
  2279
		/* GSF_BRIDGE */       BridgeChangeInfo,
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2280
		/* GSF_TOWNHOUSE */    TownHouseChangeInfo,
8974
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2281
		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2282
		/* GSF_INDUSTRYTILES */IndustrytilesChangeInfo,
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  2283
		/* GSF_INDUSTRIES */   IndustriesChangeInfo,
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2284
		/* 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
  2285
		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2286
	};
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  2287
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
  2288
	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
  2289
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2290
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2291
	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
  2292
	uint numinfo  = grf_load_byte(&buf);
8388
d11398135687 (svn r11443) -Fix: [NewGRF] Action 0 <id> is an extended byte
glx
parents: 8378
diff changeset
  2293
	uint engine   = grf_load_extended(&buf);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2294
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2295
	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
  2296
	               feature, numprops, engine, numinfo);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 373
diff changeset
  2297
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
  2298
	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
  2299
		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
  2300
		return;
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2301
	}
573193308396 (svn r583) -newgrf: Hopefully prevent GRF files introducing new bridges or townhouses to crash the game (pasky).
darkvater
parents: 389
diff changeset
  2302
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2303
	while (numprops-- && buf < bufend) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2304
		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
  2305
		bool ignoring = false;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2306
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2307
		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
  2308
			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
  2309
			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
  2310
			case GSF_SHIP:
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2311
			case GSF_AIRCRAFT: {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2312
				bool handled = true;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2313
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2314
				for (uint i = 0; i < numinfo; i++) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2315
					Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, engine + i);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2316
					EngineInfo *ei = &e->info;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2317
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2318
					/* Common properties for vehicles */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2319
					switch (prop) {
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2320
						case 0x00: // Introduction date
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2321
							ei->base_intro = grf_load_word(&buf) + DAYS_TILL_ORIGINAL_BASE_YEAR;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2322
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2323
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2324
						case 0x02: // Decay speed
10837
90f01f8fd55d (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 10825
diff changeset
  2325
							ei->decay_speed = grf_load_byte(&buf);
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2326
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2327
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2328
						case 0x03: // Vehicle life
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2329
							ei->lifelength = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2330
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2331
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2332
						case 0x04: // Model life
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2333
							ei->base_life = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2334
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2335
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2336
						case 0x06: // Climates available
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2337
							ei->climates = grf_load_byte(&buf);
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2338
							// XXX sometimes a grf wants hidden vehicles :o
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2339
							if (ei->climates == 0) ei->climates = 0x80;
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2340
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2341
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2342
						case 0x07: // Loading speed
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2343
							/* Hyronymus explained me what does
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2344
							 * this mean and insists on having a
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2345
							 * credit ;-). --pasky */
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2346
							ei->load_amount = grf_load_byte(&buf);
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2347
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2348
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2349
						default:
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2350
							handled = false;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2351
							break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2352
					}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2353
				}
7655
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2354
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2355
				if (handled) break;
8d1e8833ce28 (svn r10433) -Codechange: Remove FOR_EACH_OBJECT by moving the for loops in the Action 0
maedhros
parents: 7530
diff changeset
  2356
			} /* 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
  2357
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2358
			default:
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2359
				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
  2360
					ignoring = true;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2361
				}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2362
				break;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2363
		}
2421
7b6750d797bd (svn r2947) Reorder some code to prepare for future enhancements and get rid of some gotos (peter1138)
tron
parents: 2400
diff changeset
  2364
8570
3312a80e0ebd (svn r11635) -Codechange: Give a more informative debug message when encountering unknown newgrf feature in action 00 handling.(FS#1551, Bilbo)
belugas
parents: 8536
diff changeset
  2365
		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
  2366
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2367
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2368
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
  2369
/* Action 0x00 (GLS_SAFETYSCAN) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  2370
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
  2371
{
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
  2372
	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
  2373
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2374
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2375
	uint8 numprops = grf_load_byte(&buf);
8388
d11398135687 (svn r11443) -Fix: [NewGRF] Action 0 <id> is an extended byte
glx
parents: 8378
diff changeset
  2376
	grf_load_byte(&buf);     // num-info
d11398135687 (svn r11443) -Fix: [NewGRF] Action 0 <id> is an extended byte
glx
parents: 8378
diff changeset
  2377
	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
  2378
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
  2379
	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
  2380
		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
  2381
		/* 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
  2382
		 * 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
  2383
		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
  2384
	}
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
  2385
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2386
	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
  2387
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
  2388
	/* 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
  2389
	_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
  2390
}
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
  2391
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2392
/* Action 0x00 (GLS_RESERVE) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  2393
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
  2394
{
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2395
	byte *bufend = buf + len;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2396
8974
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2397
	if (!check_length(len, 6, "ReserveChangeInfo")) return;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2398
	buf++;
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2399
	uint8 feature  = grf_load_byte(&buf);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2400
8437
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2401
	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
  2402
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2403
	uint8 numprops = grf_load_byte(&buf);
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2404
	uint8 numinfo  = grf_load_byte(&buf);
8388
d11398135687 (svn r11443) -Fix: [NewGRF] Action 0 <id> is an extended byte
glx
parents: 8378
diff changeset
  2405
	uint8 index    = grf_load_extended(&buf);
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2406
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2407
	while (numprops-- && buf < bufend) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2408
		uint8 prop = grf_load_byte(&buf);
8437
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2409
		bool ignoring = false;
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2410
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2411
		switch (feature) {
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2412
			default: NOT_REACHED();
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2413
			case GSF_CARGOS:
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2414
				ignoring = CargoChangeInfo(index, numinfo, prop, &buf, bufend - buf);
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2415
				break;
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2416
			case GSF_GLOBALVAR:
8974
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2417
				switch (prop) {
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2418
					case 0x09: // Cargo Translation Table
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2419
						if (index != 0) {
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2420
							grfmsg(1, "ReserveChangeInfo: Cargo translation table must start at zero");
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2421
							return;
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2422
						}
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2423
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2424
						free(_cur_grffile->cargo_list);
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2425
						_cur_grffile->cargo_max = numinfo;
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2426
						_cur_grffile->cargo_list = MallocT<CargoLabel>(numinfo);
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2427
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2428
						for (uint i = 0; i < numinfo; i++) {
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2429
							CargoLabel cl = grf_load_dword(&buf);
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2430
							_cur_grffile->cargo_list[i] = BSWAP32(cl);
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2431
						}
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2432
						break;
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2433
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2434
					case 0x11: // GRF match for engine allocation
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2435
						for (uint i = 0; i < numinfo; i++) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2436
							uint32 s = grf_load_dword(&buf);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2437
							uint32 t = grf_load_dword(&buf);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2438
							SetNewGRFOverride(s, t);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2439
						}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  2440
						break;
8974
2d3cc23e12ce (svn r12052) -Fix [FS#1737] (r11494): The cargo translation table was loaded at the right time, but all the other global variables were now loaded too early. ;)
maedhros
parents: 8966
diff changeset
  2441
				}
8437
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2442
				break;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2443
		}
8437
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2444
10c4010055a9 (svn r11494) -Fix [FS#1461] (r11450): cargo translation table was now loaded too late ;)
glx
parents: 8427
diff changeset
  2445
		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
  2446
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2447
}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  2448
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2449
/**
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2450
 * Creates a spritegroup representing a callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2451
 * @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
  2452
 * @return A spritegroup representing that callback result
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2453
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2454
static const SpriteGroup* NewCallBackResultSpriteGroup(uint16 value)
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2455
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2456
	SpriteGroup *group = AllocateSpriteGroup();
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2457
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2458
	group->type = SGT_CALLBACK;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2459
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  2460
	/* 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
  2461
	 * 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
  2462
	if ((value >> 8) == 0xFF) {
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2463
		value &= ~0xFF00;
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2464
	} else {
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2465
		value &= ~0x8000;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  2466
	}
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2467
2488
cbe3d6b60c27 (svn r3014) -NewGRF, Codechange: Make all sprite group references be pointers instead of copying the data around.
peter1138
parents: 2480
diff changeset
  2468
	group->g.callback.result = value;
1883
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2469
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2470
	return group;
3b02000cfbe0 (svn r2389) - Feature: [newgrf] Implement the mechanism for handling newgrf callbacks.
hackykid
parents: 1873
diff changeset
  2471
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2472
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
  2473
/**
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
  2474
 * Creates a spritegroup representing a sprite number result.
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6975
diff changeset
  2475
 * @param sprite The sprite number.
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6975
diff changeset
  2476
 * @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
  2477
 * @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
  2478
 */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2479
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
  2480
{
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  2481
	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
  2482
	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
  2483
	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
  2484
	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
  2485
	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
  2486
}
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
  2487
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2488
/* Action 0x01 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  2489
static void NewSpriteSet(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2490
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2491
	/* <01> <feature> <num-sets> <num-ent>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2492
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2493
	 * B feature       feature to define sprites for
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2494
	 *                 0, 1, 2, 3: veh-type, 4: train stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2495
	 * B num-sets      number of sprite sets
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2496
	 * 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
  2497
	 *                 For vehicles, this is the number of different
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2498
	 *                         vehicle directions in each sprite set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2499
	 *                         Set num-dirs=8, unless your sprites are symmetric.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2500
	 *                         In that case, use num-dirs=4.
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2501
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2502
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
  2503
	if (!check_length(len, 4, "NewSpriteSet")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  2504
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2505
	uint8 feature   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2506
	uint8 num_sets  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2507
	uint16 num_ents = grf_load_extended(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2508
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
  2509
	_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
  2510
	_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
  2511
	_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
  2512
	_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
  2513
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2514
	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
  2515
		_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
  2516
	);
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  2517
8778
787d7fe77e9c (svn r11846) -Fix [FS#1651]: implicit conversion from unsigned to signed int caused compilation failure with MSVC.
peter1138
parents: 8766
diff changeset
  2518
	for (int i = 0; i < num_sets * num_ents; i++) {
8449
c5759019cbcd (svn r11509) -Fix: off-by-one error in some sprite numbers; increase sprite number counter before loading the next sprite instead of after doing so.
rubidium
parents: 8437
diff changeset
  2519
		_nfo_line++;
7404
fc0559157f16 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 7390
diff changeset
  2520
		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
  2521
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2522
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2523
7072
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2524
/* Action 0x01 (SKIP) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  2525
static void SkipAct1(byte *buf, size_t len)
7072
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2526
{
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2527
	if (!check_length(len, 4, "SkipAct1")) return;
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2528
	buf++;
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2529
	grf_load_byte(&buf);
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2530
	uint8 num_sets  = grf_load_byte(&buf);
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2531
	uint16 num_ents = grf_load_extended(&buf);
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2532
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2533
	_skip_sprites = num_sets * num_ents;
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2534
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2535
	grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites);
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2536
}
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  2537
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
  2538
/* 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
  2539
 * defined spritegroup. */
4893
07d158194395 (svn r6837) - Codechange: More const SpriteGroups missed in r6836
peter1138
parents: 4869
diff changeset
  2540
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
  2541
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2542
	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
  2543
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
  2544
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2545
		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
  2546
		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
  2547
	}
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
  2548
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
  2549
	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
  2550
}
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
  2551
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
  2552
/* 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
  2553
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
  2554
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2555
	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
  2556
3667
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2557
	if (spriteid >= _cur_grffile->spriteset_numsets) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2558
		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
  2559
		return NULL;
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2560
	}
f87c17c36375 (svn r4582) - NewGRF: include an additional check to see if a spriteset id is within range.
peter1138
parents: 3666
diff changeset
  2561
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
  2562
	/* 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
  2563
	 * 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
  2564
	 * 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
  2565
	if (_cur_grffile->spriteset_start + spriteid * num_sprites + num_sprites > _cur_spriteid) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2566
		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
  2567
				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
  2568
				_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
  2569
				_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
  2570
		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
  2571
	}
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
  2572
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2573
	if (feature != _cur_grffile->spriteset_feature) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2574
		grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping",
7381
bdc89f7887a1 (svn r10128) -Fix (r4811): missing printf parameters in newgrf debug message
peter1138
parents: 7369
diff changeset
  2575
				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
  2576
				_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
  2577
		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
  2578
	}
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2579
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
  2580
	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
  2581
}
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
  2582
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  2583
/* Action 0x02 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  2584
static void NewSpriteGroup(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2585
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2586
	/* <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
  2587
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2588
	 * B feature       see action 1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2589
	 * B set-id        ID of this particular definition
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2590
	 * B type/num-entries
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2591
	 *                 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
  2592
	 *                 list definition, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2593
	 *                 otherwise it specifies a number of entries, the exact
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2594
	 *                 meaning depends on the feature
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2595
	 * 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
  2596
	SpriteGroup *group = NULL;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2597
	byte *bufend = buf + len;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 74
diff changeset
  2598
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
  2599
	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
  2600
	buf++;
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2601
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2602
	uint8 feature = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2603
	uint8 setid   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2604
	uint8 type    = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2605
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
  2606
	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
  2607
		/* 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
  2608
		_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
  2609
		/* 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
  2610
		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
  2611
			_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
  2612
	}
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
  2613
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2614
	switch (type) {
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2615
		/* Deterministic Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2616
		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
  2617
		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
  2618
		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
  2619
		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
  2620
		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
  2621
		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
  2622
		{
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
  2623
			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
  2624
			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
  2625
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2626
			/* 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
  2627
			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
  2628
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2629
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2630
			group->type = SGT_DETERMINISTIC;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2631
			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
  2632
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2633
			switch (GB(type, 2, 2)) {
3672
73caf2e829f8 (svn r4588) - NewGRF: silence a false compiler warning
peter1138
parents: 3668
diff changeset
  2634
				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
  2635
				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
  2636
				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
  2637
				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
  2638
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2639
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
  2640
			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
  2641
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2642
			/* 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
  2643
			 * 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
  2644
			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
  2645
				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
  2646
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2647
				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
  2648
					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
  2649
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2650
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2651
				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
  2652
				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
  2653
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2654
				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
  2655
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2656
				/* 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
  2657
				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
  2658
				adjust->variable  = grf_load_byte(&buf);
5868
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2659
				if (adjust->variable == 0x7E) {
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2660
					/* Link subroutine group */
baa704b6dc4f (svn r8075) -Feature: Add support for variable 7E - subroutines. (peter1138)
maedhros
parents: 5860
diff changeset
  2661
					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
  2662
				} else {
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8449
diff changeset
  2663
					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
  2664
				}
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
  2665
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2666
				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
  2667
				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
  2668
				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
  2669
				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
  2670
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2671
				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
  2672
					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
  2673
					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
  2674
				} 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
  2675
					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
  2676
					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
  2677
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2678
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2679
				/* Continue reading var adjusts while bit 5 is set. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2680
			} 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
  2681
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2682
			group->g.determ.num_ranges = grf_load_byte(&buf);
7155
d7f32c08076b (svn r9890) -Codechange: Don't allocate space for 0 spriteset ranges
peter1138
parents: 7148
diff changeset
  2683
			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
  2684
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
  2685
			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
  2686
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2687
			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
  2688
				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
  2689
				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
  2690
				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
  2691
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2692
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
  2693
			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
  2694
			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
  2695
		}
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
  2696
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2697
		/* Randomized Sprite Group */
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2698
		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
  2699
		case 0x83: // Parent scope
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9250
diff changeset
  2700
		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
  2701
		{
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9250
diff changeset
  2702
			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
  2703
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2704
			group = AllocateSpriteGroup();
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2705
			group->type = SGT_RANDOMIZED;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2706
			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
  2707
9254
7190535588ee (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents: 9252
diff changeset
  2708
			if (HasBit(type, 2)) {
7190535588ee (svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)
glx
parents: 9252
diff changeset
  2709
				if (feature <= GSF_AIRCRAFT) group->g.random.var_scope = VSG_SCOPE_RELATIVE;
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9250
diff changeset
  2710
				group->g.random.count = grf_load_byte(&buf);
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9250
diff changeset
  2711
			}
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9250
diff changeset
  2712
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2713
			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
  2714
			group->g.random.triggers       = GB(triggers, 0, 7);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2715
			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
  2716
			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
  2717
			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
  2718
			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
  2719
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
  2720
			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
  2721
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2722
			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
  2723
				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
  2724
			}
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2725
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2726
			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
  2727
		}
3633
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2728
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
  2729
		/* 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
  2730
		default:
414a50db1ac3 (svn r4537) - NewGRF: replace if cascade with a switch block in the sprite group loader
peter1138
parents: 3630
diff changeset
  2731
		{
3803
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2732
1bd124196372 (svn r4811) - NewGRF: only check a sprite set's feature when assigning a sprite result sprite group.
peter1138
parents: 3785
diff changeset
  2733
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
  2734
			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
  2735
				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
  2736
				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
  2737
				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
  2738
				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
  2739
				case GSF_STATION:
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  2740
				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
  2741
				case GSF_CARGOS:
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
  2742
				{
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2743
					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
  2744
					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
  2745
					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
  2746
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2747
					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
  2748
						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
  2749
						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
  2750
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2751
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
  2752
					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
  2753
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2754
					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
  2755
					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
  2756
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2757
					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
  2758
					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
  2759
					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
  2760
					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
  2761
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  2762
					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
  2763
							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
  2764
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2765
					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
  2766
						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
  2767
						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
  2768
						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
  2769
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2770
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2771
					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
  2772
						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
  2773
						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
  2774
						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
  2775
					}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2776
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2777
					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
  2778
				}
d7ed0a867b49 (svn r4583) - NewGRF: Revamp sprite group loading to support advanced varadjusts and variable size. These are not yet processed, however.
peter1138
parents: 3667
diff changeset
  2779
7670
a37783587593 (svn r10448) -Codechange: Industry Tiles and Houses share almost the same spritegroup format.
belugas
parents: 7664
diff changeset
  2780
				case GSF_TOWNHOUSE:
a37783587593 (svn r10448) -Codechange: Industry Tiles and Houses share almost the same spritegroup format.
belugas
parents: 7664
diff changeset
  2781
				case GSF_INDUSTRYTILES: {
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2782
					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
  2783
					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
  2784
					uint i;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2785
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2786
					group = AllocateSpriteGroup();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2787
					group->type = SGT_TILELAYOUT;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2788
					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
  2789
					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
  2790
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2791
					/* Groundsprite */
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2792
					group->g.layout.dts->ground.sprite = grf_load_word(&buf);
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2793
					group->g.layout.dts->ground.pal    = grf_load_word(&buf);
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  2794
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2795
					/* Remap transparent/colour modifier bits */
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  2796
					MapSpriteMappingRecolour(&group->g.layout.dts->ground);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  2797
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2798
					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
  2799
						/* 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
  2800
						 * last spriteset defined. */
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2801
						SpriteID sprite = _cur_grffile->spriteset_start + GB(group->g.layout.dts->ground.sprite, 0, 14) * sprites;
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2802
						SB(group->g.layout.dts->ground.sprite, 0, SPRITE_WIDTH, sprite);
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2803
						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
  2804
					}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2805
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2806
					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
  2807
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2808
					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
  2809
						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
  2810
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  2811
						seq->image.sprite = grf_load_word(&buf);
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  2812
						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
  2813
						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
  2814
						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
  2815
9073
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  2816
						MapSpriteMappingRecolour(&seq->image);
740f7aaa3ff6 (svn r12158) -Codechange: merge all the sprite recolouring mapping under a single function
belugas
parents: 9067
diff changeset
  2817
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  2818
						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
  2819
							/* 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
  2820
							 * last spriteset defined. */
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  2821
							SpriteID sprite = _cur_grffile->spriteset_start + GB(seq->image.sprite, 0, 14) * sprites;
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  2822
							SB(seq->image.sprite, 0, SPRITE_WIDTH, sprite);
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9042
diff changeset
  2823
							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
  2824
						}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2825
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2826
						if (type > 0) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2827
							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
  2828
							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
  2829
						}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2830
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2831
						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
  2832
						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
  2833
						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
  2834
					}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2835
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2836
					/* Set the terminator value. */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2837
					((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
  2838
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2839
					break;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2840
				}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  2841
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2842
				case GSF_INDUSTRIES: {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2843
					if (type > 1) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2844
						grfmsg(1, "NewSpriteGroup: Unsupported industry production version %d, skipping", type);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2845
						break;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2846
					}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2847
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2848
					group = AllocateSpriteGroup();
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2849
					group->type = SGT_INDUSTRY_PRODUCTION;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2850
					group->g.indprod.version = type;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2851
					if (type == 0) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2852
						for (uint i = 0; i < 3; i++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2853
							group->g.indprod.substract_input[i] = grf_load_word(&buf);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2854
						}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2855
						for (uint i = 0; i < 2; i++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2856
							group->g.indprod.add_output[i] = grf_load_word(&buf);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2857
						}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2858
						group->g.indprod.again = grf_load_byte(&buf);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2859
					} else {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2860
						for (uint i = 0; i < 3; i++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2861
							group->g.indprod.substract_input[i] = grf_load_byte(&buf);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2862
						}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2863
						for (uint i = 0; i < 2; i++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2864
							group->g.indprod.add_output[i] = grf_load_byte(&buf);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2865
						}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2866
						group->g.indprod.again = grf_load_byte(&buf);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2867
					}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2868
					break;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2869
				}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7658
diff changeset
  2870
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
  2871
				/* 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
  2872
				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
  2873
			}
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
  2874
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2875
	}
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
  2876
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
  2877
	_cur_grffile->spritegroups[setid] = group;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2878
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2879
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2880
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
  2881
{
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2882
	/* 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
  2883
	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
  2884
	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
  2885
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
  2886
	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
  2887
		/* 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
  2888
		if (ctype >= 32) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2889
			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
  2890
			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
  2891
		}
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
  2892
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
  2893
		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
  2894
			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
  2895
			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
  2896
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
  2897
			if (cs->bitnum == ctype) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2898
				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
  2899
				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
  2900
			}
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
  2901
		}
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
  2902
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2903
		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
  2904
		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
  2905
	}
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
  2906
6469
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2907
	/* 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
  2908
	if (ctype >= _cur_grffile->cargo_max) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2909
		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
  2910
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2911
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2912
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2913
	/* 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
  2914
	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
  2915
	if (cl == 0) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2916
		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
  2917
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2918
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2919
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2920
	ctype = GetCargoIDByLabel(cl);
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2921
	if (ctype == CT_INVALID) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2922
		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
  2923
		return CT_INVALID;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2924
	}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2925
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2926
	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
  2927
	return ctype;
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2928
}
05a2e97144ec (svn r8886) -Codechange: (NewGRF) Add (partial) cargo translation table support, applied to action 3s only.
peter1138
parents: 6468
diff changeset
  2929
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
  2930
10812
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2931
static bool IsValidGroupID(uint16 groupid, const char *function)
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2932
{
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2933
	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2934
		grfmsg(1, "%s: Spriteset 0x%04X out of range (maximum 0x%02X) or empty, skipping.", function, groupid, _cur_grffile->spritegroups_count - 1);
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2935
		return false;
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2936
	}
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2937
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2938
	return true;
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2939
}
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  2940
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2941
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
  2942
{
8694
8b6828a78860 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents: 8690
diff changeset
  2943
	static EngineID *last_engines;
8b6828a78860 (svn r11761) -Codechange: Use appropriate variable types for NewGRF engine overrides, and adjust scope while there.
peter1138
parents: 8690
diff changeset
  2944
	static uint last_engines_count;
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2945
	bool wagover = false;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2946
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2947
	/* Test for 'wagon override' flag */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2948
	if (HasBit(idcount, 7)) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2949
		wagover = true;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2950
		/* Strip off the flag */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2951
		idcount = GB(idcount, 0, 7);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2952
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2953
		if (last_engines_count == 0) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2954
			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
  2955
			return;
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2956
		}
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
  2957
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  2958
		grfmsg(6, "VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons",
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2959
				last_engines_count, idcount);
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2960
	} else {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2961
		if (last_engines_count != idcount) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2962
			last_engines = ReallocT(last_engines, idcount);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2963
			last_engines_count = idcount;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2964
		}
372
1cc9354e2362 (svn r560) -newgrf: General cleanup of the code (pasky & octo)
celestar
parents: 369
diff changeset
  2965
	}
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
  2966
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  2967
	EngineID *engines = AllocaM(EngineID, idcount);
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  2968
	for (uint i = 0; i < idcount; i++) {
10929
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  2969
		engines[i] = GetNewEngine(_cur_grffile, (VehicleType)feature, grf_load_extended(&buf))->index;
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2970
		if (!wagover) last_engines[i] = engines[i];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2971
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2972
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2973
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2974
	for (uint c = 0; c < cidcount; c++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2975
		uint8 ctype = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2976
		uint16 groupid = grf_load_word(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2977
		if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) continue;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2978
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2979
		grfmsg(8, "VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2980
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2981
		ctype = TranslateCargo(feature, ctype);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2982
		if (ctype == CT_INVALID) continue;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2983
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2984
		for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2985
			EngineID engine = engines[i];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2986
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2987
			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
  2988
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  2989
			if (wagover) {
4869
cded5f3a83c9 (svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
peter1138
parents: 4818
diff changeset
  2990
				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
  2991
			} 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
  2992
				SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2993
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2994
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  2995
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2996
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2997
	uint16 groupid = grf_load_word(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2998
	if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) return;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  2999
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3000
	grfmsg(8, "-- Default group id 0x%04X", groupid);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3001
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3002
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3003
		EngineID engine = engines[i];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3004
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3005
		if (wagover) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3006
			SetWagonOverrideSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3007
		} else {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3008
			SetCustomEngineSprites(engine, CT_DEFAULT, _cur_grffile->spritegroups[groupid]);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3009
			SetEngineGRF(engine, _cur_grffile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3010
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3011
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3012
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3013
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
  3014
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3015
static void CanalMapSpriteGroup(byte *buf, uint8 idcount)
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3016
{
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  3017
	CanalFeature *cfs = AllocaM(CanalFeature, idcount);
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3018
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3019
		cfs[i] = (CanalFeature)grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3020
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3021
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3022
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3023
	buf += cidcount * 3;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3024
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3025
	uint16 groupid = grf_load_word(&buf);
10812
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  3026
	if (!IsValidGroupID(groupid, "CanalMapSpriteGroup")) return;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3027
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3028
	for (uint i = 0; i < idcount; i++) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3029
		CanalFeature cf = cfs[i];
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3030
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3031
		if (cf >= CF_END) {
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3032
			grfmsg(1, "CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3033
			continue;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3034
		}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3035
8868
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  3036
		_water_feature[cf].group = _cur_grffile->spritegroups[groupid];
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3037
	}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3038
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3039
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3040
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3041
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
  3042
{
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  3043
	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
  3044
	for (uint i = 0; i < idcount; i++) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3045
		stations[i] = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3046
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3047
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3048
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3049
	for (uint c = 0; c < cidcount; c++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3050
		uint8 ctype = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3051
		uint16 groupid = grf_load_word(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3052
		if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) continue;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3053
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3054
		ctype = TranslateCargo(GSF_STATION, ctype);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3055
		if (ctype == CT_INVALID) continue;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3056
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3057
		for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3058
			StationSpec *statspec = _cur_grffile->stations[stations[i]];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3059
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3060
			if (statspec == NULL) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3061
				grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3062
				return;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3063
			}
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
  3064
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3065
			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
  3066
		}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3067
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3068
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3069
	uint16 groupid = grf_load_word(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3070
	if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) return;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3071
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3072
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3073
		StationSpec *statspec = _cur_grffile->stations[stations[i]];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3074
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3075
		if (statspec == NULL) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3076
			grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3077
			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
  3078
		}
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3079
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3080
		statspec->spritegroup[CT_DEFAULT] = _cur_grffile->spritegroups[groupid];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3081
		statspec->grffile = _cur_grffile;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3082
		statspec->localidx = stations[i];
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3083
		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
  3084
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3085
}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3086
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3087
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3088
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
  3089
{
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  3090
	uint8 *houses = AllocaM(uint8, idcount);
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3091
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3092
		houses[i] = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3093
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3094
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3095
	/* Skip the cargo type section, we only care about the default group */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3096
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3097
	buf += cidcount * 3;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3098
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3099
	uint16 groupid = grf_load_word(&buf);
10812
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  3100
	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
  3101
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3102
	for (uint i = 0; i < idcount; i++) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3103
		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
  3104
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3105
		if (hs == NULL) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3106
			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
  3107
			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
  3108
		}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3109
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3110
		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
  3111
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3112
}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3113
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3114
static void IndustryMapSpriteGroup(byte *buf, uint8 idcount)
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3115
{
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  3116
	uint8 *industries = AllocaM(uint8, idcount);
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3117
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3118
		industries[i] = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3119
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3120
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3121
	/* Skip the cargo type section, we only care about the default group */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3122
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3123
	buf += cidcount * 3;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3124
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3125
	uint16 groupid = grf_load_word(&buf);
10812
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  3126
	if (!IsValidGroupID(groupid, "IndustryMapSpriteGroup")) return;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3127
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3128
	for (uint i = 0; i < idcount; i++) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3129
		IndustrySpec *indsp = _cur_grffile->industryspec[industries[i]];
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3130
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3131
		if (indsp == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3132
			grfmsg(1, "IndustryMapSpriteGroup: Too many industries defined, skipping");
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3133
			return;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3134
		}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3135
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3136
		indsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3137
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3138
}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3139
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3140
static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount)
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3141
{
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  3142
	uint8 *indtiles = AllocaM(uint8, idcount);
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3143
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3144
		indtiles[i] = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3145
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3146
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3147
	/* Skip the cargo type section, we only care about the default group */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3148
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3149
	buf += cidcount * 3;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3150
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3151
	uint16 groupid = grf_load_word(&buf);
10812
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  3152
	if (!IsValidGroupID(groupid, "IndustrytileMapSpriteGroup")) return;
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3153
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3154
	for (uint i = 0; i < idcount; i++) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3155
		IndustryTileSpec *indtsp = _cur_grffile->indtspec[indtiles[i]];
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3156
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3157
		if (indtsp == NULL) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3158
			grfmsg(1, "IndustrytileMapSpriteGroup: Too many industry tiles defined, skipping");
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3159
			return;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3160
		}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3161
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3162
		indtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3163
	}
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3164
}
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3165
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3166
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
  3167
{
10905
293ba816b703 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 10886
diff changeset
  3168
	CargoID *cargos = AllocaM(CargoID, idcount);
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3169
	for (uint i = 0; i < idcount; i++) {
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3170
		cargos[i] = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3171
	}
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3172
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3173
	/* Skip the cargo type section, we only care about the default group */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3174
	uint8 cidcount = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3175
	buf += cidcount * 3;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3176
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3177
	uint16 groupid = grf_load_word(&buf);
10812
2326ed5f94a8 (svn r13363) -Codechange: Code duplication tidy up
peter1138
parents: 10775
diff changeset
  3178
	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
  3179
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3180
	for (uint i = 0; i < idcount; i++) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3181
		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
  3182
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3183
		if (cid >= NUM_CARGO) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3184
			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
  3185
			continue;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3186
		}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3187
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3188
		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
  3189
		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
  3190
		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
  3191
	}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3192
}
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3193
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3194
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
  3195
/* Action 0x03 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  3196
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
  3197
{
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3198
	/* <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
  3199
	 * 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
  3200
	 * 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
  3201
	 *
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3202
	 * 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
  3203
	 * 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
  3204
	 *                 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
  3205
	 * 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
  3206
	 * 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
  3207
	 *                 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
  3208
	 * 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
  3209
	 * 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
  3210
	 * 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
  3211
9040
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3212
	if (_cur_grffile->spritegroups == 0) {
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3213
		grfmsg(1, "FeatureMapSpriteGroup: No sprite groups to work on! Skipping");
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3214
		return;
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3215
	}
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3216
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
  3217
	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
  3218
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3219
	buf++;
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3220
	uint8 feature = grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3221
	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
  3222
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3223
	/* 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
  3224
	if (idcount == 0) {
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3225
		/* Skip number of cargo ids? */
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3226
		grf_load_byte(&buf);
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3227
		uint16 groupid = grf_load_word(&buf);
9040
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3228
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3229
		grfmsg(6, "FeatureMapSpriteGroup: Adding generic feature callback for feature %d", feature);
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3230
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  3231
		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
  3232
		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
  3233
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3234
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3235
	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
  3236
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3237
	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
  3238
		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
  3239
		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
  3240
		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
  3241
		case GSF_AIRCRAFT:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3242
			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
  3243
			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
  3244
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3245
		case GSF_CANAL:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3246
			CanalMapSpriteGroup(buf, idcount);
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3247
			return;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  3248
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
  3249
		case GSF_STATION:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3250
			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
  3251
			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
  3252
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3253
		case GSF_TOWNHOUSE:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3254
			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
  3255
			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
  3256
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3257
		case GSF_INDUSTRIES:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3258
			IndustryMapSpriteGroup(buf, idcount);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3259
			return;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3260
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3261
		case GSF_INDUSTRYTILES:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3262
			IndustrytileMapSpriteGroup(buf, idcount);
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3263
			return;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  3264
6691
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3265
		case GSF_CARGOS:
10813
5d79bb4d388c (svn r13364) -Codechange: Refactor action 3 mapping to use grf_load_*() instead of direct byte array access.
peter1138
parents: 10812
diff changeset
  3266
			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
  3267
			return;
e8c27a509894 (svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents: 6689
diff changeset
  3268
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
  3269
		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
  3270
			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
  3271
			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
  3272
	}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3273
}
dc89785a5bee (svn r9416) -Codechange: Split NewGRF Action 3 handler into separate functions for each feature (vehicles are common, though)
peter1138
parents: 6687
diff changeset
  3274
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3275
/* Action 0x04 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  3276
static void FeatureNewName(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3277
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3278
	/* <04> <veh-type> <language-id> <num-veh> <offset> <data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3279
	 *
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3280
	 * B veh-type      see action 0 (as 00..07, + 0A
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3281
	 *                 But IF veh-type = 48, then generic text
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3282
	 * 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
  3283
	                   with up to 64 language.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3284
	                   Otherwise, it is a mapping where set bits have meaning
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3285
	                   0 = american, 1 = english, 2 = german, 3 = french, 4 = spanish
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3286
	                   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
  3287
	 * 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
  3288
	 * 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
  3289
	 *                 Byte : ID of vehicle to change
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3290
	 *                 Word : ID of string to change/add
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3291
	 * 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
  3292
	 *                 which the next name begins. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3293
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
  3294
	bool new_scheme = _cur_grffile->grf_version >= 7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3295
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
  3296
	if (!check_length(len, 6, "FeatureNewName")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3297
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3298
	uint8 feature  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3299
	uint8 lang     = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3300
	uint8 num      = grf_load_byte(&buf);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  3301
	bool generic   = HasBit(lang, 7);
10929
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3302
	uint16 id;
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3303
	if (generic) {
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3304
		id = grf_load_word(&buf);
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3305
	} else if (feature <= GSF_AIRCRAFT) {
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3306
		id = grf_load_extended(&buf);
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3307
	} else {
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3308
		id = grf_load_byte(&buf);
4989211616f8 (svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
peter1138
parents: 10917
diff changeset
  3309
	}
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
  3310
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  3311
	ClrBit(lang, 7);
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3312
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3313
	uint16 endid = id + num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3314
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3315
	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
  3316
	               id, endid, feature, lang);
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3317
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
  3318
	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
  3319
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3320
	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
  3321
		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
  3322
		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
  3323
be4399248c60 (svn r8825) -Fix: Make sure strings read from newgrf files are 0 terminated and 0
maedhros
parents: 6388
diff changeset
  3324
		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
  3325
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3326
		grfmsg(8, "FeatureNewName: 0x%04X <- %s", id, name);
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3327
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3328
		switch (feature) {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3329
			case GSF_TRAIN:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3330
			case GSF_ROAD:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3331
			case GSF_SHIP:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3332
			case GSF_AIRCRAFT:
10820
525f5f140fac (svn r13371) -Fix (r4510 ... r12924): Engine array size is not related to the ID used when setting a vehicle's name (it is vehicle type specific). Instead just test for a generic string.
peter1138
parents: 10817
diff changeset
  3333
				if (!generic) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  3334
					Engine *e = GetNewEngine(_cur_grffile, (VehicleType)feature, id);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  3335
					StringID string = AddGRFString(_cur_grffile->grfid, e->index, lang, new_scheme, name, e->info.string_id);
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  3336
					e->info.string_id = string;
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3337
				} else {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3338
					AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, id);
3614
2c75299f54bd (svn r4510) - NewGRF bounds checking:
peter1138
parents: 3604
diff changeset
  3339
				}
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3340
				break;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3341
7678
8c61d49f4447 (svn r10456) -Codechange: Enable loading newgrf strings for Industries
belugas
parents: 7670
diff changeset
  3342
			case GSF_INDUSTRIES: {
8c61d49f4447 (svn r10456) -Codechange: Enable loading newgrf strings for Industries
belugas
parents: 7670
diff changeset
  3343
				AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
8c61d49f4447 (svn r10456) -Codechange: Enable loading newgrf strings for Industries
belugas
parents: 7670
diff changeset
  3344
				break;
8c61d49f4447 (svn r10456) -Codechange: Enable loading newgrf strings for Industries
belugas
parents: 7670
diff changeset
  3345
			}
8c61d49f4447 (svn r10456) -Codechange: Enable loading newgrf strings for Industries
belugas
parents: 7670
diff changeset
  3346
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3347
			case GSF_TOWNHOUSE:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3348
			default:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3349
				switch (GB(id, 8, 8)) {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3350
					case 0xC4: // Station class name
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3351
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3352
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3353
						} else {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3354
							StationClassID sclass = _cur_grffile->stations[GB(id, 0, 8)]->sclass;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3355
							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
  3356
						}
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3357
						break;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3358
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3359
					case 0xC5: // Station name
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3360
						if (_cur_grffile->stations == NULL || _cur_grffile->stations[GB(id, 0, 8)] == NULL) {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3361
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3362
						} else {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3363
							_cur_grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3364
						}
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3365
						break;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3366
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3367
					case 0xC9: // House name
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3368
						if (_cur_grffile->housespec == NULL || _cur_grffile->housespec[GB(id, 0, 8)] == NULL) {
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3369
							grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8));
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3370
						} else {
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  3371
							_cur_grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3372
						}
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3373
						break;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3374
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3375
					case 0xD0:
9151
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
  3376
					case 0xD1:
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
  3377
					case 0xD2:
8296bc2c7ca2 (svn r12316) -Codechange: Support loading full range of 0xD0xx NewGRF strings which
peter1138
parents: 9145
diff changeset
  3378
					case 0xD3:
7103
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3379
					case 0xDC:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3380
						AddGRFString(_cur_grffile->grfid, id, lang, new_scheme, name, STR_UNDEFINED);
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3381
						break;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3382
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3383
					default:
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3384
						grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3385
						break;
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3386
				}
8c91ce192058 (svn r9827) -Codechange/Fix: [NewGRF] Text strings of 1 character are perfectly valid... (fixes dbsetxl refits again...)
peter1138
parents: 7102
diff changeset
  3387
				break;
3642
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  3388
a247e07fafdf (svn r4551) - NewGRF: add string handling for newstations.
peter1138
parents: 3641
diff changeset
  3389
#if 0
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3390
				case GSF_CANAL :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3391
				case GSF_BRIDGE :
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3392
					AddGRFString(_cur_spriteid, id, lang, name);
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
  3393
					switch (GB(id, 8, 8)) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  3394
						case 0xC9: // House name
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3395
						default:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3396
							grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3397
					}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3398
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3399
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3400
				default :
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3401
					grfmsg(7, "FeatureNewName: Unsupported feature (0x%02X)", feature);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3402
					break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  3403
#endif
379
4605aa187b18 (svn r568) -newgrf: Make @wagover bool, simplifying stuff. (pasky)
celestar
parents: 378
diff changeset
  3404
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3405
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3407
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3408
/**
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3409
 * Sanitize incoming sprite offsets for Action 5 graphics replacements.
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3410
 * @param num         the number of sprites to load.
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3411
 * @param offset      offset from the base.
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3412
 * @param max_sprites the maximum number of sprites that can be loaded in this action 5.
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3413
 * @param name        used for error warnings.
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3414
 * @return the number of sprites that is going to be skipped
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3415
 */
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3416
static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites, const char *name)
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3417
{
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3418
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3419
	if (offset >= max_sprites) {
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3420
		grfmsg(1, "GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3421
		uint orig_num = num;
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3422
		num = 0;
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3423
		return orig_num;
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3424
	}
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3425
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3426
	if (offset + num > max_sprites) {
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3427
		grfmsg(4, "GraphicsNew: %s sprite overflow, truncating...", name);
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3428
		uint orig_num = num;
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3429
		num = max(max_sprites - offset, 0);
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3430
		return orig_num - num;
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3431
	}
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3432
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3433
	return 0;
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3434
}
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3435
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3436
/* Action 0x05 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  3437
static void GraphicsNew(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3438
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3439
	/* <05> <graphics-type> <num-sprites> <other data...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3440
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3441
	 * 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
  3442
	 * 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
  3443
	 * V other data    Graphics type specific data.  Currently unused. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3444
	/* TODO */
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3445
8739
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3446
	enum Action5BlockType {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3447
		A5BLOCK_FIXED,                ///< Only allow replacing a whole block of sprites. (TTDP compatible)
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3448
		A5BLOCK_ALLOW_OFFSET,         ///< Allow replacing any subset by specifiing an offset.
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3449
		A5BLOCK_INVALID,              ///< unknown/not-implemented type
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3450
	};
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3451
	struct Action5Type {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3452
		Action5BlockType block_type;  ///< How is this Action5 type processed?
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3453
		SpriteID sprite_base;         ///< Load the sprites starting from this sprite.
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3454
		uint16 min_sprites;           ///< If the Action5 contains less sprites, the whole block will be ignored.
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3455
		uint16 max_sprites;           ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used.
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3456
		const char *name;             ///< Name for error messages.
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3457
	};
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3458
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3459
	static const Action5Type action5_types[] = {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3460
		/* Note: min_sprites should not be changed. Therefore these constants are directly here and not in sprites.h */
10917
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3461
		/* 0x00 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x00"             },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3462
		/* 0x01 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x01"             },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3463
		/* 0x02 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x02"             },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3464
		/* 0x03 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x03"             },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3465
		/* 0x04 */ { A5BLOCK_FIXED,        SPR_SIGNALS_BASE,            48, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,    "Signal graphics"       },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3466
		/* 0x05 */ { A5BLOCK_FIXED,        SPR_ELRAIL_BASE,             48, ELRAIL_SPRITE_COUNT,                         "Catenary graphics"     },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3467
		/* 0x06 */ { A5BLOCK_FIXED,        SPR_SLOPES_BASE,             74, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, "Foundation graphics"   },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3468
		/* 0x07 */ { A5BLOCK_INVALID,      0,                           75, 0,                                           "TTDP GUI graphics"     }, // Not used by OTTD.
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3469
		/* 0x08 */ { A5BLOCK_FIXED,        SPR_CANALS_BASE,             65, CANALS_SPRITE_COUNT,                         "Canal graphics"        },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3470
		/* 0x09 */ { A5BLOCK_FIXED,        SPR_ONEWAY_BASE,              6, ONEWAY_SPRITE_COUNT,                         "One way road graphics" },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3471
		/* 0x0A */ { A5BLOCK_FIXED,        SPR_2CCMAP_BASE,            256, TWOCCMAP_SPRITE_COUNT,                       "2CC colour maps"       },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3472
		/* 0x0B */ { A5BLOCK_FIXED,        SPR_TRAMWAY_BASE,           113, TRAMWAY_SPRITE_COUNT,                        "Tramway graphics"      },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3473
		/* 0x0C */ { A5BLOCK_INVALID,      0,                          133, 0,                                           "Snowy temperate tree"  }, // Not yet used by OTTD.
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3474
		/* 0x0D */ { A5BLOCK_FIXED,        SPR_SHORE_BASE,              16, SPR_SHORE_SPRITE_COUNT,                      "Shore graphics"        },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3475
		/* 0x0E */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "New Signals graphics"  }, // Not yet used by OTTD.
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3476
		/* 0x0F */ { A5BLOCK_FIXED,        SPR_TRACKS_FOR_SLOPES_BASE,  12, TRACKS_FOR_SLOPES_SPRITE_COUNT,              "Sloped rail track"     },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3477
		/* 0x10 */ { A5BLOCK_FIXED,        SPR_AIRPORTX_BASE,           15, AIRPORTX_SPRITE_COUNT,                       "Airport graphics"      },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3478
		/* 0x11 */ { A5BLOCK_FIXED,        SPR_ROADSTOP_BASE,            8, ROADSTOP_SPRITE_COUNT,                       "Road stop graphics"    },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3479
		/* 0x12 */ { A5BLOCK_FIXED,        SPR_AQUEDUCT_BASE,            8, AQUEDUCT_SPRITE_COUNT,                       "Aqueduct graphics"     },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3480
		/* 0x13 */ { A5BLOCK_FIXED,        SPR_AUTORAIL_BASE,           55, AUTORAIL_SPRITE_COUNT,                       "Autorail graphics"     },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3481
		/* 0x14 */ { A5BLOCK_ALLOW_OFFSET, SPR_FLAGS_BASE,               1, FLAGS_SPRITE_COUNT,                          "Flag graphics"         },
d300d6e6b982 (svn r13469) -Codechange: add support for loading Action 0x05, type 0F: "tracks for slopes". It's not useful right now, but it will be in the future.
rubidium
parents: 10913
diff changeset
  3482
		/* 0x15 */ { A5BLOCK_ALLOW_OFFSET, SPR_OPENTTD_BASE,             1, OPENTTD_SPRITE_COUNT,                        "OpenTTD GUI graphics"  },
8739
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3483
	};
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3484
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
  3485
	if (!check_length(len, 2, "GraphicsNew")) return;
2346
7e88b66abdbd (svn r2872) -Feature: [NewGRF] Add support for "extended bytes"
tron
parents: 2345
diff changeset
  3486
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3487
	uint8 type = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3488
	uint16 num = grf_load_extended(&buf);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  3489
	uint16 offset = HasBit(type, 7) ? grf_load_extended(&buf) : 0;
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  3490
	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
  3491
8739
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3492
	if ((type == 0x0D) && (num == 10) && _cur_grffile->is_ottdfile) {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3493
		/* Special not-TTDP-compatible case used in openttd(d/w).grf
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3494
		 * Missing shore sprites and initialisation of SPR_SHORE_BASE */
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3495
		grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from openttd(d/w).grf.");
10821
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3496
		LoadNextSprite(SPR_SHORE_BASE +  0, _file_index, _nfo_line++); // SLOPE_STEEP_S
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3497
		LoadNextSprite(SPR_SHORE_BASE +  5, _file_index, _nfo_line++); // SLOPE_STEEP_W
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3498
		LoadNextSprite(SPR_SHORE_BASE +  7, _file_index, _nfo_line++); // SLOPE_WSE
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3499
		LoadNextSprite(SPR_SHORE_BASE + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3500
		LoadNextSprite(SPR_SHORE_BASE + 11, _file_index, _nfo_line++); // SLOPE_NWS
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3501
		LoadNextSprite(SPR_SHORE_BASE + 13, _file_index, _nfo_line++); // SLOPE_ENW
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3502
		LoadNextSprite(SPR_SHORE_BASE + 14, _file_index, _nfo_line++); // SLOPE_SEN
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3503
		LoadNextSprite(SPR_SHORE_BASE + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3504
		LoadNextSprite(SPR_SHORE_BASE + 16, _file_index, _nfo_line++); // SLOPE_EW
0956995992b5 (svn r13372) -Cleanup: Excessive whitespace
peter1138
parents: 10820
diff changeset
  3505
		LoadNextSprite(SPR_SHORE_BASE + 17, _file_index, _nfo_line++); // SLOPE_NS
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  3506
		if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ONLY_NEW;
8739
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3507
		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
  3508
	}
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
  3509
8739
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3510
	/* Supported type? */
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3511
	if ((type >= lengthof(action5_types)) || (action5_types[type].block_type == A5BLOCK_INVALID)) {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3512
		grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3513
		_skip_sprites = num;
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3514
		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
  3515
	}
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
  3516
8739
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3517
	const Action5Type *action5_type = &action5_types[type];
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3518
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3519
	/* Ignore offset if not allowed */
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3520
	if ((action5_type->block_type != A5BLOCK_ALLOW_OFFSET) && (offset != 0)) {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3521
		grfmsg(1, "GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->name, type);
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3522
		offset = 0;
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3523
	}
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3524
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3525
	/* Ignore action5 if too few sprites are specified. (for TTDP compatibility)
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3526
	 * This does not make sense, if <offset> is allowed */
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3527
	if ((action5_type->block_type == A5BLOCK_FIXED) && (num < action5_type->min_sprites)) {
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3528
		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);
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3529
		_skip_sprites = num;
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3530
		return;
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3531
	}
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3532
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3533
	/* Load at most max_sprites sprites. Skip remaining sprites. (for compatibility with TTDP and future extentions) */
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3534
	uint16 skip_num = SanitizeSpriteOffset(num, offset, action5_type->max_sprites, action5_type->name);
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3535
	SpriteID replace = action5_type->sprite_base + offset;
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3536
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3537
	/* Load <num> sprites starting from <replace>, then skip <skip_num> sprites. */
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3538
	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);
4ae8f4bbc065 (svn r11807) -Codechange: Make Action5 handler more upwards- and TTDP-compatible by allowing specifiing more sprites than needed.
frosch
parents: 8735
diff changeset
  3539
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
  3540
	for (; num > 0; num--) {
8449
c5759019cbcd (svn r11509) -Fix: off-by-one error in some sprite numbers; increase sprite number counter before loading the next sprite instead of after doing so.
rubidium
parents: 8437
diff changeset
  3541
		_nfo_line++;
7404
fc0559157f16 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 7390
diff changeset
  3542
		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
  3543
	}
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3544
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  3545
	if (type == 0x0D) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_5;
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  3546
8378
9f849e5763e2 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 8375
diff changeset
  3547
	_skip_sprites = skip_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3548
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3549
7025
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3550
/* Action 0x05 (SKIP) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  3551
static void SkipAct5(byte *buf, size_t len)
7025
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3552
{
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3553
	if (!check_length(len, 2, "SkipAct5")) return;
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3554
	buf++;
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3555
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3556
	/* Ignore type byte */
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3557
	grf_load_byte(&buf);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3558
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3559
	/* Skip the sprites of this action */
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3560
	_skip_sprites = grf_load_extended(&buf);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3561
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3562
	grfmsg(3, "SkipAct5: Skipping %d sprites", _skip_sprites);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3563
}
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  3564
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3565
/**
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3566
 * Reads a variable common to VarAction2 and Action7/9/D.
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3567
 *
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3568
 * Returns VarAction2 variable 'param' resp. Action7/9/D variable '0x80 + param'.
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3569
 * If a variable is not accessible from all four actions, it is handled in the action specific functions.
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3570
 *
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3571
 * @param param variable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first).
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3572
 * @param value returns the value of the variable.
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3573
 * @return true iff the variable is known and the value is returned in 'value'.
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3574
 */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3575
bool GetGlobalVariable(byte param, uint32 *value)
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3576
{
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3577
	switch (param) {
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3578
		case 0x00: // current date
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3579
			*value = max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3580
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3581
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3582
		case 0x01: // current year
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3583
			*value = Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3584
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3585
11038
d253e0dfa688 (svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
frosch
parents: 11020
diff changeset
  3586
		case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24)
d253e0dfa688 (svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
frosch
parents: 11020
diff changeset
  3587
			YearMonthDay ymd;
d253e0dfa688 (svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
frosch
parents: 11020
diff changeset
  3588
			ConvertDateToYMD(_date, &ymd);
d253e0dfa688 (svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
frosch
parents: 11020
diff changeset
  3589
			Date start_of_year = ConvertYMDToDate(ymd.year, 0, 1);
d253e0dfa688 (svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
frosch
parents: 11020
diff changeset
  3590
			*value = ymd.month | (ymd.day - 1) << 8 | (IsLeapYear(ymd.year) ? 1 << 15 : 0) | (_date - start_of_year) << 16;
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3591
			return true;
11038
d253e0dfa688 (svn r13594) -Feature(ette)[FS#2093]: Supply newgrfs with 'day of month', 'leap year' and 'day of year'.
frosch
parents: 11020
diff changeset
  3592
		}
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3593
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3594
		case 0x03: // current climate, 0=temp, 1=arctic, 2=trop, 3=toyland
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  3595
			*value = _settings_game.game_creation.landscape;
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3596
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3597
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3598
		case 0x06: // road traffic side, bit 4 clear=left, set=right
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  3599
			*value = _settings_game.vehicle.road_side << 4;
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3600
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3601
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3602
		case 0x09: // date fraction
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3603
			*value = _date_fract;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3604
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3605
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3606
		case 0x0A: // animation counter
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3607
			*value = _tick_counter;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3608
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3609
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3610
		case 0x0B: { // TTDPatch version
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3611
			uint major    = 2;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3612
			uint minor    = 6;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3613
			uint revision = 1; // special case: 2.0.1 is 2.0.10
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3614
			uint build    = 1382;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3615
			*value = (major << 24) | (minor << 20) | (revision << 16) | build;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3616
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3617
		}
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3618
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3619
		case 0x0D: // TTD Version, 00=DOS, 01=Windows
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3620
			*value = !_use_dos_palette;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3621
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3622
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3623
		case 0x0E: // Y-offset for train sprites
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3624
			*value = _traininfo_vehicle_pitch;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3625
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3626
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3627
		case 0x0F: // Rail track type cost factors
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3628
			*value = 0;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3629
			SB(*value, 0, 8, _railtype_cost_multiplier[0]); // normal rail
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  3630
			if (_settings_game.vehicle.disable_elrails) {
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3631
				/* skip elrail multiplier - disabled */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3632
				SB(*value, 8, 8, _railtype_cost_multiplier[2]); // monorail
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3633
			} else {
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3634
				SB(*value, 8, 8, _railtype_cost_multiplier[1]); // electified railway
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3635
				/* Skip monorail multiplier - no space in result */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3636
			}
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3637
			SB(*value, 16, 8, _railtype_cost_multiplier[3]); // maglev
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3638
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3639
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3640
		case 0x11: // current rail tool type
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3641
			*value = 0;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3642
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3643
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3644
		case 0x12: // Game mode
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3645
			*value = _game_mode;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3646
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3647
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3648
		/* case 0x13: // Tile refresh offset to left    not implemented */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3649
		/* case 0x14: // Tile refresh offset to right   not implemented */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3650
		/* case 0x15: // Tile refresh offset upwards    not implemented */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3651
		/* case 0x16: // Tile refresh offset downwards  not implemented */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3652
		/* case 0x17: // temperate snow line            not implemented */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3653
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3654
		case 0x1A: // Always -1
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3655
			*value = UINT_MAX;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3656
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3657
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3658
		case 0x1B: // Display options
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3659
			*value = GB(_display_opt, 0, 6);
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3660
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3661
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3662
		case 0x1D: // TTD Platform, 00=TTDPatch, 01=OpenTTD
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3663
			*value = 1;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3664
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3665
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3666
		case 0x1E: // Miscellaneous GRF features
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3667
			*value = _misc_grf_features;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3668
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3669
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3670
		/* case 0x1F: // locale dependent settings not implemented */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3671
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3672
		case 0x20: // snow line height
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  3673
			*value = _settings_game.game_creation.landscape == LT_ARCTIC ? GetSnowLine() : 0xFF;
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3674
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3675
10402
b168fbb99f7c (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 10390
diff changeset
  3676
		case 0x21: // OpenTTD version
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3677
			*value = _openttd_newgrf_version;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3678
			return true;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3679
9249
71cd193d6461 (svn r12449) -Feature[newGRF]: Add support for var A2/22 for action 7/9/D: Diificulty level
belugas
parents: 9191
diff changeset
  3680
		case 0x22: // difficulty level
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  3681
			*value = _settings_game.difficulty.diff_level;
9249
71cd193d6461 (svn r12449) -Feature[newGRF]: Add support for var A2/22 for action 7/9/D: Diificulty level
belugas
parents: 9191
diff changeset
  3682
			return true;
71cd193d6461 (svn r12449) -Feature[newGRF]: Add support for var A2/22 for action 7/9/D: Diificulty level
belugas
parents: 9191
diff changeset
  3683
10825
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3684
		case 0x23: // long format date
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3685
			*value = _date;
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3686
			return true;
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3687
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3688
		case 0x24: // long format year
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3689
			*value = _cur_year;
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3690
			return true;
e9b5f2644bb8 (svn r13376) -Feature: Add access to current long year and date from Action 7/9/D and VarAction2 (23/24 or A3/A4)
belugas
parents: 10823
diff changeset
  3691
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3692
		default: return false;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3693
	}
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3694
}
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3695
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3696
static uint32 GetParamVal(byte param, uint32 *cond_val)
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3697
{
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3698
	/* First handle variable common with VarAction2 */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3699
	uint32 value;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3700
	if (GetGlobalVariable(param - 0x80, &value)) return value;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3701
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3702
	/* Non-common variable */
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3703
	switch (param) {
7309
bc9f31c4ab97 (svn r10052) -Codechange: Support reserve/activate stage bits of action 7/9 variable 84.
peter1138
parents: 7302
diff changeset
  3704
		case 0x84: { // GRF loading stage
bc9f31c4ab97 (svn r10052) -Codechange: Support reserve/activate stage bits of action 7/9 variable 84.
peter1138
parents: 7302
diff changeset
  3705
			uint32 res = 0;
bc9f31c4ab97 (svn r10052) -Codechange: Support reserve/activate stage bits of action 7/9 variable 84.
peter1138
parents: 7302
diff changeset
  3706
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  3707
			if (_cur_stage > GLS_INIT) SetBit(res, 0);
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  3708
			if (_cur_stage == GLS_RESERVE) SetBit(res, 8);
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  3709
			if (_cur_stage == GLS_ACTIVATION) SetBit(res, 9);
7309
bc9f31c4ab97 (svn r10052) -Codechange: Support reserve/activate stage bits of action 7/9 variable 84.
peter1138
parents: 7302
diff changeset
  3710
			return res;
bc9f31c4ab97 (svn r10052) -Codechange: Support reserve/activate stage bits of action 7/9 variable 84.
peter1138
parents: 7302
diff changeset
  3711
		}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3712
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  3713
		case 0x85: // TTDPatch flags, only for bit tests
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3714
			if (cond_val == NULL) {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3715
				/* Supported in Action 0x07 and 0x09, not 0x0D */
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3716
				return 0;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3717
			} else {
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3718
				uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3719
				*cond_val %= 0x20;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3720
				return param_val;
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  3721
			}
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3722
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  3723
		case 0x88: // GRF ID check
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3724
			return 0;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3725
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  3726
		/* case 0x99: Global ID offest not implemented */
8276
1fe8700644de (svn r11330) -Add: OTTD version checking for NewGRFs. This allows NewGRFs to do something different for different versions of OpenTTD, like disabling it for too low versions or loading different graphics.
rubidium
parents: 8268
diff changeset
  3727
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3728
		default:
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3729
			/* GRF Parameter */
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3730
			if (param < 0x80) return _cur_grffile->param[param];
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3731
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3732
			/* In-game variable. */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3733
			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
  3734
			return UINT_MAX;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3735
	}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3736
}
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3737
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3738
/* Action 0x06 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  3739
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
  3740
{
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3741
	/* <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
  3742
	 *
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3743
	 * 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
  3744
	 *                 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
  3745
	 * 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
  3746
	 *                 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
  3747
	 *                 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
  3748
	 *                 were specified.
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3749
	 * 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
  3750
	 *                 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
  3751
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3752
	/* Preload the next sprite */
10751
ebd94f2d6385 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 10707
diff changeset
  3753
	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
  3754
	uint16 num = FioReadWord();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3755
	uint8 type = FioReadByte();
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3756
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3757
	/* 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
  3758
	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
  3759
		_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
  3760
		FioReadBlock(_preload_sprite, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3761
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3762
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3763
	/* 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
  3764
	FioSeekTo(pos, SEEK_SET);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3765
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3766
	if (type != 0xFF) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3767
		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
  3768
		return;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3769
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3770
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3771
	/* 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
  3772
	buf++;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3773
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3774
	for (;;) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3775
		uint i;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3776
		uint param_num;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3777
		uint param_size;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3778
		uint offset;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3779
		bool add_value;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3780
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3781
		/* 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
  3782
		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
  3783
		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
  3784
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3785
		/* 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
  3786
		 * 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
  3787
		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
  3788
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3789
		/* 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
  3790
		 * instead of replacing it. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  3791
		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
  3792
		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
  3793
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3794
		/* 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
  3795
		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
  3796
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3797
		/* 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
  3798
		 * 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
  3799
		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
  3800
			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
  3801
			break;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3802
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3803
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  3804
		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
  3805
7148
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3806
		bool carry = false;
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3807
		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
  3808
			uint32 value = GetParamVal(param_num + i / 4, NULL);
7148
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3809
			/* Reset carry flag for each iteration of the variable (only really
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3810
			 * matters if param_size is greater than 4) */
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3811
			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
  3812
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3813
			if (add_value) {
7148
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3814
				uint new_value = _preload_sprite[offset + i] + GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3815
				_preload_sprite[offset + i] = GB(new_value, 0, 8);
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3816
				/* Check if the addition overflowed */
8de751a801a8 (svn r9883) -Fix (r4965): [NewGRF] Check for overflow and carry over when adding to the existing value.
peter1138
parents: 7145
diff changeset
  3817
				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
  3818
			} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3819
				_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
  3820
			}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3821
		}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3822
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3823
}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  3824
11020
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3825
/**
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3826
 * Disable a static NewGRF when it is influencing another (non-static)
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3827
 * NewGRF as this could cause desyncs.
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3828
 *
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3829
 * We could just tell the NewGRF querying that the file doesn't exist,
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3830
 * but that might give unwanted results. Disabling the NewGRF gives the
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3831
 * best result as no NewGRF author can complain about that.
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3832
 * @param c the NewGRF to disable.
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3833
 */
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3834
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3835
{
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3836
	if (c->error != NULL) {
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3837
		free(c->error->custom_message);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3838
		free(c->error->data);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3839
		free(c->error);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3840
	}
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3841
	c->status = GCS_DISABLED;
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3842
	c->error  = CallocT<GRFError>(1);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3843
	c->error->data = strdup(_cur_grfconfig->name);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3844
	c->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3845
	c->error->message  = STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  3846
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  3847
	ClearTemporaryNewGRFData();
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  3848
	_skip_sprites = -1;
11020
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3849
}
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3850
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3851
/* Action 0x07 */
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  3852
/* Action 0x09 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  3853
static void SkipIf(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3854
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3855
	/* <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
  3856
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3857
	 * B param-num
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3858
	 * B param-size
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3859
	 * B condition-type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3860
	 * V value
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3861
	 * B num-sprites */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3862
	/* 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
  3863
	uint32 cond_val = 0;
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3864
	uint32 mask = 0;
360
ff657281ae48 (svn r548) -newgrf: minor style changes, and application of boolean type
darkvater
parents: 359
diff changeset
  3865
	bool result;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3866
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
  3867
	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
  3868
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3869
	uint8 param     = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3870
	uint8 paramsize = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3871
	uint8 condtype  = grf_load_byte(&buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3872
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
  3873
	if (condtype < 2) {
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3874
		/* 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
  3875
		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
  3876
	}
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
  3877
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3878
	switch (paramsize) {
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3879
		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3880
		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3881
		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
  3882
		default: break;
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  3883
	}
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
  3884
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3885
	if (param < 0x80 && _cur_grffile->param_end <= param) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3886
		grfmsg(7, "SkipIf: Param %d undefined, skipping test", param);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3887
		return;
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3888
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3889
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3890
	uint32 param_val = GetParamVal(param, &cond_val);
3806
dbbfd0c2331b (svn r4816) - NewGRF: action 7/9 improvements:
peter1138
parents: 3803
diff changeset
  3891
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3892
	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
  3893
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3894
	/*
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3895
	 * Parameter (variable in specs) 0x88 can only have GRF ID checking
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3896
	 * conditions, except conditions 0x0B and 0x0C (cargo availability)
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3897
	 * as those ignore the parameter. So, when the condition type is
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3898
	 * either of those, the specific variable 0x88 code is skipped, so
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3899
	 * the "general" code for the cargo availability conditions kicks in.
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3900
	 */
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3901
	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
  3902
		/* 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
  3903
11020
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3904
		GRFConfig *c = GetGRFConfig(cond_val);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3905
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3906
		if (c != NULL && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur_grfconfig->flags, GCF_STATIC) && c->status != GCS_DISABLED && _networking) {
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3907
			DisableStaticNewGRFInfluencingNonStaticNewGRFs(c);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3908
			c = NULL;
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  3909
		}
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
  3910
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
  3911
		if (condtype != 10 && c == NULL) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3912
			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
  3913
			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
  3914
		}
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
  3915
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
  3916
		switch (condtype) {
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3917
			/* Tests 0x06 to 0x0A are only for param 0x88, GRFID checks */
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3918
			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
  3919
				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
  3920
				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
  3921
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3922
			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
  3923
				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
  3924
				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
  3925
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3926
			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
  3927
				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
  3928
				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
  3929
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3930
			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
  3931
				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
  3932
				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
  3933
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3934
			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
  3935
				/* 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
  3936
				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
  3937
				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
  3938
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3939
			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
  3940
		}
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
  3941
	} 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
  3942
		/* 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
  3943
		switch (condtype) {
8304
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3944
			case 0x00: result = !!(param_val & (1 << cond_val));
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3945
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3946
			case 0x01: result = !(param_val & (1 << cond_val));
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3947
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3948
			case 0x02: result = (param_val & mask) == cond_val;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3949
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3950
			case 0x03: result = (param_val & mask) != cond_val;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3951
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3952
			case 0x04: result = (param_val & mask) < cond_val;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3953
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3954
			case 0x05: result = (param_val & mask) > cond_val;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3955
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3956
			case 0x0B: result = GetCargoIDByLabel(BSWAP32(cond_val)) == CT_INVALID;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3957
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3958
			case 0x0C: result = GetCargoIDByLabel(BSWAP32(cond_val)) != CT_INVALID;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3959
				break;
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3960
eb927ead85bf (svn r11358) -Fix: condition types 0x0B and 0x0C are also valid for variable 0x88 in action 7/9.
rubidium
parents: 8301
diff changeset
  3961
			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
  3962
		}
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3963
	}
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3964
1607
320079c7ac28 (svn r2111) So, result is bool therefore no need for this horrible == 0 thing.
pasky
parents: 1606
diff changeset
  3965
	if (!result) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3966
		grfmsg(2, "SkipIf: Not skipping sprites, test was false");
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3967
		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
  3968
	}
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
  3969
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3970
	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
  3971
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
  3972
	/* 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
  3973
	 * 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
  3974
	 * 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
  3975
	 * label in the file is used. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3976
	GRFLabel *choice = NULL;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  3977
	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
  3978
		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
  3979
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
  3980
		/* 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
  3981
		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
  3982
		/* 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
  3983
		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
  3984
			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
  3985
			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
  3986
		}
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
  3987
	}
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
  3988
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
  3989
	if (choice != NULL) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3990
		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
  3991
		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
  3992
		_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
  3993
		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
  3994
	}
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
  3995
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  3996
	grfmsg(2, "SkipIf: Skipping %d sprites, test was true", numsprites);
357
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3997
	_skip_sprites = numsprites;
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3998
	if (_skip_sprites == 0) {
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  3999
		/* Zero means there are no sprites to skip, so
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4000
		 * we use -1 to indicate that all further
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4001
		 * sprites should be skipped. */
912b71f33867 (svn r545) -newgrf: repaired indendation (pasky & octo)
celestar
parents: 356
diff changeset
  4002
		_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
  4003
14794ebde68e (svn r8831) -Feature: If an action 7/9 leads to skipping the rest of the file, disable the
maedhros
parents: 6421
diff changeset
  4004
		/* If an action 8 hasn't been encountered yet, disable the grf. */
8585
6579b0a2ba0e (svn r11650) -Fix: 'initialised' NewGRFs could still be deactivated in the later 'activation' pass.
rubidium
parents: 8580
diff changeset
  4005
		if (_cur_grfconfig->status != GCS_ACTIVATED) {
7421
094cf7e66ba8 (svn r10178) -Fix: Don't deactivate newgrf files when skipping the rest of the file during the initialisation stage.
maedhros
parents: 7410
diff changeset
  4006
			_cur_grfconfig->status = GCS_DISABLED;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  4007
			ClearTemporaryNewGRFData();
7421
094cf7e66ba8 (svn r10178) -Fix: Don't deactivate newgrf files when skipping the rest of the file during the initialisation stage.
maedhros
parents: 7410
diff changeset
  4008
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4009
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4010
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4011
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4012
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
  4013
/* Action 0x08 (GLS_FILESCAN) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4014
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
  4015
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4016
	if (!check_length(len, 8, "Info")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4017
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4018
	grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4019
	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
  4020
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4021
	_cur_grfconfig->grfid = grfid;
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4022
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
  4023
	/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  4024
	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
  4025
5317
e235a3a573e3 (svn r7475) -Fix (r7348): sanity check NewGRF action 8 strings for null terminator
peter1138
parents: 5306
diff changeset
  4026
	len -= 6;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4027
	const char *name = grf_load_string(&buf, len);
9152
35fa006cf0f0 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 9151
diff changeset
  4028
	_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
  4029
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
  4030
	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
  4031
	if (len > 0) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4032
		const char *info = grf_load_string(&buf, len);
9152
35fa006cf0f0 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 9151
diff changeset
  4033
		_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
  4034
	}
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
  4035
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
  4036
	/* 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
  4037
	_skip_sprites = -1;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4038
}
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  4039
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  4040
/* Action 0x08 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4041
static void GRFInfo(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4042
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4043
	/* <08> <version> <grf-id> <name> <info>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4044
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4045
	 * B version       newgrf version, currently 06
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4046
	 * 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
  4047
	 * S name          name of this .grf set
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4048
	 * 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
  4049
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4050
	if (!check_length(len, 8, "GRFInfo")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4051
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4052
	uint8 version    = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4053
	uint32 grfid     = grf_load_dword(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4054
	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
  4055
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
  4056
	_cur_grffile->grfid = grfid;
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  4057
	_cur_grffile->grf_version = version;
7302
7aa974539f27 (svn r10045) -Codechange: Process Action 8 during GLS_RESERVATION to allow Action 7/Action 9s to work properly
peter1138
parents: 7301
diff changeset
  4058
	_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
  4059
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
  4060
	/* Do swap the GRFID for displaying purposes since people expect that */
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  4061
	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
  4062
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4063
3640
b73687dd2b62 (svn r4549) - NewGRF: store the grf version from Action 0x08.
peter1138
parents: 3638
diff changeset
  4064
/* Action 0x0A */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4065
static void SpriteReplace(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4066
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4067
	/* <0A> <num-sets> <set1> [<set2> ...]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4068
	 * <set>: <num-sprites> <first-sprite>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4069
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4070
	 * 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
  4071
	 * Each set:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4072
	 * 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
  4073
	 * 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
  4074
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4075
	buf++; // skip action byte
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4076
	uint8 num_sets = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4077
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4078
	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
  4079
		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
  4080
		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
  4081
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4082
		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
  4083
			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
  4084
		);
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
  4085
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4086
		for (uint j = 0; j < num_sprites; j++) {
8679
2bc4cefab729 (svn r11746) -Fix(r11727): Make sure that action 0A does follow the same new ordering of shore sprites. It was not considered in the missing shore patch
belugas
parents: 8661
diff changeset
  4087
			int load_index = first_sprite + j;
8449
c5759019cbcd (svn r11509) -Fix: off-by-one error in some sprite numbers; increase sprite number counter before loading the next sprite instead of after doing so.
rubidium
parents: 8437
diff changeset
  4088
			_nfo_line++;
8679
2bc4cefab729 (svn r11746) -Fix(r11727): Make sure that action 0A does follow the same new ordering of shore sprites. It was not considered in the missing shore patch
belugas
parents: 8661
diff changeset
  4089
			LoadNextSprite(load_index, _file_index, _nfo_line); // XXX
2bc4cefab729 (svn r11746) -Fix(r11727): Make sure that action 0A does follow the same new ordering of shore sprites. It was not considered in the missing shore patch
belugas
parents: 8661
diff changeset
  4090
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  4091
			/* Shore sprites now located at different addresses.
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  4092
			 * So detect when the old ones get replaced. */
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  4093
			if (IsInsideMM(load_index, SPR_ORIGINALSHORE_START, SPR_ORIGINALSHORE_END + 1)) {
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  4094
				if (_loaded_newgrf_features.shore != SHORE_REPLACE_ACTION_5) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_A;
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  4095
			}
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
  4096
		}
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
  4097
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4098
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4099
7025
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4100
/* Action 0x0A (SKIP) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4101
static void SkipActA(byte *buf, size_t len)
7025
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4102
{
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4103
	buf++;
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4104
	uint8 num_sets = grf_load_byte(&buf);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4105
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4106
	for (uint i = 0; i < num_sets; i++) {
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4107
		/* Skip the sprites this replaces */
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4108
		_skip_sprites += grf_load_byte(&buf);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4109
		/* But ignore where they go */
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4110
		grf_load_word(&buf);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4111
	}
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4112
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4113
	grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites);
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4114
}
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  4115
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4116
/* Action 0x0B */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4117
static void GRFLoadError(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4118
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4119
	/* <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
  4120
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4121
	 * B severity      00: notice, contine loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4122
	 *                 01: warning, continue loading grf file
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4123
	 *                 02: error, but continue loading grf file, and attempt
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4124
	 *                     loading grf again when loading or starting next game
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4125
	 *                 03: error, abort loading and prevent loading again in
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4126
	 *                     the future (only when restarting the patch)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4127
	 * 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
  4128
	 * B message-id    message to show, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4129
	 * 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
  4130
	 *                 not present for built-in messages.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4131
	 * 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
  4132
	 * 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
  4133
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4134
	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
  4135
		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
  4136
		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
  4137
		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
  4138
		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
  4139
		STR_NEWGRF_ERROR_LOAD_BEFORE,
8276
1fe8700644de (svn r11330) -Add: OTTD version checking for NewGRFs. This allows NewGRFs to do something different for different versions of OpenTTD, like disabling it for too low versions or loading different graphics.
rubidium
parents: 8268
diff changeset
  4140
		STR_NEWGRF_ERROR_LOAD_AFTER,
1fe8700644de (svn r11330) -Add: OTTD version checking for NewGRFs. This allows NewGRFs to do something different for different versions of OpenTTD, like disabling it for too low versions or loading different graphics.
rubidium
parents: 8268
diff changeset
  4141
		STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4142
	};
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4143
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
  4144
	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
  4145
		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
  4146
		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
  4147
		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
  4148
		STR_NEWGRF_ERROR_MSG_FATAL
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4149
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4150
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
  4151
	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
  4152
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4153
	/* 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
  4154
	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
  4155
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4156
	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
  4157
	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
  4158
	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
  4159
	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
  4160
	len -= 4;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4161
7369
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  4162
	/* Skip the error if it isn't valid for the current language. */
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  4163
	if (!CheckGrfLangID(lang, _cur_grffile->grf_version)) return;
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  4164
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4165
	/* 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
  4166
	 * is set. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  4167
	if (!HasBit(severity, 7) && _cur_stage == GLS_INIT) {
7301
0e314c60f7a0 (svn r10044) -Fix: Minor NewGRF debug message fixes, and skip sprites of an unsupported Action 5 feature.
peter1138
parents: 7277
diff changeset
  4168
		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
  4169
		return;
3588
a1adf8a40756 (svn r4474) - NewGRF: Skip non-fatal errors when not in stage 2.
peter1138
parents: 3577
diff changeset
  4170
	}
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  4171
	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
  4172
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4173
	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
  4174
		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
  4175
		severity = 2;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4176
	} 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
  4177
		/* 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
  4178
		 * 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
  4179
		_cur_grfconfig->status = GCS_DISABLED;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  4180
		ClearTemporaryNewGRFData();
6421
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4181
		_skip_sprites = -1;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4182
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4183
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4184
	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
  4185
		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
  4186
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4187
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4188
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4189
	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
  4190
		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
  4191
		return;
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4192
	}
48a6f5c43920 (svn r8830) -Feature: Stop loading and disable the current newgrf if a fatal error message
maedhros
parents: 6417
diff changeset
  4193
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
  4194
	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
  4195
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4196
	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
  4197
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4198
	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
  4199
		/* 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
  4200
		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
  4201
		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
  4202
9152
35fa006cf0f0 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 9151
diff changeset
  4203
		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
  4204
	} 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
  4205
		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
  4206
	}
02c062eb2c74 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 6422
diff changeset
  4207
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
  4208
	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
  4209
		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
  4210
		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
  4211
9152
35fa006cf0f0 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 9151
diff changeset
  4212
		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
  4213
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4214
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4215
	/* 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
  4216
	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
  4217
	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
  4218
		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
  4219
		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
  4220
	}
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4221
	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
  4222
dddb39b41ee0 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6454
diff changeset
  4223
	_cur_grfconfig->error = error;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4224
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4225
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4226
/* Action 0x0C */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4227
static void GRFComment(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4228
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4229
	/* <0C> [<ignored...>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4230
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4231
	 * 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
  4232
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
  4233
	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
  4234
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4235
	size_t text_len = len - 1;
6433
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4236
	const char *text = (const char*)(buf + 1);
84cd6e4262fd (svn r8843) -Fix
tron
parents: 6429
diff changeset
  4237
	grfmsg(2, "GRFComment: %.*s", text_len, text);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4238
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4239
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
  4240
/* Action 0x0D (GLS_SAFETYSCAN) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4241
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
  4242
{
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
  4243
	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
  4244
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4245
	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
  4246
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
  4247
	/* 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
  4248
	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
  4249
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
  4250
	/* 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
  4251
	 * 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
  4252
	 * 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
  4253
	 * 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
  4254
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  4255
	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
  4256
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
  4257
	/* 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
  4258
	_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
  4259
}
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
  4260
7011
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4261
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4262
static uint32 GetPatchVariable(uint8 param)
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4263
{
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4264
	switch (param) {
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4265
		/* start year - 1920 */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  4266
		case 0x0B: return max(_settings_game.game_creation.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4267
7011
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4268
		/* freight trains weight factor */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  4269
		case 0x0E: return _settings_game.vehicle.freight_trains;
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4270
7011
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4271
		/* empty wagon speed increase */
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4272
		case 0x0F: return 0;
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4273
9145
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4274
		/* plane speed factor; our patch option is reversed from TTDPatch's,
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4275
		 * the following is good for 1x, 2x and 4x (most common?) and...
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4276
		 * well not really for 3x. */
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4277
		case 0x10:
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  4278
			switch (_settings_game.vehicle.plane_speed) {
9145
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4279
				default:
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4280
				case 4: return 1;
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4281
				case 3: return 2;
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4282
				case 2: return 2;
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4283
				case 1: return 4;
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4284
			}
d9831299672e (svn r12295) -Codechange: Make plane speed option available to NewGRFs
peter1138
parents: 9122
diff changeset
  4285
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4286
7011
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4287
		/* 2CC colormap base sprite */
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4288
		case 0x11: return SPR_2CCMAP_BASE;
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4289
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4290
		/* map size: format = -MABXYSS
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4291
		 * M  : the type of map
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4292
		 *       bit 0 : set   : squared map. Bit 1 is now not relevant
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4293
		 *               clear : rectangle map. Bit 1 will indicate the bigger edge of the map
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4294
		 *       bit 1 : set   : Y is the bigger edge. Bit 0 is clear
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4295
		 *               clear : X is the bigger edge.
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4296
		 * A  : minimum edge(log2) of the map
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4297
		 * B  : maximum edge(log2) of the map
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4298
		 * XY : edges(log2) of each side of the map.
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4299
		 * SS : combination of both X and Y, thus giving the size(log2) of the map
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4300
		 */
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4301
		case 0x13: {
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4302
			byte map_bits = 0;
8889
a3633be104ff (svn r11963) -Fix(r11961): Forgot to specify the meaning of the magical 6 substraction
belugas
parents: 8887
diff changeset
  4303
			byte log_X = MapLogX() - 6; // substraction is required to make the minimal size (64) zero based
8887
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4304
			byte log_Y = MapLogY() - 6;
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4305
			byte max_edge = max(log_X, log_Y);
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4306
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4307
			if (log_X == log_Y) { // we have a squared map, since both edges are identical
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4308
				SetBit(map_bits ,0);
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4309
			} else {
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4310
				if (max_edge == log_Y) SetBit(map_bits, 1); // edge Y been the biggest, mark it
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4311
			}
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4312
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4313
			return (map_bits << 24) | (min(log_X, log_Y) << 20) | (max_edge << 16) |
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4314
				(log_X << 12) | (log_Y << 8) | (log_X + log_Y);
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4315
		}
4bc5c9811562 (svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
belugas
parents: 8868
diff changeset
  4316
7011
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4317
		default:
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4318
			grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param);
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4319
			return 0;
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4320
	}
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4321
}
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4322
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4323
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4324
static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, uint8 target, const char *type)
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4325
{
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4326
	uint start = 0;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4327
	uint size  = 0;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4328
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4329
	if (op == 6) {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4330
		/* Return GRFID of set that reserved ID */
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4331
		return grm[_cur_grffile->param[target]];
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4332
	}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4333
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4334
	/* With an operation of 2 or 3, we want to reserve a specific block of IDs */
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4335
	if (op == 2 || op == 3) start = _cur_grffile->param[target];
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4336
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4337
	for (uint i = start; i < num_ids; i++) {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4338
		if (grm[i] == 0) {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4339
			size++;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4340
		} else {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4341
			if (op == 2 || op == 3) break;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4342
			start = i + 1;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4343
			size = 0;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4344
		}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4345
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4346
		if (size == count) break;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4347
	}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4348
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4349
	if (size == count) {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4350
		/* Got the slot... */
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4351
		if (op == 0 || op == 3) {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4352
			grfmsg(2, "ParamSet: GRM: Reserving %d %s at %d", count, type, start);
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4353
			for (uint i = 0; i < count; i++) grm[start + i] = _cur_grffile->grfid;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4354
		}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4355
		return start;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4356
	}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4357
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4358
	/* Unable to allocate */
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4359
	if (op != 4 && op != 5) {
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4360
		/* Deactivate GRF */
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4361
		grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4362
		_cur_grfconfig->status = GCS_DISABLED;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  4363
		ClearTemporaryNewGRFData();
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4364
		_skip_sprites = -1;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4365
		return UINT_MAX;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4366
	}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4367
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4368
	grfmsg(1, "ParamSet: GRM: Unable to allocate %d %s", count, type);
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4369
	return UINT_MAX;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4370
}
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4371
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4372
356
e3721e481b38 (svn r544) -newgrf: codechange for better handling (pasky and octo__)
celestar
parents: 193
diff changeset
  4373
/* Action 0x0D */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4374
static void ParamSet(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4375
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4376
	/* <0D> <target> <operation> <source1> <source2> [<data>]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4377
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4378
	 * B target        parameter number where result is stored
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4379
	 * B operation     operation to perform, see below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4380
	 * B source1       first source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4381
	 * B source2       second source operand
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4382
	 * 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
  4383
	 *                 if both source1 and source2 refer to actual parameters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4384
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4385
	 * Operations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4386
	 * 00      Set parameter equal to source1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4387
	 * 01      Addition, source1 + source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4388
	 * 02      Subtraction, source1 - source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4389
	 * 03      Unsigned multiplication, source1 * source2 (both unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4390
	 * 04      Signed multiplication, source1 * source2 (both signed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4391
	 * 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
  4392
	 *         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
  4393
	 *         negative, source1 is unsigned)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4394
	 * 06      Signed bit shift, source1 by source2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4395
	 *         (source2 like in 05, and source1 as well)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4396
	 */
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
  4397
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
  4398
	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
  4399
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4400
	uint8 target = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4401
	uint8 oper   = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4402
	uint32 src1  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4403
	uint32 src2  = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4404
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4405
	uint32 data = 0;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4406
	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
  4407
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
  4408
	/* 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
  4409
	 * 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
  4410
	 * 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
  4411
	 * - 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
  4412
	 * - 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
  4413
	 *   an earlier action D */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  4414
	if (HasBit(oper, 7)) {
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4415
		if (target < 0x80 && target < _cur_grffile->param_end) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  4416
			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
  4417
			return;
3807
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4418
		}
927ac7827a28 (svn r4817) - NewGRF: allow partial support for parameter retrieval in action D.
peter1138
parents: 3806
diff changeset
  4419
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4420
		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
  4421
	}
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
  4422
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
  4423
	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
  4424
		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
  4425
			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
  4426
				/* Patch variables */
7011
9a7685426523 (svn r9701) -Codechange: Add support for returning 'ttdpatch variables' - http://wiki.ttdpatch.net/tiki-index.php?page=ActionDSpecialVariables
peter1138
parents: 7003
diff changeset
  4427
				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
  4428
			} 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
  4429
				/* GRF Resource Management */
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4430
				uint8  op      = src1;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4431
				uint8  feature = GB(data, 8, 8);
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4432
				uint16 count   = GB(data, 16, 16);
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4433
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4434
				if (_cur_stage == GLS_RESERVE) {
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4435
					if (feature == 0x08) {
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4436
						/* General sprites */
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4437
						if (op == 0) {
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4438
							/* Check if the allocated sprites will fit below the original sprite limit */
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4439
							if (_cur_spriteid + count >= 16384) {
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4440
								grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4441
								_cur_grfconfig->status = GCS_DISABLED;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  4442
								ClearTemporaryNewGRFData();
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4443
								_skip_sprites = -1;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4444
								return;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4445
							}
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4446
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4447
							/* Reserve space at the current sprite ID */
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4448
							grfmsg(4, "ParamSet: GRM: Allocated %d sprites at %d", count, _cur_spriteid);
10431
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
  4449
							_grm_sprites[GRFLocation(_cur_grffile->grfid, _nfo_line)] = _cur_spriteid;
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4450
							_cur_spriteid += count;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4451
						}
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4452
					}
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4453
					/* Ignore GRM result during reservation */
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4454
					src1 = 0;
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4455
				} 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
  4456
					switch (feature) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4457
						case 0x00: // Trains
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4458
						case 0x01: // Road Vehicles
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4459
						case 0x02: // Ships
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4460
						case 0x03: // Aircraft
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  4461
							if (!_settings_game.vehicle.dynamic_engines) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4462
								src1 = PerformGRM(&_grm_engines[_engine_offsets[feature]], _engine_counts[feature], count, op, target, "vehicles");
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4463
								if (_skip_sprites == -1) return;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4464
							} else {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4465
								// GRM does not apply for dynamic engine allocation.
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4466
								switch (op) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4467
									case 2:
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4468
									case 3:
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4469
										src1 = _cur_grffile->param[target];
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4470
										break;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4471
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4472
									default:
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4473
										src1 = 0;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4474
										break;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4475
								}
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  4476
							}
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4477
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4478
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4479
						case 0x08: // General sprites
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4480
							switch (op) {
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4481
								case 0:
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4482
									/* Return space reserved during reservation stage */
10431
2cc3740f3527 (svn r12973) -Codechange: Rename GRMSpriteEntry to GRFLocation, as it is not necessarily specific to GRM sprites...
peter1138
parents: 10429
diff changeset
  4483
									src1 = _grm_sprites[GRFLocation(_cur_grffile->grfid, _nfo_line)];
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4484
									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
  4485
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4486
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4487
								case 1:
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4488
									src1 = _cur_spriteid;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4489
									break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4490
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4491
								default:
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  4492
									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
  4493
									return;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4494
							}
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4495
							break;
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4496
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4497
						case 0x0B: // Cargo
8186
a5c489500f23 (svn r11224) -Fix: GRM for cargos has registration entries for both cargo IDs and cargo bitmasks, not only cargo IDs.
rubidium
parents: 8170
diff changeset
  4498
							/* There are two ranges: one for cargo IDs and one for cargo bitmasks */
a5c489500f23 (svn r11224) -Fix: GRM for cargos has registration entries for both cargo IDs and cargo bitmasks, not only cargo IDs.
rubidium
parents: 8170
diff changeset
  4499
							src1 = PerformGRM(_grm_cargos, NUM_CARGO * 2, count, op, target, "cargos");
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4500
							if (_skip_sprites == -1) return;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4501
							break;
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  4502
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  4503
						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
  4504
					}
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4505
				} else {
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4506
					/* Ignore GRM during initialization */
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  4507
					src1 = 0;
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  4508
				}
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
  4509
			}
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
  4510
		} 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
  4511
			/* 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
  4512
			const GRFFile *file = GetFileByGRFID(data);
11020
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  4513
			GRFConfig *c = GetGRFConfig(data);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  4514
			if (c != NULL && HasBit(c->status, GCF_STATIC) && !HasBit(_cur_grfconfig->status, GCF_STATIC) && _networking) {
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  4515
				/* Disable the read GRF if it is a static NewGRF. */
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  4516
				DisableStaticNewGRFInfluencingNonStaticNewGRFs(c);
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  4517
				src1 = 0;
e5f91b9e33f8 (svn r13576) -Codechange: disable static NewGRFs when non-static NewGRFs query them in the context of network games. This makes it impossible for static NewGRFs to disable non-static NewGRFs and 'bad' things happening because the non-static NewGRF doesn't know about the static NewGRF.
rubidium
parents: 10929
diff changeset
  4518
			} else if (file == NULL || src1 >= file->param_end || (c != NULL && c->status == GCS_DISABLED)) {
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
  4519
				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
  4520
			} 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
  4521
				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
  4522
			}
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
  4523
		}
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
  4524
	} 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
  4525
		/* 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
  4526
		 * 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
  4527
		 * 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
  4528
		 * 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
  4529
		 * of 0 is used instead.  */
3811
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4530
		src1 = (src1 == 0xFF) ? data : GetParamVal(src1, NULL);
7324eb563ae0 (svn r4821) - NewGRF: simplify parameter retrieval in Action 0x0D
peter1138
parents: 3808
diff changeset
  4531
		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
  4532
	}
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
  4533
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
  4534
	/* 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
  4535
	 * 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
  4536
	 * 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
  4537
	 * 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
  4538
	 * 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
  4539
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4540
	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
  4541
	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
  4542
		case 0x00:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4543
			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
  4544
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4545
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4546
		case 0x01:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4547
			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
  4548
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4549
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4550
		case 0x02:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4551
			res = src1 - src2;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4552
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4553
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
  4554
		case 0x03:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4555
			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
  4556
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4557
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
  4558
		case 0x04:
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4559
			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
  4560
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4561
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
  4562
		case 0x05:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4563
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4564
				res = src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4565
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4566
				res = src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4567
			}
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
  4568
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4569
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
  4570
		case 0x06:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4571
			if ((int32)src2 < 0) {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4572
				res = (int32)src1 >> -(int32)src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4573
			} else {
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4574
				res = (int32)src1 << src2;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3997
diff changeset
  4575
			}
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
  4576
			break;
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4577
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4578
		case 0x07: // Bitwise AND
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4579
			res = src1 & src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4580
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4581
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4582
		case 0x08: // Bitwise OR
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4583
			res = src1 | src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4584
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4585
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4586
		case 0x09: // Unsigned division
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4587
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4588
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4589
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4590
				res = src1 / src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4591
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4592
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4593
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4594
		case 0x0A: // Signed divison
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4595
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4596
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4597
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4598
				res = (int32)src1 / (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4599
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4600
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4601
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4602
		case 0x0B: // Unsigned modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4603
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4604
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4605
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4606
				res = src1 % src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4607
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4608
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4609
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4610
		case 0x0C: // Signed modulo
2442
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4611
			if (src2 == 0) {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4612
				res = src1;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4613
			} else {
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4614
				res = (int32)src1 % (int32)src2;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4615
			}
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4616
			break;
da9a2075c747 (svn r2968) -Newgrf: Implement current set of action D (ParamSet) operations.
peter1138
parents: 2440
diff changeset
  4617
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4618
		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
  4619
	}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4620
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4621
	switch (target) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4622
		case 0x8E: // Y-Offset for train sprites
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4623
			_traininfo_vehicle_pitch = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4624
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4625
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4626
		case 0x8F: // Rail track type cost factors
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4627
			_railtype_cost_multiplier[0] = GB(res, 0, 8);
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  4628
			if (_settings_game.vehicle.disable_elrails) {
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4629
				_railtype_cost_multiplier[1] = GB(res, 0, 8);
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4630
				_railtype_cost_multiplier[2] = GB(res, 8, 8);
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4631
			} else {
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4632
				_railtype_cost_multiplier[1] = GB(res, 8, 8);
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4633
				_railtype_cost_multiplier[2] = GB(res, 16, 8);
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4634
			}
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4635
			_railtype_cost_multiplier[3] = GB(res, 16, 8);
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4636
			break;
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  4637
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4638
		/* @todo implement */
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4639
		case 0x93: // Tile refresh offset to left
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4640
		case 0x94: // Tile refresh offset to right
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4641
		case 0x95: // Tile refresh offset upwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4642
		case 0x96: // Tile refresh offset downwards
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4643
		case 0x97: // Snow line height
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4644
		case 0x99: // Global ID offset
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4645
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4646
			break;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4647
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4648
		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
  4649
			_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
  4650
			/* Set train list engine width */
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 7029
diff changeset
  4651
			_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
  4652
			break;
d0b901dfc313 (svn r4824) - NewGRF: add support for getting/setting miscellaneous grf flags (param 0x9E)
peter1138
parents: 3811
diff changeset
  4653
9042
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  4654
		case 0x9F: // locale-dependent settings
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  4655
			grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target);
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  4656
			break;
28aab5504e15 (svn r12124) -Codechange: Move newgrf-variables that are common to VarAction2 and Action7/9/D to their own function.
frosch
parents: 9040
diff changeset
  4657
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4658
		default:
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4659
			if (target < 0x80) {
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4660
				_cur_grffile->param[target] = res;
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4661
				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
  4662
			} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4663
				grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target);
2345
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4664
			}
8a14ff5d4851 (svn r2871) -Feature/Fix: Per GRF parameter lists
tron
parents: 2342
diff changeset
  4665
			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
  4666
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4667
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4668
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
  4669
/* Action 0x0E (GLS_SAFETYSCAN) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4670
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
  4671
{
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
  4672
	/* <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
  4673
	 *
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
  4674
	 * 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
  4675
	 * 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
  4676
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4677
	if (!check_length(len, 2, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4678
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4679
	uint8 num = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4680
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4681
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4682
	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
  4683
		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
  4684
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
  4685
		/* 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
  4686
		if (grfid != _cur_grfconfig->grfid) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  4687
			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
  4688
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
  4689
			/* 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
  4690
			_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
  4691
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
  4692
			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
  4693
		}
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
  4694
	}
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
  4695
}
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
  4696
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4697
/* Action 0x0E */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4698
static void GRFInhibit(byte *buf, size_t len)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4699
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4700
	/* <0E> <num> <grfids...>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4701
	 *
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4702
	 * B num           Number of GRFIDs that follow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4703
	 * 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
  4704
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4705
	if (!check_length(len, 2, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4706
	buf++;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4707
	uint8 num = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4708
	if (!check_length(len, 2 + 4 * num, "GRFInhibit")) return;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4709
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4710
	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
  4711
		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
  4712
		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
  4713
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
  4714
		/* 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
  4715
		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
  4716
			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
  4717
			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
  4718
		}
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
  4719
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4720
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  4721
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4722
/* Action 0x0F */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4723
static void FeatureTownName(byte *buf, size_t len)
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4724
{
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4725
	/* <0F> <id> <style-name> <num-parts> <parts>
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4726
	 *
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4727
	 * B id          ID of this definition in bottom 7 bits (final definition if bit 7 set)
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4728
	 * V style-name  Name of the style (only for final definition)
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4729
	 * B num-parts   Number of parts in this definition
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4730
	 * V parts       The parts */
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4731
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4732
	if (!check_length(len, 1, "FeatureTownName: definition ID")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4733
	buf++; len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4734
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4735
	uint32 grfid = _cur_grffile->grfid;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4736
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4737
	GRFTownName *townname = AddGRFTownName(grfid);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4738
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4739
	byte id = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4740
	len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4741
	grfmsg(6, "FeatureTownName: definition 0x%02X", id & 0x7F);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4742
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  4743
	if (HasBit(id, 7)) {
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4744
		/* Final definition */
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  4745
		ClrBit(id, 7);
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4746
		bool new_scheme = _cur_grffile->grf_version >= 7;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4747
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4748
		if (!check_length(len, 1, "FeatureTownName: lang_id")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4749
		byte lang = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4750
		len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4751
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4752
		byte nb_gen = townname->nb_gen;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4753
		do {
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  4754
			ClrBit(lang, 7);
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4755
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4756
			if (!check_length(len, 1, "FeatureTownName: style name")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4757
			const char *name = grf_load_string(&buf, len);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4758
			len -= strlen(name) + 1;
9152
35fa006cf0f0 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 9151
diff changeset
  4759
			grfmsg(6, "FeatureTownName: lang 0x%X -> '%s'", lang, TranslateTTDPatchCodes(grfid, name));
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4760
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4761
			townname->name[nb_gen] = AddGRFString(grfid, id, lang, new_scheme, name, STR_UNDEFINED);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4762
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4763
			if (!check_length(len, 1, "FeatureTownName: lang_id")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4764
			lang = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4765
			len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4766
		} while (lang != 0);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4767
		townname->id[nb_gen] = id;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4768
		townname->nb_gen++;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4769
	}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4770
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4771
	if (!check_length(len, 1, "FeatureTownName: number of parts")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4772
	byte nb = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4773
	len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4774
	grfmsg(6, "FeatureTownName: %d parts", nb, nb);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4775
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4776
	townname->nbparts[id] = nb;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4777
	townname->partlist[id] = CallocT<NamePartList>(nb);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4778
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4779
	for (int i = 0; i < nb; i++) {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4780
		if (!check_length(len, 3, "FeatureTownName: parts header")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4781
		byte nbtext =  grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4782
		townname->partlist[id][i].bitstart  = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4783
		townname->partlist[id][i].bitcount  = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4784
		townname->partlist[id][i].maxprob   = 0;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4785
		townname->partlist[id][i].partcount = nbtext;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4786
		townname->partlist[id][i].parts     = CallocT<NamePart>(nbtext);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4787
		len -= 3;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4788
		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);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4789
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4790
		for (int j = 0; j < nbtext; j++) {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4791
			if (!check_length(len, 2, "FeatureTownName: part")) return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4792
			byte prob = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4793
			len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4794
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  4795
			if (HasBit(prob, 7)) {
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4796
				byte ref_id = grf_load_byte(&buf);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4797
				len--;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4798
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4799
				if (townname->nbparts[ref_id] == 0) {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4800
					grfmsg(0, "FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4801
					DelGRFTownName(grfid);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4802
					_cur_grfconfig->status = GCS_DISABLED;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  4803
					ClearTemporaryNewGRFData();
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4804
					_skip_sprites = -1;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4805
					return;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4806
				}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4807
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4808
				grfmsg(6, "FeatureTownName: part %d, text %d, uses intermediate definition 0x%02X (with probability %d)", i, j, ref_id, prob & 0x7F);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4809
				townname->partlist[id][i].parts[j].data.id = ref_id;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4810
			} else {
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4811
				const char *text = grf_load_string(&buf, len);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4812
				len -= strlen(text) + 1;
9152
35fa006cf0f0 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 9151
diff changeset
  4813
				townname->partlist[id][i].parts[j].data.text = TranslateTTDPatchCodes(grfid, text);
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4814
				grfmsg(6, "FeatureTownName: part %d, text %d, '%s' (with probability %d)", i, j, townname->partlist[id][i].parts[j].data.text, prob);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4815
			}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4816
			townname->partlist[id][i].parts[j].prob = prob;
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4817
			townname->partlist[id][i].maxprob += GB(prob, 0, 7);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4818
		}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4819
		grfmsg(6, "FeatureTownName: part %d, total probability %d", i, townname->partlist[id][i].maxprob);
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4820
	}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4821
}
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  4822
3715
dd9807bf5927 (svn r4658) - NewGRF: add Action 0xNN comments before each action handler. This mainly aids code navigation...
peter1138
parents: 3714
diff changeset
  4823
/* Action 0x10 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4824
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
  4825
{
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
  4826
	/* <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
  4827
	 *
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
  4828
	 * 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
  4829
	 * 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
  4830
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
  4831
	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
  4832
	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
  4833
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4834
	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
  4835
	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
  4836
	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
  4837
	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
  4838
	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
  4839
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
  4840
	/* 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
  4841
	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
  4842
		_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
  4843
	} 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
  4844
		/* 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
  4845
		GRFLabel *l;
9191
ae14770c829a (svn r12368) -Codechange: use explicit body for loops and conditions and remove -Wno-empty-body from the configure script
smatz
parents: 9171
diff changeset
  4846
		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
  4847
		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
  4848
	}
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
  4849
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4850
	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
  4851
}
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
  4852
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4853
/* Action 0x11 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4854
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
  4855
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4856
	/* <11> <num>
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4857
	 *
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4858
	 * 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
  4859
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
  4860
	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
  4861
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4862
	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
  4863
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4864
	_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
  4865
	_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
  4866
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4867
	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
  4868
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4869
8927
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4870
/* Action 0x11 (SKIP) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4871
static void SkipAct11(byte *buf, size_t len)
8927
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4872
{
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4873
	/* <11> <num>
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4874
	 *
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4875
	 * W num      Number of sound files that follow */
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4876
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4877
	if (!check_length(len, 1, "SkipAct11")) return;
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4878
	buf++;
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4879
	_skip_sprites = grf_load_word(&buf);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4880
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4881
	grfmsg(3, "SkipAct11: Skipping %d sprites", _skip_sprites);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4882
}
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  4883
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4884
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
  4885
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4886
	const GRFFile *file;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4887
	FileEntry *se = AllocateFileEntry();
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4888
	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
  4889
	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
  4890
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4891
	file = GetFileByGRFID(grfid);
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4892
	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
  4893
		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
  4894
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4895
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4896
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4897
	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
  4898
		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
  4899
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4900
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4901
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4902
	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
  4903
5024
f13f2f2d43f9 (svn r7065) Use simple assignment instead of memcpy()
tron
parents: 5011
diff changeset
  4904
	*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
  4905
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4906
	/* 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
  4907
	se->volume   = 128;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4908
	se->priority = 0;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4909
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4910
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4911
/* 'Action 0xFE' */
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4912
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
  4913
{
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4914
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4915
		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
  4916
		return;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4917
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4918
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4919
	buf++;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4920
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4921
	_grf_data_blocks--;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4922
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4923
	/* 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
  4924
	 * 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
  4925
	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
  4926
		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
  4927
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4928
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4929
	switch (_grf_data_type) {
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4930
		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
  4931
		default: NOT_REACHED(); break;
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4932
	}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4933
}
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  4934
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4935
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
  4936
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4937
	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
  4938
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4939
	/* 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
  4940
	 * so that the indices used elsewhere are still correct. */
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  4941
	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
  4942
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4943
	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
  4944
		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
  4945
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4946
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4947
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4948
	/* 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
  4949
	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
  4950
5567
2af6b4aa2833 (svn r7564) -Codechange: Some newgrf changes. FFIR/EVAW endian-swapping, functionalize
Darkvater
parents: 5557
diff changeset
  4951
	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
  4952
		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
  4953
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4954
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4955
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4956
	for (;;) {
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4957
		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
  4958
		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
  4959
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4960
		switch (tag) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4961
			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
  4962
				/* 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
  4963
				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
  4964
					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
  4965
					return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4966
				}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4967
				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
  4968
				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
  4969
				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
  4970
				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
  4971
				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
  4972
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4973
				/* 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
  4974
				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
  4975
				break;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4976
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  4977
			case 'atad': // 'data'
8066
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7955
diff changeset
  4978
				se->file_size   = size;
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7955
diff changeset
  4979
				se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
7acd480e05c9 (svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
truelight
parents: 7955
diff changeset
  4980
				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
  4981
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4982
				/* 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
  4983
				se->volume = 0x80;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4984
				se->priority = 0;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4985
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  4986
				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
  4987
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4988
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4989
			default:
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4990
				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
  4991
				return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4992
		}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4993
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4994
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  4995
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
  4996
/* Action 0x12 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  4997
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
  4998
{
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
  4999
	/* <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
  5000
	 *
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
  5001
	 * 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
  5002
	 * 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
  5003
	 * 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
  5004
	 * 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
  5005
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
  5006
	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
  5007
	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
  5008
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5009
	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
  5010
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
  5011
	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
  5012
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5013
	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
  5014
		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
  5015
		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
  5016
		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
  5017
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5018
		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
  5019
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5020
		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
  5021
			SetUnicodeGlyph(size, base_char + c, _cur_spriteid);
8449
c5759019cbcd (svn r11509) -Fix: off-by-one error in some sprite numbers; increase sprite number counter before loading the next sprite instead of after doing so.
rubidium
parents: 8437
diff changeset
  5022
			_nfo_line++;
7404
fc0559157f16 (svn r10157) -Fix: use as indentified for PNGs, the place of the image as it was in the grf, not the internal SpriteID
truelight
parents: 7390
diff changeset
  5023
			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
  5024
		}
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
  5025
	}
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
  5026
}
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
  5027
8927
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5028
/* Action 0x12 (SKIP) */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  5029
static void SkipAct12(byte *buf, size_t len)
8927
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5030
{
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5031
	/* <12> <num_def> <font_size> <num_char> <base_char>
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5032
	 *
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5033
	 * B num_def      Number of definitions
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5034
	 * B font_size    Size of font (0 = normal, 1 = small, 2 = large)
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5035
	 * B num_char     Number of consecutive glyphs
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5036
	 * W base_char    First character index */
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5037
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5038
	buf++; len--;
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5039
	if (!check_length(len, 1, "SkipAct12")) return;
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5040
	uint8 num_def = grf_load_byte(&buf);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5041
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5042
	if (!check_length(len, 1 + num_def * 4, "SkipAct12")) return;
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5043
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5044
	for (uint i = 0; i < num_def; i++) {
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5045
		/* Ignore 'size' byte */
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5046
		grf_load_byte(&buf);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5047
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5048
		/* Sum up number of characters */
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5049
		_skip_sprites += grf_load_byte(&buf);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5050
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5051
		/* Ignore 'base_char' word */
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5052
		grf_load_word(&buf);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5053
	}
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5054
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5055
	grfmsg(3, "SkipAct12: Skipping %d sprites", _skip_sprites);
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5056
}
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5057
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5058
/* Action 0x13 */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  5059
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
  5060
{
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5061
	/* <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
  5062
	 *
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5063
	 * 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
  5064
	 * 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
  5065
	 * 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
  5066
	 * 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
  5067
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5068
	buf++; len--;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5069
	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
  5070
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5071
	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
  5072
	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
  5073
	if (c == NULL || (c->status != GCS_INITIALISED && c->status != GCS_ACTIVATED)) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5074
		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
  5075
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5076
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5077
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5078
	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
  5079
		/* 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
  5080
		 * and disable this file. */
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5081
		GRFError *error = CallocT<GRFError>(1);
7369
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5082
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5083
		char tmp[256];
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5084
		GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5085
		error->data = strdup(tmp);
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5086
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5087
		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
  5088
		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
  5089
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5090
		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
  5091
		_cur_grfconfig->error = error;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5092
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5093
		_cur_grfconfig->status = GCS_DISABLED;
11117
cb9c1d913f92 (svn r13675) -Fix: memory leak when NewGRFs got forcefully disabled and they defined GOTO labels.
rubidium
parents: 11038
diff changeset
  5094
		ClearTemporaryNewGRFData();
6560
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5095
		_skip_sprites = -1;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5096
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5097
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5098
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5099
	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
  5100
	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
  5101
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5102
	if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD3FF) || (first_id >= 0xDC00 && first_id + num_strings <= 0xDCFF))) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5103
		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
  5104
		return;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5105
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5106
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5107
	len -= 7;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5108
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5109
	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
  5110
		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
  5111
		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
  5112
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5113
		len -= (int)string_length;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5114
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5115
		if (string_length == 1) {
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5116
			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
  5117
			continue;
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5118
		}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5119
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5120
		/* 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
  5121
		 * 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
  5122
		 * 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
  5123
		 * 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
  5124
		 * 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
  5125
		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
  5126
	}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5127
}
ff59c862deae (svn r9037) -Feature: [NewGRF] Add support for Action 13, which allows you to translate
maedhros
parents: 6555
diff changeset
  5128
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5129
/* 'Action 0xFF' */
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5130
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
  5131
{
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5132
	if (_grf_data_blocks == 0) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5133
		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
  5134
		return;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5135
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5136
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5137
	buf++;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5138
	uint8 name_len = grf_load_byte(&buf);
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5139
	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
  5140
	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
  5141
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5142
	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
  5143
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5144
	_grf_data_blocks--;
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5145
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5146
	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
  5147
		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
  5148
		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
  5149
	}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5150
}
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5151
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
  5152
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
  5153
/* Used during safety scan on unsafe actions */
10465
0c68afe3d725 (svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents: 10431
diff changeset
  5154
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
  5155
{
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  5156
	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
  5157
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
  5158
	/* 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
  5159
	_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
  5160
}
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
  5161
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
  5162
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5163
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
  5164
{
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5165
	_ttdpatch_flags[0] =  ((_settings_game.station.always_small_airport ? 1 : 0) << 0x0C)  // keepsmallairport
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5166
	                   |                                                 (1 << 0x0D)  // newairports
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5167
	                   |                                                 (1 << 0x0E)  // largestations
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5168
	                   |      ((_settings_game.construction.longbridges ? 1 : 0) << 0x0F)  // longbridges
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5169
	                   |                                                 (0 << 0x10)  // loadtime
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5170
	                   |                                                 (1 << 0x12)  // presignals
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5171
	                   |                                                 (1 << 0x13)  // extpresignals
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5172
	                   | ((_settings_game.vehicle.never_expire_vehicles ? 1 : 0) << 0x16)  // enginespersist
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5173
	                   |                                                 (1 << 0x1B)  // multihead
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5174
	                   |                                                 (1 << 0x1D)  // lowmemory
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5175
	                   |                                                 (1 << 0x1E); // generalfixes
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5176
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5177
	_ttdpatch_flags[1] =   ((_settings_game.economy.station_noise_level ? 1 : 0) << 0x07)  // moreairports - based on units of noise
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5178
	                   |        ((_settings_game.vehicle.mammoth_trains ? 1 : 0) << 0x08)  // mammothtrains
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5179
	                   |                                                 (1 << 0x09)  // trainrefit
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5180
	                   |                                                 (0 << 0x0B)  // subsidiaries
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5181
	                   |         ((_settings_game.order.gradual_loading ? 1 : 0) << 0x0C)  // gradualloading
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5182
	                   |                                                 (1 << 0x12)  // unifiedmaglevmode - set bit 0 mode. Not revelant to OTTD
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5183
	                   |                                                 (1 << 0x13)  // unifiedmaglevmode - set bit 1 mode
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5184
	                   |                                                 (1 << 0x14)  // bridgespeedlimits
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5185
	                   |                                                 (1 << 0x16)  // eternalgame
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5186
	                   |                                                 (1 << 0x17)  // newtrains
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5187
	                   |                                                 (1 << 0x18)  // newrvs
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5188
	                   |                                                 (1 << 0x19)  // newships
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5189
	                   |                                                 (1 << 0x1A)  // newplanes
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5190
	                   |      ((_settings_game.construction.signal_side ? 1 : 0) << 0x1B)  // signalsontrafficside
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5191
	                   |       ((_settings_game.vehicle.disable_elrails ? 0 : 1) << 0x1C); // electrifiedrailway
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5192
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5193
	_ttdpatch_flags[2] =                                                 (1 << 0x01)  // loadallgraphics - obsolote
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5194
	                   |                                                 (1 << 0x03)  // semaphores
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5195
	                   |                                                 (0 << 0x0B)  // enhancedgui
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5196
	                   |                                                 (0 << 0x0C)  // newagerating
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5197
	                   |  ((_settings_game.construction.build_on_slopes ? 1 : 0) << 0x0D)  // buildonslopes
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5198
	                   |                                                 (1 << 0x0E)  // fullloadany
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5199
	                   |                                                 (1 << 0x0F)  // planespeed
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5200
	                   |                                                 (0 << 0x10)  // moreindustriesperclimate - obsolete
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5201
	                   |                                                 (0 << 0x11)  // moretoylandfeatures
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5202
	                   |                                                 (1 << 0x12)  // newstations
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5203
	                   |                                                 (1 << 0x13)  // tracktypecostdiff
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5204
	                   |                                                 (1 << 0x14)  // manualconvert
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5205
	                   |  ((_settings_game.construction.build_on_slopes ? 1 : 0) << 0x15)  // buildoncoasts
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5206
	                   |                                                 (1 << 0x16)  // canals
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5207
	                   |                                                 (1 << 0x17)  // newstartyear
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5208
	                   |    ((_settings_game.vehicle.freight_trains > 1 ? 1 : 0) << 0x18)  // freighttrains
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5209
	                   |                                                 (1 << 0x19)  // newhouses
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5210
	                   |                                                 (1 << 0x1A)  // newbridges
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5211
	                   |                                                 (1 << 0x1B)  // newtownnames
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5212
	                   |                                                 (1 << 0x1C)  // moreanimation
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5213
	                   |    ((_settings_game.vehicle.wagon_speed_limits ? 1 : 0) << 0x1D)  // wagonspeedlimits
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5214
	                   |                                                 (1 << 0x1E)  // newshistory
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5215
	                   |                                                 (0 << 0x1F); // custombridgeheads
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5216
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5217
	_ttdpatch_flags[3] =                                                 (0 << 0x00)  // newcargodistribution
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5218
	                   |                                                 (1 << 0x01)  // windowsnap
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5219
	                   |                                                 (0 << 0x02)  // townbuildnoroad
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5220
	                   |                                                 (0 << 0x03)  // pathbasedsignalling. To enable if ever pbs is back
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5221
	                   |                                                 (0 << 0x04)  // aichoosechance
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5222
	                   |                                                 (1 << 0x05)  // resolutionwidth
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5223
	                   |                                                 (1 << 0x06)  // resolutionheight
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5224
	                   |                                                 (1 << 0x07)  // newindustries
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5225
	                   |           ((_settings_game.order.improved_load ? 1 : 0) << 0x08)  // fifoloading
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5226
	                   |                                                 (0 << 0x09)  // townroadbranchprob
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5227
	                   |                                                 (0 << 0x0A)  // tempsnowline
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5228
	                   |                                                 (1 << 0x0B)  // newcargo
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5229
	                   |                                                 (1 << 0x0C)  // enhancemultiplayer
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5230
	                   |                                                 (1 << 0x0D)  // onewayroads
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5231
	                   |   ((_settings_game.station.nonuniform_stations ? 1 : 0) << 0x0E)  // irregularstations
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5232
	                   |                                                 (1 << 0x0F)  // statistics
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5233
	                   |                                                 (1 << 0x10)  // newsounds
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5234
	                   |                                                 (1 << 0x11)  // autoreplace
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5235
	                   |                                                 (1 << 0x12)  // autoslope
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5236
	                   |                                                 (0 << 0x13)  // followvehicle
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5237
	                   |                                                 (1 << 0x14)  // trams
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5238
	                   |                                                 (0 << 0x15)  // enhancetunnels
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5239
	                   |                                                 (1 << 0x16)  // shortrvs
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5240
	                   |                                                 (1 << 0x17)  // articulatedrvs
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5241
	                   |       ((_settings_game.vehicle.dynamic_engines ? 1 : 0) << 0x18)  // dynamic engines
10703
2c998f3776d1 (svn r13251) -Codechange: rename _patches to _settings as that is more logic.
rubidium
parents: 10682
diff changeset
  5242
	                   |                                                 (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
  5243
}
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
  5244
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5245
static void ResetCustomStations()
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5246
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5247
	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
  5248
		if (file->stations == NULL) continue;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5249
		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
  5250
			if (file->stations[i] == NULL) continue;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5251
			StationSpec *statspec = file->stations[i];
3740
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5252
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5253
			/* 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
  5254
			if (!statspec->copied_renderdata) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5255
				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
  5256
					free((void*)statspec->renderdata[t].seq);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5257
				}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5258
				free(statspec->renderdata);
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5259
			}
00a9594628b1 (svn r4722) - Newstations: release station sprite layout data when uninitializing NewGRF data.
peter1138
parents: 3738
diff changeset
  5260
5061
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5261
			/* Release platforms and layouts */
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5262
			if (!statspec->copied_layouts) {
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5263
				for (uint l = 0; l < statspec->lengths; l++) {
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5264
					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
  5265
						free(statspec->layouts[l][p]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5266
					}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5267
					free(statspec->layouts[l]);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5268
				}
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5269
				free(statspec->layouts);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5270
				free(statspec->platforms);
cb097749d18f (svn r7114) -Codechange: [NewStations] Free up custom station layouts
peter1138
parents: 5060
diff changeset
  5271
			}
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
  5272
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
  5273
			/* 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
  5274
			free(statspec);
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5275
		}
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
  5276
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
  5277
		/* 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
  5278
		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
  5279
		file->stations = NULL;
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5280
	}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5281
}
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5282
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5283
static void ResetCustomHouses()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5284
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5285
	GRFFile *file;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5286
	uint i;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5287
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5288
	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
  5289
		if (file->housespec == NULL) continue;
7344
72e3e8607419 (svn r10088) -Codechange: A typo and a code-style
belugas
parents: 7330
diff changeset
  5290
		for (i = 0; i < HOUSE_MAX; i++) {
72e3e8607419 (svn r10088) -Codechange: A typo and a code-style
belugas
parents: 7330
diff changeset
  5291
			free(file->housespec[i]);
72e3e8607419 (svn r10088) -Codechange: A typo and a code-style
belugas
parents: 7330
diff changeset
  5292
		}
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5293
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5294
		free(file->housespec);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5295
		file->housespec = NULL;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5296
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5297
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5298
7255
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5299
static void ResetCustomIndustries()
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5300
{
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5301
	GRFFile *file;
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5302
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5303
	for (file = _first_grffile; file != NULL; file = file->next) {
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5304
		uint i;
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5305
		/* We are verifiying both tiles and industries specs loaded from the grf file
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5306
		 * First, let's deal with industryspec */
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5307
		if (file->industryspec != NULL) {
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5308
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5309
			for (i = 0; i < NUM_INDUSTRYTYPES; i++) {
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5310
				IndustrySpec *ind = file->industryspec[i];
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5311
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5312
				if (ind != NULL) {
7261
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5313
					/* We need to remove the sounds array */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  5314
					if (HasBit(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
7261
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5315
						free((void*)ind->random_sounds);
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5316
					}
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5317
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5318
					/* We need to remove the tiles layouts */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  5319
					if (HasBit(ind->cleanup_flag, CLEAN_TILELSAYOUT) && ind->table != NULL) {
7261
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5320
						for (int j = 0; j < ind->num_table; j++) {
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5321
							/* remove the individual layouts */
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5322
							if (ind->table[j] != NULL) {
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5323
								free((IndustryTileTable*)ind->table[j]);
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5324
							}
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5325
						}
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5326
						/* remove the layouts pointers */
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5327
						free((IndustryTileTable**)ind->table);
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5328
						ind->table = NULL;
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5329
					}
a75c5668b75b (svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
belugas
parents: 7260
diff changeset
  5330
7255
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5331
					free(ind);
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5332
					ind = NULL;
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5333
				}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5334
			}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5335
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5336
			free(file->industryspec);
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5337
			file->industryspec = NULL;
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5338
		}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5339
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5340
		if (file->indtspec != NULL) {
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5341
			for (i = 0; i < NUM_INDUSTRYTILES; i++) {
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5342
				if (file->indtspec[i] != NULL) {
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5343
					free(file->indtspec[i]);
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5344
					file->indtspec[i] = NULL;
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5345
				}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5346
			}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5347
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5348
			free(file->indtspec);
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5349
			file->indtspec = NULL;
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5350
		}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5351
	}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5352
}
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5353
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5354
static void ResetNewGRF()
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5355
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5356
	GRFFile *next;
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5357
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5358
	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
  5359
		next = f->next;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5360
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5361
		free(f->filename);
7180
6ecf06dd7299 (svn r9916) -Codechange: Free memory used by cargo translation tables
peter1138
parents: 7155
diff changeset
  5362
		free(f->cargo_list);
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5363
		free(f);
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5364
	}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5365
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5366
	_first_grffile = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5367
	_cur_grffile   = NULL;
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5368
}
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5369
7366
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5370
static void ResetNewGRFErrors()
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5371
{
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5372
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  5373
		if (!HasBit(c->flags, GCF_COPY) && c->error != NULL) {
7369
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5374
			free(c->error->custom_message);
26325201d4d7 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 7366
diff changeset
  5375
			free(c->error->data);
7366
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5376
			free(c->error);
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5377
			c->error = NULL;
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5378
		}
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5379
	}
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5380
}
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5381
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5382
/**
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
  5383
 * 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
  5384
 * 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
  5385
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5386
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
  5387
{
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  5388
	CleanUpStrings();
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  5389
	CleanUpGRFTownNames();
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3595
diff changeset
  5390
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5391
	/* Copy/reset original engine info data */
8717
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8710
diff changeset
  5392
	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
  5393
8985
2f7b495d5807 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8980
diff changeset
  5394
	/* Copy/reset original bridge info data */
2f7b495d5807 (svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
belugas
parents: 8980
diff changeset
  5395
	ResetBridges();
2491
dfe9542f783e (svn r3017) -NewGRF: Implement sprite group unreferencing and unloading.
peter1138
parents: 2490
diff changeset
  5396
10298
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  5397
	/* Allocate temporary refit/cargo class data */
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5398
	_gted = CallocT<GRFTempEngineData>(GetEnginePoolSize());
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5399
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5400
	/* Reset GRM reservations */
4961
0ba3cfeaff61 (svn r6960) - Feature: NewGRF: Implement some support for GRF Resource Management (GRM)
peter1138
parents: 4953
diff changeset
  5401
	memset(&_grm_engines, 0, sizeof(_grm_engines));
7277
eddd0a777e8b (svn r10019) -Codechange: Implement GRM for newcargos
peter1138
parents: 7265
diff changeset
  5402
	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
  5403
9040
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  5404
	/* Reset generic feature callback lists */
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  5405
	ResetGenericCallbacks();
7d9d63315d91 (svn r12122) -Codechange: Add framework for generic feature callbacks, along with some parts for AI use.
peter1138
parents: 9037
diff changeset
  5406
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5407
	/* Reset price base data */
2506
777ac2d9a98a (svn r3032) -NewGRF, Feature: Add support for changing base prices.
peter1138
parents: 2491
diff changeset
  5408
	ResetPriceBaseMultipliers();
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5409
4377
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5410
	/* Reset the curencies array */
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5411
	ResetCurrencies();
0fb9077b8173 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4322
diff changeset
  5412
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5413
	/* Reset the house array */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5414
	ResetCustomHouses();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5415
	ResetHouses();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5416
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7187
diff changeset
  5417
	/* Reset the industries structures*/
7255
8b6f5524dfbc (svn r9994) -Codechange: Add pointers for Industry and Industry Tiles in the grf file.
belugas
parents: 7239
diff changeset
  5418
	ResetCustomIndustries();
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7187
diff changeset
  5419
	ResetIndustries();
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7187
diff changeset
  5420
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5421
	/* Reset station classes */
2625
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5422
	ResetStationClasses();
66b3d632dcd2 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents: 2624
diff changeset
  5423
	ResetCustomStations();
2812
f250489941f9 (svn r3360) Fix initialization of engines for precalculation of default refit mask.
peter1138
parents: 2769
diff changeset
  5424
8868
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  5425
	/* Reset canal sprite groups and flags */
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8819
diff changeset
  5426
	memset(_water_feature, 0, sizeof(_water_feature));
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents: 7077
diff changeset
  5427
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  5428
	/* Reset the snowline table. */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  5429
	ClearSnowLine();
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6668
diff changeset
  5430
4953
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5431
	/* Reset NewGRF files */
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5432
	ResetNewGRF();
6c40b2b16164 (svn r6948) - Codechange: Clear out all NewGRF file data before loading files again
peter1138
parents: 4952
diff changeset
  5433
7366
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5434
	/* Reset NewGRF errors. */
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5435
	ResetNewGRFErrors();
3a76f142e0ab (svn r10110) -Fix: Reset NewGRF errors along with all the other NewGRF data so that errors get loaded again when pressing "Apply".
maedhros
parents: 7353
diff changeset
  5436
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
  5437
	/* Set up the default cargo types */
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10751
diff changeset
  5438
	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
  5439
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
  5440
	/* 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
  5441
	_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
  5442
	_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
  5443
	_traininfo_vehicle_width = 29;
7265
74148c363f9d (svn r10005) -Codechange: Merge two flags (2cc and newhouses) indicating some newgrf features have been loaded, and introduce the newindustry one.
belugas
parents: 7261
diff changeset
  5444
8226
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  5445
	/* Reset track cost multipliers. */
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  5446
	memcpy(&_railtype_cost_multiplier, &_default_railtype_cost_multiplier, sizeof(_default_railtype_cost_multiplier));
c66a40c8e9bf (svn r11265) -Feature: Make more advanced rail types more expensive to build.
maedhros
parents: 8214
diff changeset
  5447
7410
358b83972e29 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 7404
diff changeset
  5448
	_loaded_newgrf_features.has_2CC           = false;
358b83972e29 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents: 7404
diff changeset
  5449
	_loaded_newgrf_features.has_newhouses     = false;
8157
e2506892a70f (svn r11192) -Fix: Little typo with bigger consequences when trying to remove a newindustries aware grf
belugas
parents: 8156
diff changeset
  5450
	_loaded_newgrf_features.has_newindustries = false;
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5451
	_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
  5452
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5453
	/* Clear all GRF overrides */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5454
	_grf_id_overrides.clear();
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5455
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5456
	InitializeSoundPool();
3595
20621831cd46 (svn r4486) - NewGRF: Create and use a memory pool to manage sprite groups. This
peter1138
parents: 3593
diff changeset
  5457
	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
  5458
}
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
  5459
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5460
static void BuildCargoTranslationMap()
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5461
{
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5462
	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
  5463
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5464
	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
  5465
		const CargoSpec *cs = GetCargo(c);
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5466
		if (!cs->IsValid()) continue;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5467
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5468
		if (_cur_grffile->cargo_max == 0) {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5469
			/* 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
  5470
			_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
  5471
		} else {
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5472
			/* 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
  5473
			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
  5474
				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
  5475
					_cur_grffile->cargo_map[c] = i;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5476
					break;
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5477
				}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5478
			}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5479
		}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5480
	}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5481
}
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  5482
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
  5483
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
  5484
{
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5485
	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
  5486
	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
  5487
		/* 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
  5488
		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
  5489
		_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
  5490
		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
  5491
	}
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
  5492
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
  5493
	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
  5494
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5495
	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
  5496
7530
31257d744079 (svn r10298) -Fix [FS#903]: show the subdirectory below the default data directory in this filename in the newgrf list. The directory was removed in r9560 because then it used to full path instead of the path relative to the data directory, but since the inclusion of "search paths" that is not necessary anymore.
rubidium
parents: 7452
diff changeset
  5497
	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
  5498
	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
  5499
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
  5500
	/* 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
  5501
	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
  5502
	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
  5503
	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
  5504
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
  5505
	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
  5506
		_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
  5507
		_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
  5508
	} 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
  5509
		_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
  5510
		_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
  5511
	}
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
  5512
}
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
  5513
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5514
6471
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5515
/** 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
  5516
 * 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
  5517
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
  5518
	'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
  5519
	'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
  5520
	'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
  5521
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5522
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5523
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5524
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
  5525
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5526
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5527
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
  5528
	'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
  5529
	'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
  5530
	'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
  5531
	'PLST', 'FZDR',
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5532
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5533
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5534
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
  5535
	'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
  5536
	'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
  5537
	0 };
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5538
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5539
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
  5540
	_default_refitmasks_rail,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5541
	_default_refitmasks_road,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5542
	_default_refitmasks_ships,
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5543
	_default_refitmasks_aircraft,
5037
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5544
};
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5545
7d956200ee71 (svn r7079) -Codechange: Move an array to the only place it is used.
peter1138
parents: 5024
diff changeset
  5546
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5547
/**
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5548
 * 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
  5549
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5550
static void CalculateRefitMasks()
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5551
{
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5552
	Engine *e;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5553
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5554
	FOR_ALL_ENGINES(e) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5555
		EngineID engine = e->index;
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5556
		EngineInfo *ei = &e->info;
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5557
		uint32 mask = 0;
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5558
		uint32 not_mask = 0;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5559
		uint32 xor_mask = 0;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5560
9250
9011a285f2dd (svn r12450) -Codechange: Use a pointer instead of several array dereferences.
peter1138
parents: 9249
diff changeset
  5561
		if (ei->refit_mask != 0) {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5562
			const GRFFile *file = e->grffile;
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5563
			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
  5564
				/* 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
  5565
				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
  5566
				for (uint i = 0; i < num_cargo; i++) {
9250
9011a285f2dd (svn r12450) -Codechange: Use a pointer instead of several array dereferences.
peter1138
parents: 9249
diff changeset
  5567
					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
  5568
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5569
					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
  5570
					if (c == CT_INVALID) continue;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5571
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  5572
					SetBit(xor_mask, c);
6610
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5573
				}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5574
			} else {
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5575
				/* 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
  5576
				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
  5577
					const CargoSpec *cs = GetCargo(c);
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5578
					if (!cs->IsValid()) continue;
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5579
9250
9011a285f2dd (svn r12450) -Codechange: Use a pointer instead of several array dereferences.
peter1138
parents: 9249
diff changeset
  5580
					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
  5581
				}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5582
			}
ecaea43b2238 (svn r9102) -Codechange: (NewGRF) Apply cargo translation table to vehicle refit masks
peter1138
parents: 6608
diff changeset
  5583
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5584
10298
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  5585
		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
  5586
			/* 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
  5587
			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
  5588
				const CargoSpec *cs = GetCargo(i);
10298
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  5589
				if (_gted[engine].cargo_allowed    & cs->classes) SetBit(mask,     i);
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  5590
				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
  5591
			}
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5592
		} else if (xor_mask == 0) {
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  5593
			/* Don't apply default refit mask to wagons or engines with no capacity */
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5594
			if (e->type != VEH_TRAIN || (e->u.rail.capacity != 0 && e->u.rail.railveh_type != RAILVEH_WAGON)) {
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5595
				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
  5596
				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
  5597
					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
  5598
d0e79064c324 (svn r8888) -Codechange: Replace hardcoded default cargo bitmasks with a list of cargo labels.
peter1138
parents: 6469
diff changeset
  5599
					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
  5600
					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
  5601
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  5602
					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
  5603
				}
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3026
diff changeset
  5604
			}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5605
		}
9250
9011a285f2dd (svn r12450) -Codechange: Use a pointer instead of several array dereferences.
peter1138
parents: 9249
diff changeset
  5606
9011a285f2dd (svn r12450) -Codechange: Use a pointer instead of several array dereferences.
peter1138
parents: 9249
diff changeset
  5607
		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
  5608
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
  5609
		/* 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
  5610
		 * cargo type. Apparently cargo_type isn't a common property... */
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5611
		switch (e->type) {
7134
c5a90dd41166 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 7125
diff changeset
  5612
			default: NOT_REACHED();
c5a90dd41166 (svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents: 7125
diff changeset
  5613
			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
  5614
			case VEH_TRAIN: {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5615
				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
  5616
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5617
				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
  5618
				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
  5619
			}
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
  5620
			case VEH_ROAD: {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5621
				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
  5622
				if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5623
				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
  5624
				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
  5625
			}
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
  5626
			case VEH_SHIP: {
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5627
				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
  5628
				if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  5629
				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
  5630
				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
  5631
			}
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
  5632
		}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5633
	}
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  5634
}
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
  5635
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5636
/** 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
  5637
 * 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
  5638
 * 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
  5639
 * 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
  5640
static void FinaliseHouseArray()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5641
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5642
	/* 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
  5643
	 * 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
  5644
	 * 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
  5645
	 * 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
  5646
	 * If there have been any houses defined with start dates before 1930 then
8661
18e70c2e086e (svn r11728) -Fix [FS#1577]: if there are no houses that can be build in a specific year yet, force the houses with the earliest introduction year to be available.
rubidium
parents: 8660
diff changeset
  5647
	 * the dates are left alone.
18e70c2e086e (svn r11728) -Fix [FS#1577]: if there are no houses that can be build in a specific year yet, force the houses with the earliest introduction year to be available.
rubidium
parents: 8660
diff changeset
  5648
	 * On the other hand, why 1930? Just 'fix' the houses with the lowest
18e70c2e086e (svn r11728) -Fix [FS#1577]: if there are no houses that can be build in a specific year yet, force the houses with the earliest introduction year to be available.
rubidium
parents: 8660
diff changeset
  5649
	 * minimum introduction date to 0.
18e70c2e086e (svn r11728) -Fix [FS#1577]: if there are no houses that can be build in a specific year yet, force the houses with the earliest introduction year to be available.
rubidium
parents: 8660
diff changeset
  5650
	 */
10817
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  5651
	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
  5652
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5653
	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
  5654
		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
  5655
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5656
		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
  5657
			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
  5658
			if (hs != NULL) {
7125
4ce0c7a12a3f (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents: 7119
diff changeset
  5659
				_house_mngr.SetEntitySpec(hs);
10817
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  5660
				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
  5661
			}
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
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5664
10817
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  5665
	if (min_year != 0) {
8661
18e70c2e086e (svn r11728) -Fix [FS#1577]: if there are no houses that can be build in a specific year yet, force the houses with the earliest introduction year to be available.
rubidium
parents: 8660
diff changeset
  5666
		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
  5667
			HouseSpec *hs = GetHouseSpecs(i);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5668
10817
fa6a5e01b710 (svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas
parents: 10813
diff changeset
  5669
			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
  5670
		}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5671
	}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5672
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5673
7679
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5674
/** Add all new industries to the industry array. Industry properties can be set at any
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5675
 * time in the GRF file, so we can only add a industry spec to the industry array
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5676
 * after the file has finished loading. */
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5677
static void FinaliseIndustriesArray()
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5678
{
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5679
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5680
		if (file->industryspec != NULL) {
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5681
			for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5682
				IndustrySpec *indsp = file->industryspec[i];
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5683
7713
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5684
				if (indsp != NULL && indsp->enabled) {
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5685
					StringID strid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5686
					/* process the conversion of text at the end, so to be sure everything will be fine
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5687
					 * and available.  Check if it does not return undefind marker, which is a very good sign of a
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5688
					 * substitute industry who has not changed the string been examined, thus using it as such */
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5689
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5690
					if (strid != STR_UNDEFINED) indsp->name = strid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5691
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5692
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5693
					if (strid != STR_UNDEFINED) indsp->closure_text = strid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5694
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5695
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5696
					if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5697
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5698
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5699
					if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5700
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5701
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5702
					if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
051fca48d12b (svn r10495) -Codechange: Add the Action 00 property handlers for Industries and Industry tiles
belugas
parents: 7679
diff changeset
  5703
8966
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5704
					if (indsp->station_name != STR_NULL) {
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5705
						/* STR_NULL (0) can be set by grf.  It has a meaning regarding assignation of the
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5706
						 * station's name. Don't wont to loose the value, therefor, do not process. */
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5707
						strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->station_name);
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5708
						if (strid != STR_UNDEFINED) indsp->station_name = strid;
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5709
					}
19ceef337cb6 (svn r12041) -Codechange: Add the loader and the property for action 00 industries, prop 24, nearby station name.
belugas
parents: 8945
diff changeset
  5710
7679
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5711
					_industry_mngr.SetEntitySpec(indsp);
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5712
					_loaded_newgrf_features.has_newindustries = true;
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5713
				}
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5714
			}
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5715
		}
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5716
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5717
		if (file->indtspec != NULL) {
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5718
			for (int i = 0; i < NUM_INDUSTRYTILES; i++) {
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5719
				IndustryTileSpec *indtsp = file->indtspec[i];
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5720
				if (indtsp != NULL) {
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5721
					_industile_mngr.SetEntitySpec(indtsp);
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5722
				}
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5723
			}
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5724
		}
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5725
	}
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5726
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5727
	for (uint j = 0; j < NUM_INDUSTRYTYPES; j++) {
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5728
		IndustrySpec *indsp = &_industry_specs[j];
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5729
		if (indsp->enabled && indsp->grf_prop.grffile != NULL) {
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5730
			for (uint i = 0; i < 3; i++) {
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5731
				indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid);
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5732
			}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5733
		}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
  5734
	}
7679
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5735
}
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5736
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5737
/** 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
  5738
 * 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
  5739
 * properly. */
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5740
static void MapNewCargoStrings()
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5741
{
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5742
	for (CargoID c = 0; c < NUM_CARGO; c++) {
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5743
		CargoSpec *cs = &_cargo[c];
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5744
		/* Don't map if the cargo is unavailable or not from NewGRF */
8214
854acef589c8 (svn r11253) -Fix (r9411): industries can still use cargo they define, even if these cargo are disabled by a grf loaded later
glx
parents: 8213
diff changeset
  5745
		if (cs->grfid == 0) continue;
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5746
	}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5747
}
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5748
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5749
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5750
/* 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
  5751
 * 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
  5752
 * partial implementation yet). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5753
/* 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
  5754
 * 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
  5755
 * 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
  5756
static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  5757
{
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 381
diff changeset
  5758
	/* 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
  5759
	 * 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
  5760
	 * 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
  5761
	 * "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
  5762
	 * 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
  5763
	 * 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
  5764
	 * 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
  5765
	 * 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
  5766
	 * --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
  5767
	/* 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
  5768
	 * 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
  5769
	 * 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
  5770
	static const SpecialSpriteHandler handlers[][GLS_END] = {
8395
f59a33543bf8 (svn r11450) -Fix [FS#1432](r8886): cargo translation table was loaded too early
glx
parents: 8388
diff changeset
  5771
		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       NULL,           ReserveChangeInfo, FeatureChangeInfo, },
7072
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  5772
		/* 0x01 */ { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
973b998c5cfe (svn r9790) -Codechange: [NewGRF] Skip action 1 sprites in all stages except activation. This also cleans up some special-case handling of the sprites. Actions 1 and 2 are now not considered unsafe, as an Action 3 (which is unsafe) is required for them.
peter1138
parents: 7066
diff changeset
  5773
		/* 0x02 */ { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5774
		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5775
		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
7025
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  5776
		/* 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
  5777
		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5778
		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
7302
7aa974539f27 (svn r10045) -Codechange: Process Action 8 during GLS_RESERVATION to allow Action 7/Action 9s to work properly
peter1138
parents: 7301
diff changeset
  5779
		/* 0x08 */ { ScanInfo, NULL,      NULL,            GRFInfo,        GRFInfo,           GRFInfo, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5780
		/* 0x09 */ { NULL,     NULL,      NULL,            SkipIf,         SkipIf,            SkipIf, },
7025
8504c5cfa1e5 (svn r9717) -Codechange: (NewGRF) Skip Action 5 & A sprites in all loading stages except activation.
peter1138
parents: 7011
diff changeset
  5781
		/* 0x0A */ { SkipActA, SkipActA,  SkipActA,        SkipActA,       SkipActA,          SpriteReplace, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5782
		/* 0x0B */ { NULL,     NULL,      NULL,            GRFLoadError,   GRFLoadError,      GRFLoadError, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5783
		/* 0x0C */ { NULL,     NULL,      NULL,            GRFComment,     NULL,              GRFComment, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5784
		/* 0x0D */ { NULL,     SafeParamSet, NULL,         ParamSet,       ParamSet,          ParamSet, },
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5785
		/* 0x0E */ { NULL,     SafeGRFInhibit, NULL,       GRFInhibit,     GRFInhibit,        GRFInhibit, },
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  5786
		/* 0x0F */ { NULL,     GRFUnsafe, NULL,            FeatureTownName, NULL,             NULL, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5787
		/* 0x10 */ { NULL,     NULL,      DefineGotoLabel, NULL,           NULL,              NULL, },
8927
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5788
		/* 0x11 */ { SkipAct11,GRFUnsafe, SkipAct11,       SkipAct11,      SkipAct11,         GRFSound, },
8c38efc3987a (svn r12001) -Fix: When skipping Action 11 or 12, also skip belonging sprites.
frosch
parents: 8899
diff changeset
  5789
		/* 0x12 */ { SkipAct12, SkipAct12, SkipAct12,      SkipAct12,      SkipAct12,         LoadFontGlyph, },
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5790
		/* 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
  5791
	};
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5792
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5793
	byte* buf;
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5794
3895
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5795
	if (_preload_sprite == NULL) {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5796
		/* 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
  5797
		 * 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
  5798
		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
  5799
		FioReadBlock(buf, num);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5800
	} else {
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5801
		/* 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
  5802
		buf = _preload_sprite;
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5803
		_preload_sprite = NULL;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5567
diff changeset
  5804
		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
  5805
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5806
		/* 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
  5807
		FioSeekTo(num, SEEK_CUR);
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5808
	}
a67d4451a1df (svn r4965) - NewGRF: add support for action 0x06 (modify sprite data) for pseudo sprites
peter1138
parents: 3879
diff changeset
  5809
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  5810
	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
  5811
4656
acffecd6f484 (svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents: 4625
diff changeset
  5812
	if (action == 0xFF) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5813
		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
  5814
		GRFDataBlock(buf, num);
4818
1625f49f708d (svn r6742) - Newsounds: Add support for importing sounds from previously loaded GRF files.
peter1138
parents: 4817
diff changeset
  5815
	} else if (action == 0xFE) {
8395
f59a33543bf8 (svn r11450) -Fix [FS#1432](r8886): cargo translation table was loaded too early
glx
parents: 8388
diff changeset
  5816
		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
  5817
		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
  5818
	} else if (action >= lengthof(handlers)) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5819
		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
  5820
	} else if (handlers[action][stage] == NULL) {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5821
		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
  5822
	} else {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5823
		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
  5824
		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
  5825
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5826
	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
  5827
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5828
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5829
8690
49dffe46a866 (svn r11757) -Fix(r11727): Don't use a function's default parameter when the value can be (more adequately, even better) computed from another source.
belugas
parents: 8681
diff changeset
  5830
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
  5831
{
7530
31257d744079 (svn r10298) -Fix [FS#903]: show the subdirectory below the default data directory in this filename in the newgrf list. The directory was removed in r9560 because then it used to full path instead of the path relative to the data directory, but since the inclusion of "search paths" that is not necessary anymore.
rubidium
parents: 7452
diff changeset
  5832
	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
  5833
	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
  5834
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5835
	/* 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
  5836
	 * 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
  5837
	 * 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
  5838
	 * 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
  5839
	 * 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
  5840
	 *
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5841
	 * 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
  5842
	 * 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
  5843
	 * 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
  5844
	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
  5845
		_cur_grffile = GetFileByFilename(filename);
10839
a62547c31fdb (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 10837
diff changeset
  5846
		if (_cur_grffile == NULL) usererror("File '%s' lost in cache.\n", filename);
7302
7aa974539f27 (svn r10045) -Codechange: Process Action 8 during GLS_RESERVATION to allow Action 7/Action 9s to work properly
peter1138
parents: 7301
diff changeset
  5847
		if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  5848
		if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return;
8690
49dffe46a866 (svn r11757) -Fix(r11727): Don't use a function's default parameter when the value can be (more adequately, even better) computed from another source.
belugas
parents: 8681
diff changeset
  5849
		_cur_grffile->is_ottdfile = config->IsOpenTTDBaseGRF();
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
  5850
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5851
8301
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5852
	if (file_index > LAST_GRF_SLOT) {
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5853
		DEBUG(grf, 0, "'%s' is not loaded as the maximum number of GRFs has been reached", filename);
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5854
		config->status = GCS_DISABLED;
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5855
		config->error  = CallocT<GRFError>(1);
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5856
		config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5857
		config->error->message  = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED;
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5858
		return;
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5859
	}
47e8f031a6ab (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 8292
diff changeset
  5860
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
  5861
	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
  5862
	_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
  5863
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  5864
	_cur_grfconfig = config;
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5225
diff changeset
  5865
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5866
	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
  5867
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5868
	/* 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
  5869
	 * 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
  5870
	 * 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
  5871
	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
  5872
		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
  5873
	} else {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5874
		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
  5875
		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
  5876
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5877
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5878
	_skip_sprites = 0; // XXX
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  5879
	_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
  5880
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5881
	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
  5882
		byte type = FioReadByte();
3557
5d12a78ce141 (svn r4431) - NewGRF: rename nfo_line to _nfo_line, to avoid confusing Darkvater ;)
peter1138
parents: 3555
diff changeset
  5883
		_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
  5884
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5885
		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
  5886
			if (_skip_sprites == 0) {
2958
3f8946daf55f (svn r3520) Remove unused parameters from some functions
tron
parents: 2935
diff changeset
  5887
				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
  5888
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
  5889
				/* 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
  5890
				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
  5891
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
  5892
				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
  5893
			} 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
  5894
				FioSkipBytes(num);
1611
bf352a87ef51 (svn r2115) Spring cleaning, no functional changes
tron
parents: 1607
diff changeset
  5895
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5896
		} else {
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  5897
			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
  5898
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5899
			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
  5900
			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
  5901
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5902
			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
  5903
				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
  5904
			} 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
  5905
				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
  5906
					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
  5907
					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
  5908
						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
  5909
						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
  5910
					} 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
  5911
						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
  5912
						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
  5913
						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
  5914
					}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5915
				}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5916
			}
368
32aad6ad36e1 (svn r556) -newgrf: Some seemingly proper support for loading stages of grf files (octo & pasky).
darkvater
parents: 367
diff changeset
  5917
		}
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
  5918
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5919
		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
  5920
	}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5921
}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  5922
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5923
/**
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5924
 * Relocates the old shore sprites at new positions.
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5925
 *
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5926
 * 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)
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5927
 * 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)
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5928
 * 3. If a newgrf replaces shore sprites by Action5 any shore replacement by ActionA has no effect. (SHORE_REPLACE_ACTION_5)
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5929
 */
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5930
static void ActivateOldShore()
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5931
{
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5932
	/* Use default graphics, if no shore sprites were loaded.
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5933
	 * Should not happen, as openttd(w/d).grf includes some. */
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5934
	if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_A;
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5935
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5936
	if (_loaded_newgrf_features.shore != SHORE_REPLACE_ACTION_5) {
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5937
		DupSprite(SPR_ORIGINALSHORE_START +  1, SPR_SHORE_BASE +  1); // SLOPE_W
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5938
		DupSprite(SPR_ORIGINALSHORE_START +  2, SPR_SHORE_BASE +  2); // SLOPE_S
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5939
		DupSprite(SPR_ORIGINALSHORE_START +  6, SPR_SHORE_BASE +  3); // SLOPE_SW
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5940
		DupSprite(SPR_ORIGINALSHORE_START     , SPR_SHORE_BASE +  4); // SLOPE_E
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5941
		DupSprite(SPR_ORIGINALSHORE_START +  4, SPR_SHORE_BASE +  6); // SLOPE_SE
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5942
		DupSprite(SPR_ORIGINALSHORE_START +  3, SPR_SHORE_BASE +  8); // SLOPE_N
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5943
		DupSprite(SPR_ORIGINALSHORE_START +  7, SPR_SHORE_BASE +  9); // SLOPE_NW
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5944
		DupSprite(SPR_ORIGINALSHORE_START +  5, SPR_SHORE_BASE + 12); // SLOPE_NE
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5945
	}
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5946
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5947
	if (_loaded_newgrf_features.shore == SHORE_REPLACE_ACTION_A) {
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5948
		DupSprite(SPR_FLAT_GRASS_TILE + 16, SPR_SHORE_BASE +  0); // SLOPE_STEEP_S
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5949
		DupSprite(SPR_FLAT_GRASS_TILE + 17, SPR_SHORE_BASE +  5); // SLOPE_STEEP_W
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5950
		DupSprite(SPR_FLAT_GRASS_TILE +  7, SPR_SHORE_BASE +  7); // SLOPE_WSE
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5951
		DupSprite(SPR_FLAT_GRASS_TILE + 15, SPR_SHORE_BASE + 10); // SLOPE_STEEP_N
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5952
		DupSprite(SPR_FLAT_GRASS_TILE + 11, SPR_SHORE_BASE + 11); // SLOPE_NWS
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5953
		DupSprite(SPR_FLAT_GRASS_TILE + 13, SPR_SHORE_BASE + 13); // SLOPE_ENW
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5954
		DupSprite(SPR_FLAT_GRASS_TILE + 14, SPR_SHORE_BASE + 14); // SLOPE_SEN
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5955
		DupSprite(SPR_FLAT_GRASS_TILE + 18, SPR_SHORE_BASE + 15); // SLOPE_STEEP_E
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5956
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5957
		/* XXX - SLOPE_EW, SLOPE_NS are currently not used.
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5958
		 *       If they would be used somewhen, then these grass tiles will most like not look as needed */
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5959
		DupSprite(SPR_FLAT_GRASS_TILE +  5, SPR_SHORE_BASE + 16); // SLOPE_EW
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5960
		DupSprite(SPR_FLAT_GRASS_TILE + 10, SPR_SHORE_BASE + 17); // SLOPE_NS
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5961
	}
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5962
}
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  5963
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6560
diff changeset
  5964
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
  5965
8819
86c6ce890d61 (svn r11888) -Codechange: simplify sorting of the strings in town names dropdown
glx
parents: 8794
diff changeset
  5966
extern void InitGRFTownGeneratorNames();
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  5967
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5968
static void AfterLoadGRFs()
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5969
{
10219
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  5970
	for (StringIDToGRFIDMapping::iterator it = _string_to_grf_mapping.begin(); it != _string_to_grf_mapping.end(); it++) {
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  5971
		*((*it).first) = MapGRFStringID((*it).second, *((*it).first));
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  5972
	}
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  5973
	_string_to_grf_mapping.clear();
2ff2b0f7643e (svn r12751) -Codechange: do what has been done in r11862 in a different way so it uses less memory.
rubidium
parents: 10117
diff changeset
  5974
7182
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5975
	/* Update the bitmasks for the vehicle lists */
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5976
	Player *p;
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5977
	FOR_ALL_PLAYERS(p) {
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5978
		p->avail_railtypes = GetPlayerRailtypes(p->index);
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5979
		p->avail_roadtypes = GetPlayerRoadtypes(p->index);
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5980
	}
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7180
diff changeset
  5981
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5982
	/* 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
  5983
	CalculateRefitMasks();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5984
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5985
	/* 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
  5986
	InitDepotWindowBlockSizes();
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5987
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  5988
	/* 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
  5989
	FinaliseHouseArray();
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5990
7679
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5991
	/* Add all new industries to the industry array. */
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5992
	FinaliseIndustriesArray();
c3c44a572f6e (svn r10457) -Codechange: Load the newly read definitions of Industries and Industry tiles.
belugas
parents: 7678
diff changeset
  5993
7029
209e4b2e1180 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 7025
diff changeset
  5994
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
209e4b2e1180 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 7025
diff changeset
  5995
	BuildIndustriesLegend();
209e4b2e1180 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas
parents: 7025
diff changeset
  5996
6685
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5997
	/* 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
  5998
	 * loaded before strings... */
410bba0abb67 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6683
diff changeset
  5999
	MapNewCargoStrings();
7452
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  6000
f6fd23727af0 (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 7423
diff changeset
  6001
	/* Update the townname generators list */
8819
86c6ce890d61 (svn r11888) -Codechange: simplify sorting of the strings in town names dropdown
glx
parents: 8794
diff changeset
  6002
	InitGRFTownGeneratorNames();
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  6003
10382
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  6004
	/* Run all queued vehicle list order changes */
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  6005
	CommitRailVehListOrderChanges();
d1d4452acbfc (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 10298
diff changeset
  6006
8899
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  6007
	/* Load old shore sprites in new position, if they were replaced by ActionA */
b622d34771a9 (svn r11973) -Fix (r11726, r11947)[FS#1683]: Use grass tiles for corner shores, if shores got replaced by ActionA.
frosch
parents: 8889
diff changeset
  6008
	ActivateOldShore();
10298
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  6009
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  6010
	/* Deallocate temporary loading data */
0a4a98c78137 (svn r12839) -Codechange: Allocate temporary engine data when loading GRFs as needed instead of statically.
peter1138
parents: 10266
diff changeset
  6011
	free(_gted);
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  6012
	_grm_sprites.clear();
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6013
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6014
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
  6015
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
  6016
{
2930
a3bfaa5a9222 (svn r3486) - NewGRF fix: Always reinitialize the ttdpatch flags as patch settings may have changed.
peter1138
parents: 2895
diff changeset
  6017
	InitializeGRFSpecial();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6018
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
  6019
	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
  6020
8655
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6021
	/*
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6022
	 * Reset the status of all files, so we can 'retry' to load them.
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6023
	 * This is needed when one for example rearranges the NewGRFs in-game
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6024
	 * and a previously disabled NewGRF becomes useable. If it would not
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6025
	 * be reset, the NewGRF would remain disabled even though it should
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6026
	 * have been enabled.
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6027
	 */
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6028
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6029
		if (c->status != GCS_NOT_FOUND) c->status = GCS_UNKNOWN;
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6030
	}
5113b6256c42 (svn r11721) -Fix: do not disable NewGRFs for 'eternity' during games.
rubidium
parents: 8654
diff changeset
  6031
10416
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  6032
	_cur_spriteid = load_index;
96e869d65b9c (svn r12958) -Codechange: Allocate sprites reserved by GRM in advance of 'Action 1' sprites, giving much less chance of GRM reservation failure if lots of NewGRF sets are loaded.
peter1138
parents: 10408
diff changeset
  6033
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
  6034
	/* 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
  6035
	 * 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
  6036
	 * and load information from it. */
8326
f52b35031c5a (svn r11380) -Revert (r11191, r11196): it worked, but broke cargo loading
glx
parents: 8304
diff changeset
  6037
	for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
9164
04e2cc7a00e6 (svn r12333) -Fix: Switch grfstatus from 'activated' back to 'will-be-active' between reservation- and activation-stage.
frosch
parents: 9152
diff changeset
  6038
		/* Set activated grfs back to will-be-activated between reservation- and activation-stage.
04e2cc7a00e6 (svn r12333) -Fix: Switch grfstatus from 'activated' back to 'will-be-active' between reservation- and activation-stage.
frosch
parents: 9152
diff changeset
  6039
		 * This ensures that action7/9 conditions 0x06 - 0x0A work correctly. */
04e2cc7a00e6 (svn r12333) -Fix: Switch grfstatus from 'activated' back to 'will-be-active' between reservation- and activation-stage.
frosch
parents: 9152
diff changeset
  6040
		for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
04e2cc7a00e6 (svn r12333) -Fix: Switch grfstatus from 'activated' back to 'will-be-active' between reservation- and activation-stage.
frosch
parents: 9152
diff changeset
  6041
			if (c->status == GCS_ACTIVATED) c->status = GCS_INITIALISED;
04e2cc7a00e6 (svn r12333) -Fix: Switch grfstatus from 'activated' back to 'will-be-active' between reservation- and activation-stage.
frosch
parents: 9152
diff changeset
  6042
		}
04e2cc7a00e6 (svn r12333) -Fix: Switch grfstatus from 'activated' back to 'will-be-active' between reservation- and activation-stage.
frosch
parents: 9152
diff changeset
  6043
2400
0b51bc385750 (svn r2926) -Fix: Use the same file slots in both initialisation stages when loading a patch grf
tron
parents: 2346
diff changeset
  6044
		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
  6045
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  6046
		_cur_stage = stage;
6607
b4f6595855c4 (svn r9093) -Codechange: variable scope / type
peter1138
parents: 6606
diff changeset
  6047
		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
  6048
			if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  6049
			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
  6050
6674
64f4781b4653 (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6669
diff changeset
  6051
			/* @todo usererror() */
10839
a62547c31fdb (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 10837
diff changeset
  6052
			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
  6053
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
  6054
			if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
8690
49dffe46a866 (svn r11757) -Fix(r11727): Don't use a function's default parameter when the value can be (more adequately, even better) computed from another source.
belugas
parents: 8681
diff changeset
  6055
			LoadNewGRFFile(c, slot++, stage);
7316
7c38e04b95c5 (svn r10059) -Fix (r10045): Pretend GRF is still in initialisation state when leaving reservation stage. This fixes action 7/9 tests for grfs that will be active.
peter1138
parents: 7309
diff changeset
  6056
			if (stage == GLS_RESERVE) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  6057
				SetBit(c->flags, GCF_RESERVED);
8326
f52b35031c5a (svn r11380) -Revert (r11191, r11196): it worked, but broke cargo loading
glx
parents: 8304
diff changeset
  6058
			} else if (stage == GLS_ACTIVATION) {
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
  6059
				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
  6060
				ClearTemporaryNewGRFData();
6473
03480a0f016e (svn r8890) -Codechange: (NewGRF) add cargo translation support to engine var 47
peter1138
parents: 6471
diff changeset
  6061
				BuildCargoTranslationMap();
6973
100d41c32546 (svn r9653) -Codechange: Indicate the proper function names in the GRF messages
belugas
parents: 6966
diff changeset
  6062
				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
  6063
			}
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
  6064
		}
c19fb4f2df30 (svn r2868) Change the way NewGRFs are loaded: The loading process i no longer bolted onto the normal graphics loading.
tron
parents: 2340
diff changeset
  6065
	}
2611
65b5313bc525 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2582
diff changeset
  6066
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6614
diff changeset
  6067
	/* 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
  6068
	AfterLoadGRFs();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  6069
}
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 7029
diff changeset
  6070
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 7029
diff changeset
  6071
bool HasGrfMiscBit(GrfMiscBit bit)
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 7029
diff changeset
  6072
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  6073
	return HasBit(_misc_grf_features, bit);
7037
3cd1bd7a6edb (svn r9730) -Feature: [NewGRF] Add support for miscellaneous grf feature bit 1 - paved roads on desert tiles.
maedhros
parents: 7029
diff changeset
  6074
}